Skip to content

Commit

Permalink
Avoid date changes during results tests.
Browse files Browse the repository at this point in the history
As explained by @iagirre with pinpoint accuracy [1]:

"If the officer_assignments are created at 23:59:59 and the rest of the
test is executed after 00:00:00, the dates for the objects and the
`Date.current` (used to check if there are any shifts today) won't be
the same, because the shift will be for, lets say, 07/03/2018 and
`Date.current` will be 08/03/2018, so, there are no shifts."

Freezing time avoids this issue.

Related to issues consuldemocracy#2520 and consuldemocracy#2521.

[1] AyuntamientoMadrid#1342
  • Loading branch information
javierv committed Jul 8, 2018
1 parent 2c0c592 commit 4a559ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/features/officing/results_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'rails_helper'
require 'time_helper'

feature 'Officing Results' do

background do
freeze_time
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
Expand All @@ -17,6 +19,10 @@
login_as(@poll_officer.user)
end

after do
travel_back
end

scenario 'Only polls where user is officer for results are accessible' do
regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
Expand Down
8 changes: 8 additions & 0 deletions spec/time_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ActiveSupport::Testing::TimeHelpers
# Copied from Rails 5.2. TODO: remove after migrating to Rails 5.
def freeze_time(&block)
travel_to Time.now, &block
end
end

include ActiveSupport::Testing::TimeHelpers

0 comments on commit 4a559ed

Please sign in to comment.