Merge pull request #2007 from consul/fix/2000#already_voted_in_booth

Already voted in booth can't vote on website
This commit is contained in:
Raimond Garcia
2017-10-07 14:31:21 +02:00
committed by GitHub
3 changed files with 41 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
<div class="poll-question-answers">
<% if can? :answer, question %>
<% if can?(:answer, question) %>
<% question.question_answers.each do |answer| %>
<% if @answers_by_question_id[question.id] == answer.title && !voted_before_sign_in(question) %>
<% if @answers_by_question_id[question.id] == answer.title &&
(!voted_before_sign_in(question) ||
question.poll.voted_in_booth?(current_user)) %>
<span class="button answered"
title="<%= t("poll_questions.show.voted", answer: answer.title)%>">
<%= answer.title %>

View File

@@ -26,7 +26,7 @@ feature 'Answers' do
scenario 'Update' do
question = create(:poll_question)
answer = create(:poll_question_answer, question: question)
answer = create(:poll_question_answer, question: question, title: "Answer title")
visit admin_answer_path(answer)

View File

@@ -288,6 +288,42 @@ feature 'Polls' do
expect(page).to_not have_link('Chewbacca')
expect(page).to have_link('Han Solo')
end
end
context 'Booth & Website' do
let(:poll) { create(:poll, summary: "Summary", description: "Description") }
let(:booth) { create(:poll_booth) }
let(:officer) { create(:poll_officer) }
scenario 'Already voted on booth cannot vote on website', :js do
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment)
question = create(:poll_question, poll: poll)
create(:poll_question_answer, question: question, title: 'Han Solo')
create(:poll_question_answer, question: question, title: 'Chewbacca')
user = create(:user, :level_two, :in_census)
login_as(officer.user)
visit new_officing_residence_path
officing_verify_residence
click_button "Confirm vote"
expect(page).to have_content "Vote introduced!"
visit new_officing_residence_path
click_link "Sign out"
login_as user
visit poll_path(poll)
expect(page).to have_content "You have already participated in a physical booth. You can not participate again."
expect(page).to have_content('Han Solo')
expect(page).to have_content('Chewbacca')
expect(page).to_not have_link('Han Solo')
expect(page).to_not have_link('Chewbacca')
end
end
end