From e3a3c2ebb0684b4bd95ff9b97ff567f37d4aae41 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Tue, 21 Jan 2025 16:40:30 +0000 Subject: [PATCH] CLDC-3820: Ensure la/prevloc/layear validation is triggered on fields which cause la to be inferred (#2884) --- .../validations/household_validations.rb | 15 +++++++++------ .../validations/lettings/household.en.yml | 9 +++++++++ .../validations/household_validations_spec.rb | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index b4fa934dc..63da6d628 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -202,12 +202,15 @@ module Validations::HouseholdValidations return unless record.layear && record.la && record.prevloc && record.collection_start_year if record.la == record.prevloc && record.layear == 1 - record.errors.add :layear, :renewal_just_moved, message: I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area") - record.errors.add :la, :renewal_just_moved, message: I18n.t("validations.lettings.household.la.same_la_just_moved_to_area") - record.errors.add :postcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area") - record.errors.add :uprn, :renewal_just_moved, message: I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area") - record.errors.add :ppostcode_full, :renewal_just_moved, message: I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area") - record.errors.add :prevloc, :renewal_just_moved, message: I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area") + record.errors.add :layear, I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area") + record.errors.add :la, I18n.t("validations.lettings.household.la.same_la_just_moved_to_area") + record.errors.add :postcode_full, I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area") + record.errors.add :uprn, I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area") + record.errors.add :uprn_selection, I18n.t("validations.lettings.household.uprn_selection.same_la_just_moved_to_area") + record.errors.add :ppostcode_full, I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area") + record.errors.add :prevloc, I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area") + record.errors.add :scheme_id, :skip_bu_error, message: I18n.t("validations.lettings.household.scheme.same_la_just_moved_to_area") + record.errors.add :location_id, :skip_bu_error, message: I18n.t("validations.lettings.household.location.same_la_just_moved_to_area") end end diff --git a/config/locales/validations/lettings/household.en.yml b/config/locales/validations/lettings/household.en.yml index 6c38b5d24..ed27bcca6 100644 --- a/config/locales/validations/lettings/household.en.yml +++ b/config/locales/validations/lettings/household.en.yml @@ -57,6 +57,15 @@ en: uprn: same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct" + uprn_selection: + same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct" + + scheme: + same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct" + + location: + same_la_just_moved_to_area: "You told us the tenant had just moved into the local authority, but this location is in the same local authority. Check your answers are correct" + age: child_under_16_relat: "Answer cannot be under 16 as person %{person_num}'s relationship to the lead tenant is ‘partner’." child_under_16_ecstat: "Answer cannot be under 16 as person %{person_num}’s working situation is not ‘child under 16’, ‘other’ or ‘prefers not to say’." diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 0893c89cf..a48b80d1a 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -668,17 +668,23 @@ RSpec.describe Validations::HouseholdValidations do record.startdate = Time.zone.now household_validator.validate_layear_and_prevloc(record) expect(record.errors["layear"]) - .to include(match I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.layear.same_la_just_moved_to_area")) expect(record.errors["prevloc"]) - .to include(match I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.prevloc.same_la_just_moved_to_area")) expect(record.errors["ppostcode_full"]) - .to include(match I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.ppostcode_full.same_la_just_moved_to_area")) expect(record.errors["la"]) - .to include(match I18n.t("validations.lettings.household.la.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.la.same_la_just_moved_to_area")) expect(record.errors["postcode_full"]) - .to include(match I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.postcode_full.same_la_just_moved_to_area")) expect(record.errors["uprn"]) - .to include(match I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area")) + .to include(I18n.t("validations.lettings.household.uprn.same_la_just_moved_to_area")) + expect(record.errors["uprn_selection"]) + .to include(I18n.t("validations.lettings.household.uprn_selection.same_la_just_moved_to_area")) + expect(record.errors["scheme_id"]) + .to include(I18n.t("validations.lettings.household.scheme.same_la_just_moved_to_area")) + expect(record.errors["location_id"]) + .to include(I18n.t("validations.lettings.household.location.same_la_just_moved_to_area")) end end end