From 0ef6a1194533440a1fbecc9c524cee10bed559e9 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 24 Mar 2022 15:43:13 +0000 Subject: [PATCH] Add missing ecstat validation --- app/models/validations/household_validations.rb | 3 +++ config/locales/en.yml | 2 ++ spec/models/validations/household_validations_spec.rb | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 830bc3549..658416982 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -136,6 +136,9 @@ private end if age < 16 && economic_status != 8 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) + if economic_status == 8 && age > 16 + record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:) + record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_16", person_num:) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 0e43522a7..8b5197030 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -152,11 +152,13 @@ en: age: retired_male: "Male tenant who is retired must be 65 or over" retired_female: "Female tenant who is retired must be 60 or over" + child_over_16: 'Answer cannot be over 16 as tenant %{person_num} has economic status "Child under 16"' lead: over_20: "Lead tenant must be under 20 as you told us that their housing situation immediately before this letting was a children's home or foster care" ecstat: retired_over_70: "Tenant %{person_num} must be retired if over 70" child_under_16: "Tenant %{person_num} economic status must be Child under 16 if their age is under 16" + child_over_16: 'Answer cannot be "Child under 16" as tenant %{person_num} is older than 16' student_16_19: "If age is between 16 and 19 - tenant %{person_num} must be a full time student or prefer not to say." relat: child_under_16: "Tenant %{person_num}’s relationship to tenant 1 must be Child if their age is under 16" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 9819c3d49..21a1ef58b 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -318,6 +318,15 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 8 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + it "validates that a person with economic status 'child' must be under 16" do + record.age2 = 21 + record.relat2 = 1 + record.ecstat2 = 8 + household_validator.validate_household_number_of_other_members(record) + expect(record.errors["ecstat2"]) + .to include(match I18n.t("validations.household.ecstat.child_over_16", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.child_over_16", person_num: 2)) end end