Avoid date changes during results tests.
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 #2520 and #2521. [1] https://github.com/AyuntamientoMadrid/consul/pull/1342
This commit is contained in:
@@ -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
|
||||
@@ -17,6 +19,10 @@ feature 'Officing Results' do
|
||||
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)
|
||||
|
||||
8
spec/time_helper.rb
Normal file
8
spec/time_helper.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user