diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index e56a16783..8f28bff74 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -112,6 +112,15 @@ module Validations::HouseholdValidations end end + def validate_layear(record) + return unless record.layear && record.renewal + + if record.is_renewal? && record.layear == 1 + record.errors.add :layear, I18n.t("validations.household.renewal_just_moved_to_area.layear") + record.errors.add :renewal, I18n.t("validations.household.renewal_just_moved_to_area.renewal") + end + end + private def household_no_illness?(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 88f51874e..bcfe32f46 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -416,6 +416,9 @@ en: reasonpref: not_homeless: "Answer cannot be ‘no’ as the tenant was homeless or about to lose their home" previous_la_known: "Enter name of local authority" + renewal_just_moved_to_area: + layear: 'The household cannot have just moved to the local authority area if this letting is a renewal' + renewal: 'This letting cannot be a renewal if the household has just moved to the local authority area' gender: retired_male: "Answer cannot be ‘male’ as tenant is under 65 and retired" retired_female: "Answer cannot be ‘female’ as tenant is under 60 and retired" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index e1837a43d..a79db2541 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -566,6 +566,18 @@ RSpec.describe Validations::HouseholdValidations do .to include(match I18n.t("validations.household.previous_la_known")) end end + + context "when validating layear" do + it "household cannot have just moved to area if renewal" do + record.layear = 1 + record.renewal = 1 + household_validator.validate_layear(record) + expect(record.errors["layear"]) + .to include(match I18n.t("validations.household.renewal_just_moved_to_area.layear")) + expect(record.errors["renewal"]) + .to include(match I18n.t("validations.household.renewal_just_moved_to_area.renewal")) + end + end end describe "previous housing situation validations" do