Avoid using Time.now and Date.today in zone tests
We've got a rubocop rule preventing us from using them, and the tests are easier to read this way.
This commit is contained in:
@@ -124,20 +124,19 @@ describe Poll::Officer do
|
||||
end
|
||||
end
|
||||
|
||||
describe "todays_booths" do
|
||||
describe "todays_booths", :application_zone_west_of_system_zone do
|
||||
let(:officer) { create(:poll_officer) }
|
||||
|
||||
it "returns booths for the application's time zone date", :application_zone_west_of_system_zone do
|
||||
assignment_with_local_time_zone = create(:poll_officer_assignment,
|
||||
date: Date.today,
|
||||
officer: officer)
|
||||
it "returns today's booths" do
|
||||
todays_assignment = create(:poll_officer_assignment, date: Date.current, officer: officer)
|
||||
expect(officer.todays_booths).to eq [todays_assignment.booth]
|
||||
end
|
||||
|
||||
assignment_with_application_time_zone = create(:poll_officer_assignment,
|
||||
date: Date.current,
|
||||
officer: officer)
|
||||
it "does not return booths for different dates" do
|
||||
create(:poll_officer_assignment, date: Date.yesterday, officer: officer)
|
||||
create(:poll_officer_assignment, date: Date.tomorrow, officer: officer)
|
||||
|
||||
expect(officer.todays_booths).to eq [assignment_with_application_time_zone.booth]
|
||||
expect(officer.todays_booths).not_to include(assignment_with_local_time_zone.booth)
|
||||
expect(officer.todays_booths).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,8 +114,11 @@ RSpec.configure do |config|
|
||||
system_zone = ActiveSupport::TimeZone.new("Madrid")
|
||||
|
||||
allow(Time).to receive(:zone).and_return(application_zone)
|
||||
allow(Time).to receive(:now).and_return(Date.current.end_of_day.in_time_zone(system_zone))
|
||||
allow(Date).to receive(:today).and_return(Time.now.to_date)
|
||||
|
||||
system_time_at_application_end_of_day = Date.current.end_of_day.in_time_zone(system_zone)
|
||||
|
||||
allow(Time).to receive(:now).and_return(system_time_at_application_end_of_day)
|
||||
allow(Date).to receive(:today).and_return(system_time_at_application_end_of_day.to_date)
|
||||
end
|
||||
|
||||
config.before(:each, :with_non_utc_time_zone) do
|
||||
|
||||
Reference in New Issue
Block a user