Browse Source

CLDC-1856 Add housing question flow validation (#1508)

* CLDC-1856 Add housing question flow validation

* Update copy and methods
pull/1528/head
Jack 2 years ago committed by GitHub
parent
commit
8e8362a74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/validations/household_validations.rb
  2. 2
      config/locales/en.yml
  3. 16
      spec/models/validations/household_validations_spec.rb

8
app/models/validations/household_validations.rb

@ -121,6 +121,14 @@ module Validations::HouseholdValidations
end end
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 private
def household_no_illness?(record) def household_no_illness?(record)

2
config/locales/en.yml

@ -389,6 +389,8 @@ en:
housingneeds_type: 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" 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: 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" 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" 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" no_and_dont_know_disabled_needs_conjunction: "No disabled access needs and don’t know disabled access needs cannot be selected together"

16
spec/models/validations/household_validations_spec.rb

@ -637,4 +637,20 @@ RSpec.describe Validations::HouseholdValidations do
end end
end 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 end

Loading…
Cancel
Save