Merge pull request #2005 from consul/fix/2002#voting_after_singout
Allow re-casting an answer after singout
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user