Browse Source

CLDC-815-long-term-vision-validation (#387)

* add validation for condition_effects

* fixes

* review changes

* lint fixes

* update wrapper method
pull/390/head
Dushan 3 years ago committed by GitHub
parent
commit
e56830cb9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/validations/household_validations.rb
  2. 2
      config/locales/en.yml
  3. 2
      spec/factories/case_log.rb
  4. 2
      spec/fixtures/complete_case_log.json
  5. 2
      spec/fixtures/exports/case_logs.xml
  6. 91
      spec/models/validations/household_validations_spec.rb

11
app/models/validations/household_validations.rb

@ -65,6 +65,13 @@ module Validations::HouseholdValidations
end end
end end
def validate_condition_effects(record)
all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10]
if all_options.count(1) >= 1 && household_no_illness?(record)
record.errors.add :condition_effects, I18n.t("validations.household.condition_effects.no_choices")
end
end
def validate_previous_housing_situation(record) def validate_previous_housing_situation(record)
if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary? if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary?
record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation") record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation")
@ -107,6 +114,10 @@ module Validations::HouseholdValidations
private private
def household_no_illness?(record)
record.illness != 0
end
def women_of_child_bearing_age_in_household(record) def women_of_child_bearing_age_in_household(record)
(1..8).any? do |n| (1..8).any? do |n|
next if record["sex#{n}"].nil? || record["age#{n}"].nil? next if record["sex#{n}"].nil? || record["age#{n}"].nil?

2
config/locales/en.yml

@ -146,6 +146,8 @@ en:
male_refuge: "Answer cannot be male as you told us their housing situation immediately before this letting was a refuge" male_refuge: "Answer cannot be male as you told us their housing situation immediately before this letting was a refuge"
reason: reason:
not_internal_transfer: "Answer cannot be permanently decanted from another property owned by this landlord as you told us the source of referral for this tenancy was not an internal transfer" not_internal_transfer: "Answer cannot be permanently decanted from another property owned by this landlord as you told us the source of referral for this tenancy was not an internal transfer"
condition_effects:
no_choices: "You can not provide details about effects of conditions on any of the household members if you have not answered yes to the any of the household having a physical or mental health condition (or other illness) expected to last 12 months or more"
tenancy: tenancy:
length: length:

2
spec/factories/case_log.rb

@ -51,7 +51,7 @@ FactoryBot.define do
underoccupation_benefitcap { 0 } underoccupation_benefitcap { 0 }
leftreg { 1 } leftreg { 1 }
reservist { 0 } reservist { 0 }
illness { 1 } illness { 0 }
preg_occ { 1 } preg_occ { 1 }
tenancy_code { "BZ757" } tenancy_code { "BZ757" }
startertenancy { 0 } startertenancy { 0 }

2
spec/fixtures/complete_case_log.json vendored

@ -44,7 +44,7 @@
"underoccupation_benefitcap": 0, "underoccupation_benefitcap": 0,
"leftreg": 1, "leftreg": 1,
"reservist": 0, "reservist": 0,
"illness": 1, "illness": 0,
"preg_occ": 0, "preg_occ": 0,
"tenancy_code": "BZ757", "tenancy_code": "BZ757",
"startdate": "12/12/2021", "startdate": "12/12/2021",

2
spec/fixtures/exports/case_logs.xml vendored

@ -38,7 +38,7 @@
<underoccupation_benefitcap>0</underoccupation_benefitcap> <underoccupation_benefitcap>0</underoccupation_benefitcap>
<leftreg>1</leftreg> <leftreg>1</leftreg>
<reservist>0</reservist> <reservist>0</reservist>
<illness>1</illness> <illness>0</illness>
<preg_occ>1</preg_occ> <preg_occ>1</preg_occ>
<tenancy_code>BZ757</tenancy_code> <tenancy_code>BZ757</tenancy_code>
<startertenancy>0</startertenancy> <startertenancy>0</startertenancy>

91
spec/models/validations/household_validations_spec.rb

@ -482,6 +482,97 @@ RSpec.describe Validations::HouseholdValidations do
end end
end end
describe "condition effects validation" do
it "validates vision can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_1 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates hearing can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_2 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates mobility can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_3 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates dexterity can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_4 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates learning or understanding or concentrating can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_5 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates memory can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_6 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates mental health can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_7 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates stamina or breathing or fatigue can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_8 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates socially or behaviourally can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_9 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "validates other can't be selected if answer to anyone in household with health condition is not yes" do
record.illness = 1
record.illness_type_10 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"])
.to include(match I18n.t("validations.household.condition_effects.no_choices"))
end
it "expects that an illness can be selected if answer to anyone in household with health condition is yes " do
record.illness = 0
record.illness_type_1 = 1
record.illness_type_2 = 1
record.illness_type_3 = 1
household_validator.validate_condition_effects(record)
expect(record.errors["condition_effects"]).to be_empty
end
end
describe "accessibility requirement validations" do describe "accessibility requirement validations" do
it "validates that mutually exclusive options can't be selected together" do it "validates that mutually exclusive options can't be selected together" do
record.housingneeds_a = 1 record.housingneeds_a = 1

Loading…
Cancel
Save