Browse Source

tidy Timecop calls (#1053)

pull/1057/head
Phil Lee 2 years ago committed by GitHub
parent
commit
b10d9f9cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      spec/models/form_handler_spec.rb

35
spec/models/form_handler_spec.rb

@ -2,27 +2,18 @@ require "rails_helper"
RSpec.describe FormHandler do
let(:form_handler) { described_class.instance }
let(:now) { Time.utc(2022, 9, 20) }
before do
Timecop.freeze(Time.utc(2022, 9, 20))
around do |example|
Timecop.freeze(now) do
Singleton.__init__(described_class)
example.run
end
after do
Timecop.unfreeze
Singleton.__init__(described_class)
end
context "when accessing a form in a different year" do
before do
Timecop.freeze(Time.utc(2021, 8, 3))
Singleton.__init__(described_class)
end
after do
Timecop.unfreeze
Singleton.__init__(described_class) # reload FormHandler Instance to update form definitions between runs
end
let(:now) { Time.utc(2021, 8, 3) }
it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings")
@ -83,13 +74,7 @@ RSpec.describe FormHandler do
describe "Current collection start year" do
context "when the date is after 1st of April" do
before do
Timecop.freeze(Time.utc(2022, 8, 3))
end
after do
Timecop.unfreeze
end
let(:now) { Time.utc(2022, 8, 3) }
it "returns the same year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2022)
@ -125,13 +110,7 @@ RSpec.describe FormHandler do
end
context "with the date before 1st of April" do
before do
Timecop.freeze(Time.utc(2022, 2, 3))
end
after do
Timecop.unfreeze
end
let(:now) { Time.utc(2022, 2, 3) }
it "returns the previous year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2021)

Loading…
Cancel
Save