Move todays_booths_for_officer to the model

This way we can easily add a test which will fail if by accident we
change the method to use `Date.today`. Until now using `Date.today`
would only fail if we ran specs in a time zone with a different date.
This commit is contained in:
Javi Martín
2018-08-31 05:47:11 +02:00
parent a9d1fd3539
commit f7f9fc15a5
4 changed files with 23 additions and 6 deletions

View File

@@ -121,4 +121,21 @@ describe Poll::Officer do
expect(assigned_polls.last).to eq(poll_3)
end
end
describe "todays_booths" do
let(:officer) { create(:poll_officer) }
it "returns booths for the application's time zone date", :with_different_time_zone do
assignment_with_local_time_zone = create(:poll_officer_assignment,
date: Date.today,
officer: officer)
assignment_with_application_time_zone = create(:poll_officer_assignment,
date: Date.current,
officer: officer)
expect(officer.todays_booths).to include(assignment_with_application_time_zone.booth)
expect(officer.todays_booths).not_to include(assignment_with_local_time_zone.booth)
end
end
end