Browse Source

add validation for condition_effects

pull/387/head
Dushan Despotovic 3 years ago
parent
commit
8bdb6e569e
  1. 7
      app/models/validations/household_validations.rb
  2. 2
      config/locales/en.yml
  3. 82
      spec/models/validations/household_validations_spec.rb

7
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 && record.illness != 0
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")

2
config/locales/en.yml

@ -145,6 +145,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:

82
spec/models/validations/household_validations_spec.rb

@ -482,6 +482,88 @@ 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
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