From 4830b563eae0137b35297d6e2b76e6bf3c861f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 11 Jan 2019 20:41:14 +0100 Subject: [PATCH] Create only one poll for a poll voter 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 --- spec/factories/polls.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index e8139e25c..51da0246b 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -92,7 +92,10 @@ FactoryBot.define do trait :from_booth do origin "booth" - association :booth_assignment, factory: :poll_booth_assignment + + booth_assignment do + association :poll_booth_assignment, poll: poll + end officer_assignment do association :poll_officer_assignment, booth_assignment: booth_assignment, officer: officer