Remove Poll::Voter record when there is no more user answers
Now we can remove answers we should provide a way of removing voting.
This commit is contained in:
@@ -3,12 +3,10 @@ require "rails_helper"
|
||||
describe "Voter" do
|
||||
context "Origin", :with_frozen_time do
|
||||
let(:poll) { create(:poll) }
|
||||
let(:question) { create(:poll_question, poll: poll) }
|
||||
let!(:question) { create(:poll_question, :yes_no, poll: poll) }
|
||||
let(:booth) { create(:poll_booth) }
|
||||
let(:officer) { create(:poll_officer) }
|
||||
let(:admin) { create(:administrator) }
|
||||
let!(:answer_yes) { create(:poll_question_answer, question: question, title: "Yes") }
|
||||
let!(:answer_no) { create(:poll_question_answer, question: question, title: "No") }
|
||||
|
||||
before do
|
||||
create(:geozone, :in_census)
|
||||
@@ -29,8 +27,34 @@ describe "Voter" do
|
||||
expect(page).not_to have_button("Vote Yes")
|
||||
end
|
||||
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
expect(Poll::Voter.first.origin).to eq("web")
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content("You have already participated in this poll.")
|
||||
expect(page).to have_content("If you vote again it will be overwritten")
|
||||
end
|
||||
|
||||
scenario "Remove vote via web - Standard" do
|
||||
user = create(:user, :level_two)
|
||||
create(:poll_answer, question: question, author: user, answer: "Yes")
|
||||
create(:poll_voter, poll: poll, user: user)
|
||||
|
||||
login_as user
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).to have_content("You have already participated in this poll.")
|
||||
expect(page).to have_content("If you vote again it will be overwritten")
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
click_button "You have voted Yes"
|
||||
|
||||
expect(page).to have_button("Vote Yes")
|
||||
expect(page).to have_button("Vote No")
|
||||
end
|
||||
|
||||
visit poll_path(poll)
|
||||
|
||||
expect(page).not_to have_content("You have already participated in this poll.")
|
||||
expect(page).not_to have_content("If you vote again it will be overwritten")
|
||||
end
|
||||
|
||||
scenario "Voting via web as unverified user" do
|
||||
@@ -40,8 +64,8 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).to have_link(answer_yes.title, href: verification_path)
|
||||
expect(page).to have_link(answer_no.title, href: verification_path)
|
||||
expect(page).to have_link("Yes", href: verification_path)
|
||||
expect(page).to have_link("No", href: verification_path)
|
||||
end
|
||||
|
||||
expect(page).to have_content("You must verify your account in order to answer")
|
||||
@@ -120,7 +144,7 @@ describe "Voter" do
|
||||
|
||||
scenario "Trying to vote in web and then in booth" do
|
||||
login_as user
|
||||
vote_for_poll_via_web(poll, question, answer_yes.title)
|
||||
vote_for_poll_via_web(poll, question, "Yes")
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
|
||||
click_link "Sign out"
|
||||
@@ -147,7 +171,7 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
expect(page).not_to have_button("Yes")
|
||||
end
|
||||
expect(page).to have_content "You have already participated in a physical booth. You can not participate again."
|
||||
expect(Poll::Voter.count).to eq(1)
|
||||
@@ -186,7 +210,7 @@ describe "Voter" do
|
||||
visit poll_path(poll)
|
||||
|
||||
within("#poll_question_#{question.id}_answers") do
|
||||
expect(page).not_to have_button(answer_yes.title)
|
||||
expect(page).not_to have_button("Yes")
|
||||
end
|
||||
|
||||
expect(page).to have_content "You have already participated in a physical booth. You can not participate again."
|
||||
|
||||
Reference in New Issue
Block a user