diff --git a/app/models/form.rb b/app/models/form.rb index 2eb4c0747..7e13a4fa0 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -323,4 +323,8 @@ class Form def sales_or_start_year_after_2022?(type, start_year) type == "sales" || (start_year && start_year.to_i > 2022) end + + def start_year_after_2024? + start_date && start_date.year >= 2024 + end end diff --git a/app/models/form/lettings/questions/renewal.rb b/app/models/form/lettings/questions/renewal.rb index 418b64a37..1320a0f45 100644 --- a/app/models/form/lettings/questions/renewal.rb +++ b/app/models/form/lettings/questions/renewal.rb @@ -17,7 +17,7 @@ class Form::Lettings::Questions::Renewal < ::Form::Question .freeze def header_text - if form.start_date && form.start_date.year >= 2024 + if form.start_year_after_2024? "Is this letting a renewal of social housing to the same tenant in the same property?" else "Is this letting a renewal?" @@ -25,7 +25,7 @@ class Form::Lettings::Questions::Renewal < ::Form::Question end def hint_text - if form.start_date && form.start_date.year >= 2024 + if form.start_year_after_2024? "If the property was previously being used as temporary accommodation, then answer 'no'" else "A renewal is a letting to the same tenant in the same property. If the property was previously being used as temporary accommodation, then answer 'no'" diff --git a/spec/models/form/lettings/pages/renewal_spec.rb b/spec/models/form/lettings/pages/renewal_spec.rb index b4bfb213b..6a6be457d 100644 --- a/spec/models/form/lettings/pages/renewal_spec.rb +++ b/spec/models/form/lettings/pages/renewal_spec.rb @@ -6,6 +6,12 @@ RSpec.describe Form::Lettings::Pages::Renewal, type: :model do let(:page_id) { nil } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + allow(subsection).to receive(:form).and_return(form) + end it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/lettings/questions/renewal_spec.rb b/spec/models/form/lettings/questions/renewal_spec.rb index 9b01ea5cc..c1c4f5d77 100644 --- a/spec/models/form/lettings/questions/renewal_spec.rb +++ b/spec/models/form/lettings/questions/renewal_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do let(:form) { instance_double(Form) } before do - allow(form).to receive(:start_date).and_return(Time.zone.local(2023, 4, 1)) + allow(form).to receive(:start_year_after_2024?).and_return(false) allow(page).to receive(:subsection).and_return(subsection) allow(subsection).to receive(:form).and_return(form) end @@ -52,7 +52,7 @@ RSpec.describe Form::Lettings::Questions::Renewal, type: :model do context "with collection year on or after 2024" do before do - allow(form).to receive(:start_date).and_return(Time.zone.local(2024, 4, 1)) + allow(form).to receive(:start_year_after_2024?).and_return(true) end it "has the correct header" do