diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 8f28bff74..47d094be8 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -121,6 +121,14 @@ module Validations::HouseholdValidations end end + def validate_combination_of_housing_needs_responses(record) + if record.housingneeds == 1 && record.housingneeds_type == 3 && record.housingneeds_other&.zero? + record.errors.add :housingneeds, I18n.t("validations.household.housingneeds.invalid") + record.errors.add :housingneeds_type, I18n.t("validations.household.housingneeds.invalid") + record.errors.add :housingneeds_other, I18n.t("validations.household.housingneeds.invalid") + end + end + private def household_no_illness?(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 68e1d72fc..e223c7fc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -389,6 +389,8 @@ en: housingneeds_type: only_one_option_permitted: "Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected" housingneeds: + invalid: + If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs no_disabled_needs_conjunction: "No disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" dont_know_disabled_needs_conjunction: "Don’t know disabled access needs can’t be selected if you have selected fully wheelchair-accessible housing, wheelchair access to essential rooms, level access housing or other disabled access needs" no_and_dont_know_disabled_needs_conjunction: "No disabled access needs and don’t know disabled access needs cannot be selected together" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index a79db2541..b1c01b7a5 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -637,4 +637,20 @@ RSpec.describe Validations::HouseholdValidations do end end end + + describe "housing needs validations" do + it "is invalid when a combination of housingneeds == 1 (yes) && housingneeds_type == 3 (none of listed) && housingneeds_other == 0 (no)" do + record.housingneeds = 1 + record.housingneeds_type = 3 + record.housingneeds_other = 0 + + household_validator.validate_combination_of_housing_needs_responses(record) + + error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"] + + expect(record.errors["housingneeds"]).to eq(error_message) + expect(record.errors["housingneeds_type"]).to eq(error_message) + expect(record.errors["housingneeds_other"]).to eq(error_message) + end + end end