Add booth and officing assigments presence validation for booth votes, unskip specs

This commit is contained in:
Bertocq
2017-10-21 01:09:53 +02:00
committed by Javi Martín
parent 94c37eb588
commit 31428a5847
2 changed files with 24 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ class Poll
validates :poll_id, presence: true
validates :user_id, presence: true
validates :booth_assignment_id, presence: true, if: ->(voter) { voter.origin == "booth" }
validates :officer_assignment_id, presence: true, if: ->(voter) { voter.origin == "booth" }
validates :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted }
validates :origin, inclusion: { in: VALID_ORIGINS }

View File

@@ -6,6 +6,7 @@ describe Poll::Voter do
let(:booth) { create(:poll_booth) }
let(:booth_assignment) { create(:poll_booth_assignment, poll: poll, booth: booth) }
let(:voter) { create(:poll_voter) }
let(:officer_assignment) { create(:poll_officer_assignment) }
describe "validations" do
@@ -97,6 +98,7 @@ describe Poll::Voter do
it "is valid with a booth origin" do
voter.origin = "booth"
voter.officer_assignment = officer_assignment
expect(voter).to be_valid
end
@@ -104,7 +106,27 @@ describe Poll::Voter do
voter.origin = "web"
expect(voter).to be_valid
end
end
context "assignments" do
it "should not be valid without a booth_assignment_id when origin is booth" do
voter.origin = "booth"
voter.booth_assignment_id = nil
expect(voter).not_to be_valid
end
it "should not be valid without an officer_assignment_id when origin is booth" do
voter.origin = "booth"
voter.officer_assignment_id = nil
expect(voter).not_to be_valid
end
it "should be valid without assignments when origin is web" do
voter.origin = "web"
voter.booth_assignment_id = nil
voter.officer_assignment_id = nil
expect(voter).to be_valid
end
end
end