From 9f3b2bba28955e8f1bcd0f31f53ee17f3878f793 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:44:09 +0000 Subject: [PATCH] CLDC-2032 test log creation in crossover period (#1420) * ensure that no form is added to the forms hash under the key "nil" * add a test to ensure that the form handler does not add outdated forms to the forms hash with key nil * remove unnecessary singleton reinitialisation * remove a duplicated Timecop around block --- app/models/form_handler.rb | 2 +- spec/models/form_handler_spec.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 12ae4473b..b2d9168b2 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -47,7 +47,7 @@ class FormHandler form = Form.new(form_path) form_to_set = form_name_from_start_year(form.start_date.year, "lettings") - forms[form_to_set] = form if forms[form_to_set].blank? + forms[form_to_set] = form if form_to_set && forms[form_to_set].blank? end end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 417da6639..ec2ddbecc 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -9,8 +9,6 @@ RSpec.describe FormHandler do Singleton.__init__(described_class) example.run end - Timecop.return - Singleton.__init__(described_class) end context "when accessing a form in a different year" do @@ -35,6 +33,15 @@ RSpec.describe FormHandler do expect(all_forms.count).to be >= 1 expect(all_forms["current_sales"]).to be_a(Form) end + + context "when in 23/24 period or later" do + let(:now) { Time.utc(2023, 6, 7) } + + it "does not load outdated forms" do + all_forms = form_handler.forms + expect(all_forms.keys).not_to include nil + end + end end describe "Get specific form" do