|
|
|
@ -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)) |
|
|
|
|
Singleton.__init__(described_class) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
Timecop.unfreeze |
|
|
|
|
around do |example| |
|
|
|
|
Timecop.freeze(now) do |
|
|
|
|
Singleton.__init__(described_class) |
|
|
|
|
example.run |
|
|
|
|
end |
|
|
|
|
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) |
|
|
|
|