From ccc8d9e8ea835b68fbe6e16013cc05364f3363dc Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 8 Mar 2018 16:57:07 +0100 Subject: [PATCH] Stub the Date and Time classes so that the test doesn't depend on the time it is run. --- spec/features/polls/polls_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index be6e6ff4e..a7a181623 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -352,15 +352,21 @@ feature 'Polls' do context 'Booth & Website' do - let(:poll) { create(:poll, summary: "Summary", description: "Description") } + let(:poll) { create(:poll, summary: "Summary", description: "Description", starts_at: '2017-12-01', ends_at: '2018-02-01') } 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) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment, date: Date.current) question = create(:poll_question, poll: poll) create(:poll_question_answer, question: question, title: 'Han Solo') create(:poll_question_answer, question: question, title: 'Chewbacca')