diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 0d5b0a605..0cb875dff 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -46,7 +46,7 @@ module PollsHelper end def voted_before_sign_in(question) - question.answers.where(author: current_user).any? { |vote| current_user.current_sign_in_at >= vote.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 a2e009f77..b95bb8129 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -387,18 +387,12 @@ feature 'Polls' do end end - context 'Booth & Website' do + context 'Booth & Website', :with_frozen_time do - let(:poll) { create(:poll, summary: "Summary", description: "Description", starts_at: '2017-12-01', ends_at: '2018-02-01') } + let(:poll) { create(:poll, summary: "Summary", description: "Description") } let(:booth) { create(:poll_booth) } let(:officer) { create(:poll_officer) } - before do - allow(Date).to receive(:current).and_return Date.new(2018,1,1) - allow(Date).to receive(:today).and_return Date.new(2018,1,1) - allow(Time).to receive(:current).and_return Time.zone.parse("2018-01-01 12:00:00") - end - scenario 'Already voted on booth cannot vote on website', :js do create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index 5ba89fc3c..f7f1b58c8 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Voter" do - context "Origin" do + context "Origin", :with_frozen_time do let(:poll) { create(:poll, :current) } let(:question) { create(:poll_question, poll: poll) } @@ -125,12 +125,18 @@ feature "Voter" do click_link "Sign out" - login_as user - visit poll_path(poll) + # Time needs to pass between the moment we vote and the moment + # we log in; otherwise the link to vote won't be available. + # It's safe to advance one second because this test isn't + # affected by possible date changes. + travel 1.second do + login_as user + visit poll_path(poll) - within("#poll_question_#{question.id}_answers") do - expect(page).to have_link(answer_yes.title) - expect(page).to have_link(answer_no.title) + within("#poll_question_#{question.id}_answers") do + expect(page).to have_link(answer_yes.title) + expect(page).to have_link(answer_no.title) + end end end end