diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 490b32fbe..7fecefe98 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -9,6 +9,7 @@ class Polls::QuestionsController < ApplicationController answer = @question.answers.find_or_initialize_by(author: current_user) answer.answer = params[:answer] + answer.touch if answer.persisted? answer.save! answer.record_voter_participation diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index c66db216f..b6c0518bb 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -42,7 +42,7 @@ module PollsHelper end def voted_before_sign_in(question) - current_user.current_sign_in_at >= question.answers.find_or_initialize_by(author: current_user).updated_at + question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.updated_at } end end diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index c3211e1ab..91b90c23f 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -255,5 +255,39 @@ feature 'Polls' do expect(page).to have_link('Han Solo') end + scenario 'Level 2 votes, signs out, signs in, votes again', :js do + poll.update(geozone_restricted: true) + poll.geozones << geozone + + question = create(:poll_question, poll: poll) + answer1 = create(:poll_question_answer, question: question, title: 'Han Solo') + answer2 = create(:poll_question_answer, question: question, title: 'Chewbacca') + + user = create(:user, :level_two, geozone: geozone) + + login_as user + visit poll_path(poll) + click_link 'Han Solo' + + expect(page).to_not have_link('Han Solo') + expect(page).to have_link('Chewbacca') + + click_link "Sign out" + login_as user + visit poll_path(poll) + click_link 'Han Solo' + + expect(page).to_not have_link('Han Solo') + expect(page).to have_link('Chewbacca') + + click_link "Sign out" + login_as user + visit poll_path(poll) + click_link 'Chewbacca' + + expect(page).to_not have_link('Chewbacca') + expect(page).to have_link('Han Solo') + end + end end