rubyforgood / voices-of-consent

Open source tracking and inventory management application for nonprofit, Voices of Consent (Ruby for Good 2019)
https://voices-of-consent.herokuapp.com
MIT License
38 stars 82 forks source link

Create factory_bot traits #310

Open maebeale opened 4 years ago

maebeale commented 4 years ago

We have need for varied user, box_request, box, and box_item factory traits (We have existing factories) for use in tests, and later to create seed data.

If we had box traits that mimic the methods in the box model such as design_claimed, design_completed, shipping_claimed, shipping_completed where the relevant *_by_id,*_at, and aasm_state were populated, that'd be amazing. For user, we need a trait for each constant in the Permission model.

This would allow us to skip all the cajoling we had to do in box_spec.rb. Instead, it'd be so awesome to be able to call something like:

You might want to check out:

leosoaivan commented 4 years ago

@maebeale I can take a look at this. I've worked with Factory Bot before, never with traits, though. Can't be that much of a lift (hopefully) :).

maebeale commented 4 years ago

Awesome and thank you, @leosoaivan !

If it's helpful, here's something I've used in another project:

factory :ticket_pickup do
    pickup_quantity "1"
    ticket

    trait :with_ticket_quantity_of_5 do
      pickup_quantity "5"
      association :ticket, :with_quantity_of_5
    end
  end
leosoaivan commented 4 years ago

I'll get setup with the project today. Let you know if I have any issues getting setup!

maebeale commented 4 years ago

Any and all feedback welcome on the README, CONTRIBUTING, and background.md docs as you get set up, @leosoaivan ! :)

leosoaivan commented 4 years ago

It appears I can't get docker-compose up to run a local server on 3000.

voices-of-consent(develop) $ docker-compose up
Starting voices-of-consent_db_1          ... done
Starting voices-of-consent_redis_1       ... done
Starting voices-of-consent_mailcatcher_1 ... done
Attaching to voices-of-consent_mailcatcher_1, voices-of-consent_db_1, voices-of-consent_redis_1
db_1           | 2019-10-13 00:59:52.822 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1           | 2019-10-13 00:59:52.822 UTC [1] LOG:  listening on IPv6 address "::", port 5432
redis_1        | 1:C 13 Oct 2019 00:59:52.818 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1        | 1:C 13 Oct 2019 00:59:52.818 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1        | 1:C 13 Oct 2019 00:59:52.818 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1        | 1:M 13 Oct 2019 00:59:52.820 * Running mode=standalone, port=6379.
redis_1        | 1:M 13 Oct 2019 00:59:52.820 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1        | 1:M 13 Oct 2019 00:59:52.820 # Server initialized
redis_1        | 1:M 13 Oct 2019 00:59:52.820 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1        | 1:M 13 Oct 2019 00:59:52.820 * DB loaded from disk: 0.000 seconds
redis_1        | 1:M 13 Oct 2019 00:59:52.820 * Ready to accept connections
db_1           | 2019-10-13 00:59:52.827 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1           | 2019-10-13 00:59:52.845 UTC [24] LOG:  database system was interrupted; last known up at 2019-10-13 00:56:34 UTC
mailcatcher_1  | Starting MailCatcher
mailcatcher_1  | ==> smtp://0.0.0.0:1025
mailcatcher_1  | /usr/lib/ruby/gems/2.5.0/gems/thin-1.5.1/lib/thin/server.rb:104: warning: constant ::Fixnum is deprecated
mailcatcher_1  | ==> http://0.0.0.0:1080/
db_1           | 2019-10-13 00:59:53.129 UTC [24] LOG:  database system was not properly shut down; automatic recovery in progress
db_1           | 2019-10-13 00:59:53.131 UTC [24] LOG:  redo starts at 0/1871170
db_1           | 2019-10-13 00:59:53.131 UTC [24] LOG:  invalid record length at 0/1876F88: wanted 24, got 0
db_1           | 2019-10-13 00:59:53.131 UTC [24] LOG:  redo done at 0/1876F50
db_1           | 2019-10-13 00:59:53.142 UTC [1] LOG:  database system is ready to accept connections

Have I got the wrong port, perhaps?

maebeale commented 4 years ago

@leosoaivan hey there! hmmm. i don't use the docker rendition, but someone just submitted a PR that changed that from docker-compose start to docker-compose up. i'll see if i can reproduce the docker problem, but in the meantime would you try docker-compose start? (or consider using the local services option until we get this figured out.)

leosoaivan commented 4 years ago

@maebeale just a quick update. Haven't been able to get it running locally either with docker-compose start or up.

Nevertheless, it might be moot, since I'm mostly focusing on the test suite for now. Now that everything is green, I'll be able to take a closer look at those traits in the coming days!

maebeale commented 4 years ago

Thanks for the update, @leosoaivan ! Did you try the non-docker implementation? Someone else is testing the docker setup, so hopefully that'll get resolved in the next day or so. Great news about the traits! Thank you!

maebeale commented 4 years ago

@leosoaivan hello there! are you still planning to work on this?

leosoaivan commented 4 years ago

Hi @maebeale thanks for checking in, and my apologies for dropping off the face of the Earth.

Aside from the user factories in #374 , I've had some trouble getting these other ones going. I don't have much bandwidth to currently tackle them, so it may be worth unassigning me.

maebeale commented 4 years ago

Thanks, @leosoaivan ! I took a hiatus on this one too. :) Ok, I'll remove you here, but would love it if we could help you get things working again -- if you want to get involved again, that is! You're in slack, right? Maybe post something there? We're having a hack night tomorrow, so there will be some help available 7pm-9pm EST. https://www.meetup.com/Code-for-Good-DC/events/268436980/

RachelWyatt commented 4 years ago

I can work on setting up traits for boxes!