rubyforgood/voices-of-consent

Create factory_bot traits

Open

#310 opened on Oct 12, 2019

View on GitHub
 (12 comments) (0 reactions) (1 assignee)Ruby (80 forks)auto 404
Priority: Mediumhelp wanted

Repository metrics

Stars
 (40 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide