From f6f978d75c6241feb449e9b8ab83065f4b471898 Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Thu, 12 Feb 2026 10:28:34 +0000 Subject: [PATCH] Fix/add tests --- .../subsections/tenancy_information.rb | 2 +- .../subsections/tenancy_information_spec.rb | 20 ++++++++++ .../validations/soft_validations_spec.rb | 38 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/models/form/lettings/subsections/tenancy_information.rb b/app/models/form/lettings/subsections/tenancy_information.rb index 51c58fec5..e6ff48457 100644 --- a/app/models/form/lettings/subsections/tenancy_information.rb +++ b/app/models/form/lettings/subsections/tenancy_information.rb @@ -12,8 +12,8 @@ class Form::Lettings::Subsections::TenancyInformation < ::Form::Subsection Form::Lettings::Pages::StarterTenancy.new("starter_tenancy", nil, self), Form::Lettings::Pages::TenancyType.new(nil, nil, self), Form::Lettings::Pages::StarterTenancyType.new(nil, nil, self), - Form::Lettings::Pages::TenancyLength.new(nil, nil, self), (Form::Lettings::Pages::TenancyotherValueCheck.new(nil, nil, self) if form.start_year_2026_or_later?), + Form::Lettings::Pages::TenancyLength.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthAffordableRent.new(nil, nil, self), Form::Lettings::Pages::TenancyLengthIntermediateRent.new(nil, nil, self), (Form::Lettings::Pages::TenancyLengthPeriodic.new(nil, nil, self) if form.start_year_2024_or_later?), diff --git a/spec/models/form/lettings/subsections/tenancy_information_spec.rb b/spec/models/form/lettings/subsections/tenancy_information_spec.rb index 70663629c..290850cf6 100644 --- a/spec/models/form/lettings/subsections/tenancy_information_spec.rb +++ b/spec/models/form/lettings/subsections/tenancy_information_spec.rb @@ -18,6 +18,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do before do allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(false) + allow(form).to receive(:start_year_2026_or_later?).and_return(false) end context "when 2023" do @@ -26,6 +27,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do before do allow(form).to receive(:start_year_2024_or_later?).and_return(false) allow(form).to receive(:start_year_2025_or_later?).and_return(false) + allow(form).to receive(:start_year_2026_or_later?).and_return(false) end it "has correct pages" do @@ -41,6 +43,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do before do allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(false) + allow(form).to receive(:start_year_2026_or_later?).and_return(false) end it "has correct pages" do @@ -56,6 +59,7 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do before do allow(form).to receive(:start_year_2024_or_later?).and_return(true) allow(form).to receive(:start_year_2025_or_later?).and_return(true) + allow(form).to receive(:start_year_2026_or_later?).and_return(false) end it "has correct pages" do @@ -64,6 +68,22 @@ RSpec.describe Form::Lettings::Subsections::TenancyInformation, type: :model do ) end end + + context "when 2026" do + let(:start_date) { Time.utc(2026, 2, 8) } + + before do + allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(true) + allow(form).to receive(:start_year_2026_or_later?).and_return(true) + end + + it "has correct pages" do + expect(tenancy_information.pages.map(&:id)).to eq( + %w[joint starter_tenancy tenancy_type starter_tenancy_type tenancyother_value_check tenancy_length tenancy_length_affordable_rent tenancy_length_intermediate_rent tenancy_length_periodic], + ) + end + end end it "has the correct id" do diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 6c39824c5..017a67333 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -1355,6 +1355,44 @@ RSpec.describe Validations::SoftValidations do end end + describe "tenancyother_might_be_introductory_or_starter_period?" do + it "returns true if tenancyother is exactly in the 'likely introductory/starter period' list" do + record.tenancyother = "introductory" + + expect(record).to be_tenancyother_might_be_introductory_or_starter_period + end + + it "returns true if any word of tenancyother is exactly in the 'likely introductory/starter period' list" do + record.tenancyother = "a starter tenancy" + + expect(record).to be_tenancyother_might_be_introductory_or_starter_period + end + + it "is not case sensitive when matching" do + record.tenancyother = "Intro" + + expect(record).to be_tenancyother_might_be_introductory_or_starter_period + end + + it "returns false if no part of tenancyother is in the 'likely introductory/starter period' list" do + record.tenancyother = "other" + + expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period + end + + it "returns false if match to the 'likely introductory/starter period' list is only part of a word" do + record.tenancyother = "wasintroductory" + + expect(record).not_to be_tenancyother_might_be_introductory_or_starter_period + end + + it "ignores neighbouring non-alphabet for matching" do + record.tenancyother = "1starter." + + expect(record).to be_tenancyother_might_be_introductory_or_starter_period + end + end + describe "at_least_one_working_situation_is_sickness_and_household_sickness_is_no" do it "returns true if one person has working situation as illness and household sickness is no" do record.illness = 2