Simplify assigning booth to a voter

Unless we're using the booth assignment for something else in the test,
when creating a voter from booth, specifying the poll and the booth is
enough to create a booth assignment.
This commit is contained in:
Javi Martín
2019-09-28 15:23:50 +02:00
parent c15b58f927
commit 19edf0466b
2 changed files with 12 additions and 14 deletions

View File

@@ -202,8 +202,10 @@ FactoryBot.define do
trait :from_booth do
origin { "booth" }
transient { booth { association(:poll_booth) } }
booth_assignment do
association :poll_booth_assignment, poll: poll
association :poll_booth_assignment, poll: poll, booth: booth
end
officer_assignment do

View File

@@ -51,28 +51,24 @@ describe Poll::Voter do
end
it "is not valid if the user has already voted in different booth in the same poll" do
booth_assignment1 = create(:poll_booth_assignment, poll: poll)
booth_assignment2 = create(:poll_booth_assignment, poll: poll)
user = create(:user, :level_two)
voter1 = create(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment1)
voter2 = build(:poll_voter, user: user, poll: poll, booth_assignment: booth_assignment2)
create(:poll_voter, :from_booth, user: user, poll: poll, booth: create(:poll_booth))
expect(voter2).not_to be_valid
expect(voter2.errors.messages[:document_number]).to eq(["User has already voted"])
voter = build(:poll_voter, :from_booth, user: user, poll: poll, booth: booth)
expect(voter).not_to be_valid
expect(voter.errors.messages[:document_number]).to eq(["User has already voted"])
end
it "is valid if the user has already voted in the same booth in different poll" do
booth_assignment1 = create(:poll_booth_assignment, booth: booth)
booth_assignment2 = create(:poll_booth_assignment, booth: booth, poll: poll)
user = create(:user, :level_two)
voter1 = create(:poll_voter, user: user, booth_assignment: booth_assignment1)
voter2 = build(:poll_voter, user: user, booth_assignment: booth_assignment2)
create(:poll_voter, :from_booth, user: user, booth: booth, poll: create(:poll))
expect(voter2).to be_valid
voter = build(:poll_voter, :from_booth, user: user, booth: booth, poll: poll)
expect(voter).to be_valid
end
it "is not valid if the user has voted via web" do