From 258626d5a98ca28cbb14e3e0cc9bd4a2aa26e62e Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 7 Apr 2022 11:44:37 +0100 Subject: [PATCH] Add local housing authority referral validation (#456) * Add local housing authority referral validation * Update validation message --- app/models/case_log.rb | 8 ++++++++ .../validations/household_validations.rb | 4 ++++ config/locales/en.yml | 2 ++ .../validations/household_validations_spec.rb | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index ef9f5a91a..6b602362f 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -274,6 +274,14 @@ class CaseLog < ApplicationRecord landlord == 1 end + def other_landlord? + landlord == 2 + end + + def local_housing_referral? + referral == 3 + end + def is_prevten_la_general_needs? [30, 31].any?(prevten) end diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index cd8bc912b..a980e94be 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -109,6 +109,10 @@ module Validations::HouseholdValidations record.errors.add :referral, I18n.t("validations.household.referral.la_general_needs.internal_transfer") record.errors.add :prevten, I18n.t("validations.household.prevten.la_general_needs.internal_transfer") end + + if record.other_landlord? && record.local_housing_referral? + record.errors.add :referral, I18n.t("validations.household.referral.prp.local_housing_referral") + end end def validate_prevloc(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 91cdfa7e2..afd547079 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -191,6 +191,8 @@ en: reason_permanently_decanted: "Answer must be internal transfer as you already told us the tenant was permanently decanted from another property owned by this landlord" la_general_needs: internal_transfer: "Answer cannot be internal transfer as you already told us it's the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting" + prp: + local_housing_referral: "Answer cannot be 'nominated by a local housing authority' as you already told us it's another landlord on the tenancy agreement" homeless: assessed: internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 9d1a00282..36edd3f12 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -215,6 +215,24 @@ RSpec.describe Validations::HouseholdValidations do .to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer"))) end end + + context "when referral is nominated by a local housing authority" do + it "cannot have `other landlord`" do + record.landlord = 2 + record.referral = 3 + household_validator.validate_referral(record) + expect(record.errors["referral"]) + .to include(match(I18n.t("validations.household.referral.prp.local_housing_referral"))) + end + + it "can have `this landlord`" do + record.referral = 3 + record.landlord = 1 + household_validator.validate_referral(record) + expect(record.errors["referral"]) + .to be_empty + end + end end describe "armed forces validations" do