Allow voting when skip verification is enabled

This commit is contained in:
decabeza
2020-06-18 10:05:14 +02:00
committed by Javi Martín
parent 24ccf23ed8
commit 4367b2054a
2 changed files with 14 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ class Poll
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 :document_number, presence: true, uniqueness: { scope: [:poll_id, :document_type], message: :has_voted }, unless: :skip_user_verification?
validates :origin, inclusion: { in: VALID_ORIGINS }
before_validation :set_demographic_info, :set_document_info, :set_denormalized_booth_assignment_id
@@ -38,6 +38,10 @@ class Poll
self.document_number = user.document_number
end
def skip_user_verification?
Setting["feature.user.skip_verification"].present?
end
private
def set_denormalized_booth_assignment_id

View File

@@ -172,5 +172,14 @@ describe Poll::Voter do
expect(voter.document_type).to eq("1")
expect(voter.token).to eq("1234abcd")
end
it "sets user info with skip verification enabled" do
Setting["feature.user.skip_verification"] = true
user = create(:user)
voter = build(:poll_voter, user: user, token: "1234abcd")
voter.save!
expect(voter.token).to eq("1234abcd")
end
end
end