Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create factory_bot traits #310

Open
maebeale opened this issue Oct 12, 2019 · 12 comments · Fixed by #374 · May be fixed by #430
Open

Create factory_bot traits #310

maebeale opened this issue Oct 12, 2019 · 12 comments · Fixed by #374 · May be fixed by #430

Comments

@maebeale
Copy link
Collaborator

maebeale commented Oct 12, 2019

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:

  • designer = create(:designer) bc there was already a trait designer on user who had an associated create(:user_permission, name: Permission::BOX_DESIGNER)
  • assembled_box = create(:box, :is_assembled), which also has/mimics the traits :is_designed, :is_researched, box_request#is_reviewed, etc, bc our /box_requests index needs all the prior lifecycle phase to be true and all future lifecycle phases to be untrue to display correctly.
  • box_item_with_research_needed = create(:box_item_research_needed) that is a trait on box_item that who has an associated create(:inventory_type, research_needed: true)

You might want to check out:

  • Background doc (linked from README)
  • is_reviewed, is_shipped, etc, methods in box_rb
  • aasm blocks in the box_request and box.rb models
  • box_requests/index.html.erb or localhost:3000/box_requests in your local browser
  • database-diagram.png, linked from README
  • spec/models/box_spec.rb to see how we can manually walk box_requests along in the process.
@maebeale maebeale self-assigned this Oct 12, 2019
@maebeale maebeale added Hacktoberfest Hacktoberfest issues for your resolution! help wanted labels Oct 12, 2019
@maebeale maebeale removed their assignment Oct 12, 2019
@maebeale maebeale changed the title Create BoxRequest/Box traits and seed data Create BoxRequest/Box traits Oct 12, 2019
@maebeale maebeale changed the title Create BoxRequest/Box traits Create factory traits Oct 12, 2019
@maebeale maebeale changed the title Create factory traits Create factory_bot traits Oct 12, 2019
@leosoaivan
Copy link
Contributor

@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
Copy link
Collaborator Author

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
Copy link
Contributor

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

@maebeale
Copy link
Collaborator Author

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

@leosoaivan
Copy link
Contributor

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
Copy link
Collaborator Author

maebeale commented Oct 14, 2019

@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
Copy link
Contributor

@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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

@maebeale maebeale added Priority: Medium and removed Hacktoberfest Hacktoberfest issues for your resolution! labels Feb 12, 2020
@leosoaivan
Copy link
Contributor

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
Copy link
Collaborator Author

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
Copy link
Collaborator

I can work on setting up traits for boxes!

@RachelWyatt RachelWyatt self-assigned this Feb 22, 2020
@RachelWyatt RachelWyatt linked a pull request Mar 7, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants