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

Simplify poll factories #3384

Merged
merged 6 commits into from
Mar 20, 2019
Merged

Simplify poll factories #3384

merged 6 commits into from
Mar 20, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Mar 19, 2019

References

Objectives

  • Make it easier to write tests using poll voters in booths
  • Generate less records in the database during tests

The factories were creating strange database relations:

* The voter belonged to a poll, to a booth and to an officer
* The booth belonged to a different poll
* The officer belonged to a different booth

The code uses an unusual syntax because the following code:

association :booth_assignment,
            factory: :poll_booth_assignment,
            poll: poll

Would generate the following error:

ActiveRecord::AssociationTypeMismatch: Poll(#46976420451940) expected,
got FactoryBot::Declaration::Implicit
Adding the option to assign a poll to a poll recount factory meant we
didn't need to create so much data.

Also note we're removing the `create(:poll_voter, origin: "booth")`
code, since it isn't used in the stats calculations.
The line:

create(:poll_voter, booth_assignment: booth_assignment_final_recounted)

Creates a new poll for the poll voter. Not only it wastes time by
creating new database records, but it doesn't make sense to have a poll
voter for a poll which isn't the same as its booth assignment's poll.
For web poll voters, it isn't necessary in order to make the record
valid, and it adds an extra record to the database for each poll
voter created.
@javierm javierm merged commit 0fd9570 into master Mar 20, 2019
@javierm javierm deleted the backport-simplify_poll_factories branch March 20, 2019 13:32
@voodoorai2000 voodoorai2000 added this to Release 1.0.0-beta in Roadmap Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants