From 44a0b1acb84182c474d88710b1ded701e9d7ab04 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:48:40 +0100 Subject: [PATCH] CLDC-3405-update-retirement-age-validation (#2384) * update retirement soft validation pages and copy in en.yml to reflect changes in english retirement age * update soft validation tests to display interruption screens under the correct conditions given changes to state retirement age reduction of variation in retirement age means lots of code related to determining the retirement age given an individuals gender can also be removed testing updated --- ...lead_tenant_over_retirement_value_check.rb | 17 +--- .../person_over_retirement_value_check.rb | 21 +---- app/models/lettings_log.rb | 8 -- app/models/log.rb | 4 - app/models/sales_log.rb | 8 -- app/models/validations/soft_validations.rb | 11 ++- config/locales/en.yml | 6 +- ...person_over_retirement_value_check_spec.rb | 38 --------- spec/models/lettings_log_spec.rb | 58 +------------ .../validations/soft_validations_spec.rb | 82 +++++++++++-------- 10 files changed, 63 insertions(+), 190 deletions(-) diff --git a/app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb b/app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb index 9d21e21a8..b5add868b 100644 --- a/app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb +++ b/app/models/form/lettings/pages/lead_tenant_over_retirement_value_check.rb @@ -4,24 +4,9 @@ class Form::Lettings::Pages::LeadTenantOverRetirementValueCheck < ::Form::Page @depends_on = [{ "person_1_not_retired_over_soft_max_age?" => true }] @title_text = { "translation" => "soft_validations.retirement.max.title", - "arguments" => [ - { - "key" => "retirement_age_for_person_1", - "label" => false, - "i18n_template" => "age", - }, - ], } @informative_text = { "translation" => "soft_validations.retirement.max.hint_text", - "arguments" => [ - { "key" => "plural_gender_for_person_1", "label" => false, "i18n_template" => "gender" }, - { - "key" => "retirement_age_for_person_1", - "label" => false, - "i18n_template" => "age", - }, - ], } end @@ -30,6 +15,6 @@ class Form::Lettings::Pages::LeadTenantOverRetirementValueCheck < ::Form::Page end def interruption_screen_question_ids - %w[ecstat1 sex1 age1] + %w[ecstat1 age1] end end diff --git a/app/models/form/lettings/pages/person_over_retirement_value_check.rb b/app/models/form/lettings/pages/person_over_retirement_value_check.rb index 550ae0373..dbaf2d2e2 100644 --- a/app/models/form/lettings/pages/person_over_retirement_value_check.rb +++ b/app/models/form/lettings/pages/person_over_retirement_value_check.rb @@ -4,28 +4,9 @@ class Form::Lettings::Pages::PersonOverRetirementValueCheck < ::Form::Page @depends_on = [{ "person_#{person_index}_not_retired_over_soft_max_age?" => true }] @title_text = { "translation" => "soft_validations.retirement.max.title", - "arguments" => [ - { - "key" => "retirement_age_for_person_#{person_index}", - "label" => false, - "i18n_template" => "age", - }, - ], } @informative_text = { "translation" => "soft_validations.retirement.max.hint_text", - "arguments" => [ - { - "key" => "plural_gender_for_person_#{person_index}", - "label" => false, - "i18n_template" => "gender", - }, - { - "key" => "retirement_age_for_person_#{person_index}", - "label" => false, - "i18n_template" => "age", - }, - ], } @person_index = person_index end @@ -35,6 +16,6 @@ class Form::Lettings::Pages::PersonOverRetirementValueCheck < ::Form::Page end def interruption_screen_question_ids - ["ecstat#{@person_index}", "sex#{@person_index}", "age#{@person_index}"] + ["ecstat#{@person_index}", "age#{@person_index}"] end end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index be0399f77..c9e4f7af0 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -138,7 +138,6 @@ class LettingsLog < Log HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52, 10 => 53 }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze - RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 ecstat1 tcharge household_charge chcharge].freeze RENT_TYPE = { social_rent: 0, @@ -555,13 +554,6 @@ class LettingsLog < Log OPTIONAL_FIELDS + dynamically_not_required end - def retirement_age_for_person(person_num) - gender = public_send("sex#{person_num}".to_sym) - return unless gender - - RETIREMENT_AGES[gender] - end - def age_unknown?(person_num) return false unless person_num.is_a?(Integer) diff --git a/app/models/log.rb b/app/models/log.rb index cc0367daf..a3e9e3c33 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -205,10 +205,6 @@ class Log < ApplicationRecord end (1..8).each do |person_num| - define_method("retirement_age_for_person_#{person_num}") do - retirement_age_for_person(person_num) - end - define_method("plural_gender_for_person_#{person_num}") do plural_gender_for_person(person_num) end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 4c241c735..7fb19fa26 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -85,7 +85,6 @@ class SalesLog < Log } OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze - RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 ecstat1 postcode_full].freeze def lettings? @@ -368,13 +367,6 @@ class SalesLog < Log update!(created_by: nil) end - def retirement_age_for_person(person_num) - gender = public_send("sex#{person_num}".to_sym) - return unless gender - - RETIREMENT_AGES[gender] - end - def joint_purchase? jointpur == 1 end diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index e5b5f9c88..5f1ac9c7a 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -239,18 +239,17 @@ private economic_status = public_send("ecstat#{person_num}") return unless age && economic_status - tenant_is_retired?(economic_status) && age < 60 + tenant_is_retired?(economic_status) && age < 66 end def not_retired_over_soft_max_age?(person_num) age = public_send("age#{person_num}") economic_status = public_send("ecstat#{person_num}") - gender = public_send("sex#{person_num}") - tenant_retired_or_prefers_not_say = tenant_is_retired?(economic_status) || tenant_prefers_not_to_say?(economic_status) - return unless age && economic_status && gender + return unless age && economic_status + + return false if tenant_prefers_not_to_say?(economic_status) - %w[M X].include?(gender) && !tenant_retired_or_prefers_not_say && age > retirement_age_for_person(person_num) || - gender == "F" && !tenant_retired_or_prefers_not_say && age > 60 + !tenant_is_retired?(economic_status) && age > 66 end def partner_under_16?(person_num) diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b3d0f206..ce9c29c4b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -689,10 +689,10 @@ Make sure these answers are correct." retirement: min: title: "You told us this person is aged %{age} years and retired." - hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + hint_text: "The minimum expected retirement age in England is 66." max: - title: "You told us this person is %{age} or over and not retired" - hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + title: "You told us this person is over 66 and not retired" + hint_text: "The minimum expected retirement age in England is 66." extra_borrowing: title_text: "You told us that the mortgage and deposit total is %{mortgage_and_deposit_total}" hint_text: "This is higher than the purchase price minus the discount." diff --git a/spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb b/spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb index 22613095d..4cebf77b7 100644 --- a/spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb +++ b/spec/models/form/lettings/pages/person_over_retirement_value_check_spec.rb @@ -33,31 +33,12 @@ RSpec.describe Form::Lettings::Pages::PersonOverRetirementValueCheck, type: :mod it "has the correct title_text" do expect(page.title_text).to eq({ "translation" => "soft_validations.retirement.max.title", - "arguments" => [ - { - "key" => "retirement_age_for_person_2", - "label" => false, - "i18n_template" => "age", - }, - ], }) end it "has the correct informative_text" do expect(page.informative_text).to eq({ "translation" => "soft_validations.retirement.max.hint_text", - "arguments" => [ - { - "key" => "plural_gender_for_person_2", - "label" => false, - "i18n_template" => "gender", - }, - { - "key" => "retirement_age_for_person_2", - "label" => false, - "i18n_template" => "age", - }, - ], }) end end @@ -74,31 +55,12 @@ RSpec.describe Form::Lettings::Pages::PersonOverRetirementValueCheck, type: :mod it "has the correct title_text" do expect(page.title_text).to eq({ "translation" => "soft_validations.retirement.max.title", - "arguments" => [ - { - "key" => "retirement_age_for_person_3", - "label" => false, - "i18n_template" => "age", - }, - ], }) end it "has the correct informative_text" do expect(page.informative_text).to eq({ "translation" => "soft_validations.retirement.max.hint_text", - "arguments" => [ - { - "key" => "plural_gender_for_person_3", - "label" => false, - "i18n_template" => "gender", - }, - { - "key" => "retirement_age_for_person_3", - "label" => false, - "i18n_template" => "age", - }, - ], }) end end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 1eef5dbfd..067a4026d 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -3382,61 +3382,11 @@ RSpec.describe LettingsLog do end end - describe "#retirement_age_for_person" do - context "when a person gender is Male" do - let(:lettings_log) { build(:lettings_log, sex1: "M") } + context "when a postcode contains unicode characters" do + let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") } - it "returns the expected retirement age" do - expect(lettings_log.retirement_age_for_person_1).to eq(67) - end - - it "returns the expected plural" do - expect(lettings_log.plural_gender_for_person_1).to eq("male and non-binary people") - end - end - - context "when a person gender is Female" do - let(:lettings_log) { build(:lettings_log, sex2: "F") } - - it "returns the expected retirement age" do - expect(lettings_log.retirement_age_for_person_2).to eq(60) - end - - it "returns the expected plural" do - expect(lettings_log.plural_gender_for_person_2).to eq("females") - end - end - - context "when a person gender is Non-Binary" do - let(:lettings_log) { build(:lettings_log, sex3: "X") } - - it "returns the expected retirement age" do - expect(lettings_log.retirement_age_for_person_3).to eq(67) - end - - it "returns the expected plural" do - expect(lettings_log.plural_gender_for_person_3).to eq("male and non-binary people") - end - end - - context "when the person gender is not set" do - let(:lettings_log) { build(:lettings_log) } - - it "returns nil" do - expect(lettings_log.retirement_age_for_person_3).to be_nil - end - - it "returns the expected plural" do - expect(lettings_log.plural_gender_for_person_3).to be_nil - end - end - - context "when a postcode contains unicode characters" do - let(:lettings_log) { build(:lettings_log, postcode_full: "SR81LS\u00A0") } - - it "triggers a validation error" do - expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/) - end + it "triggers a validation error" do + expect { lettings_log.save! }.to raise_error(ActiveRecord::RecordInvalid, /Enter a postcode in the correct format/) end end diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 5c3d76f6f..601c5640e 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -83,62 +83,78 @@ RSpec.describe Validations::SoftValidations do end describe "retirement soft validations" do - context "when the tenant is retired but under the expected retirement age" do - it "shows the interruption screen" do - record.update!(age1: 43, ecstat1: 5) - expect(record.person_1_retired_under_soft_min_age?).to be true - end + before do + record.update!(age1:, ecstat1:) end - context "when the tenant is not retired but over the expected retirement age" do - context "when the tenant is female" do - it "shows the interruption screen" do - record.update!(age1: 85, sex1: "F", ecstat1: 3) - expect(record.person_1_not_retired_over_soft_max_age?).to be true + context "when the tenant is under the expected retirement age" do + let(:age1) { 60 } + + context "and the tenant's economic status is nil" do + let(:ecstat1) { nil } + + it "does not show the interruption screen" do + expect(record).not_to be_person_1_retired_under_soft_min_age end end - context "when the tenant is male" do - it "shows the interruption screen" do - record.update!(age1: 85, sex1: "M", ecstat1: 3) - expect(record.person_1_not_retired_over_soft_max_age?).to be true + context "and the tenant is retired" do + let(:ecstat1) { 5 } + + it "does show the interruption screen" do + expect(record).to be_person_1_retired_under_soft_min_age end end - context "when the tenant is non-binary" do - it "shows the interruption screen" do - record.update!(age1: 85, sex1: "X", ecstat1: 3) - expect(record.person_1_not_retired_over_soft_max_age?).to be true + context "and the tenant is not retired" do + let(:ecstat1) { 3 } + + it "does not show the interruption screen" do + expect(record).not_to be_person_1_retired_under_soft_min_age end end - end - context "when the tenant prefers not to say what their economic status is but is under the expected retirement age" do - it "does not show the interruption screen" do - record.update!(age1: 43, ecstat1: 10) - expect(record.person_1_retired_under_soft_min_age?).to be false + context "and the tenant prefers not to say" do + let(:ecstat1) { 10 } + + it "does not show the interruption screen" do + expect(record).not_to be_person_1_retired_under_soft_min_age + end end end - context "when the tenant prefers not to say what their economic status is but is over the expected retirement age" do - context "when the tenant is female" do + context "when the tenant is over the expected retirement age" do + let(:age1) { 70 } + + context "and the tenant's economic status is nil" do + let(:ecstat1) { nil } + it "does not show the interruption screen" do - record.update!(age1: 85, sex1: "F", ecstat1: 10) - expect(record.person_1_not_retired_over_soft_max_age?).to be false + expect(record).not_to be_person_1_not_retired_over_soft_max_age end end - context "when the tenant is male" do + context "and the tenant is retired" do + let(:ecstat1) { 5 } + it "does not show the interruption screen" do - record.update!(age1: 85, sex1: "M", ecstat1: 10) - expect(record.person_1_not_retired_over_soft_max_age?).to be false + expect(record).not_to be_person_1_not_retired_over_soft_max_age end end - context "when the tenant is non-binary" do + context "and the tenant is not retired" do + let(:ecstat1) { 3 } + + it "does show the interruption screen" do + expect(record).to be_person_1_not_retired_over_soft_max_age + end + end + + context "and the tenant prefers not to say" do + let(:ecstat1) { 10 } + it "does not show the interruption screen" do - record.update!(age1: 85, sex1: "X", ecstat1: 10) - expect(record.person_1_not_retired_over_soft_max_age?).to be false + expect(record).not_to be_person_1_not_retired_over_soft_max_age end end end