diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 658416982..c455575c0 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -133,9 +133,12 @@ private if age > 70 && economic_status != 4 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:) + record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:) end if age < 16 && economic_status != 8 record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) + record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) + end 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:) @@ -149,6 +152,7 @@ private if age < 16 && relationship != 1 record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_under_16", person_num:) + record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16_relat", person_num:) end end @@ -160,6 +164,8 @@ private if age >= 16 && age <= 19 && relationship == 1 && (economic_status != 6 && economic_status != 10) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19", person_num:) + record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19", person_num:) + record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19", person_num:) end end @@ -171,9 +177,13 @@ private if gender == "M" && economic_status == 4 && age < 65 record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male") + record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male") + record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male") end if gender == "F" && economic_status == 4 && age < 60 record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female") + record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female") + record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 8b5197030..3c213a1f1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -152,7 +152,11 @@ 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" + retired_over_70: 'Answer cannot be over 70 as as tenant %{person_num} has economic status that is not "Retired"' + child_under_16_relat: 'Answer cannot be under 16 as tenant %{person_num} is not a child of the lead tenant' + child_under_16: 'Answer cannot be under 16 as tenant %{person_num} has economic status that is not "Child under 16"' child_over_16: 'Answer cannot be over 16 as tenant %{person_num} has economic status "Child under 16"' + student_16_19: 'Answer cannot be between 16 and 19 as tenant %{person_num} is a child of the lead tenant but is not a full time student' 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: @@ -160,9 +164,12 @@ en: 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." + retired_male: "Male tenant who is under 65 cannot be retired" + retired_female: "Female tenant who is under 60 cannot be retired" relat: child_under_16: "Tenant %{person_num}’s relationship to tenant 1 must be Child if their age is under 16" one_partner: "Number of partners cannot be greater than 1" + student_16_19: 'Answer cannot be "Child" as tenant %{person_num} is between 16 and 19 but is not a full time student' housingneeds_a: one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities" prevten: @@ -187,6 +194,8 @@ en: not_homeless: "Answer cannot be ‘no’ as you already told us the tenant was homeless or about to lose their home" previous_la_known: "Enter a local authority" gender: + retired_male: 'Answer cannot be "Male" as tenant is under 65 and retired' + retired_female: 'Answer cannot be "Female" as tenant is under 60 and retired' male_refuge: "Answer cannot be male as you told us their housing situation immediately before this letting was a refuge" 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" diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 21a1ef58b..b3af9b399 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -296,6 +296,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["relat2"]) .to include(match I18n.t("validations.household.relat.child_under_16", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.child_under_16_relat", person_num: 2)) end it "expects that person is a child of the tenant" do @@ -303,6 +305,7 @@ RSpec.describe Validations::HouseholdValidations do record.relat2 = 1 household_validator.validate_household_number_of_other_members(record) expect(record.errors["relat2"]).to be_empty + expect(record.errors["age2"]).to be_empty end it "validates that person's economic status must be Child" do @@ -311,6 +314,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]) .to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.child_under_16", person_num: 2)) end it "expects that person's economic status is Child" do @@ -318,6 +323,9 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 8 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty + end + it "validates that a person with economic status 'child' must be under 16" do record.age2 = 21 record.relat2 = 1 @@ -338,6 +346,10 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]) .to include(match I18n.t("validations.household.ecstat.student_16_19", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.student_16_19", person_num: 2)) + expect(record.errors["relat2"]) + .to include(match I18n.t("validations.household.relat.student_16_19", person_num: 2)) end it "expects that person can be a full time student" do @@ -346,6 +358,8 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 6 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty + expect(record.errors["relat2"]).to be_empty end it "expects that person can refuse to share their work status" do @@ -354,6 +368,8 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 10 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty + expect(record.errors["relat2"]).to be_empty end end @@ -364,6 +380,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]) .to include(match I18n.t("validations.household.ecstat.retired_over_70", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.household.age.retired_over_70", person_num: 2)) end it "expects that person is retired" do @@ -371,6 +389,7 @@ RSpec.describe Validations::HouseholdValidations do record.ecstat2 = 1 household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty end end @@ -382,6 +401,10 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["age2"]) .to include(match I18n.t("validations.household.age.retired_male")) + expect(record.errors["sex2"]) + .to include(match I18n.t("validations.household.gender.retired_male")) + expect(record.errors["ecstat2"]) + .to include(match I18n.t("validations.household.ecstat.retired_male")) end it "expects that person is over 65" do @@ -391,6 +414,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["sex2"]).to be_empty + expect(record.errors["age2"]).to be_empty end it "validates that the number of other household members cannot be less than 0" do @@ -422,6 +447,10 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) expect(record.errors["age2"]) .to include(match I18n.t("validations.household.age.retired_female")) + expect(record.errors["sex2"]) + .to include(match I18n.t("validations.household.gender.retired_female")) + expect(record.errors["ecstat2"]) + .to include(match I18n.t("validations.household.ecstat.retired_female")) end it "expects that person is over 60" do @@ -431,6 +460,8 @@ RSpec.describe Validations::HouseholdValidations do household_validator.validate_household_number_of_other_members(record) household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["sex2"]).to be_empty + expect(record.errors["age2"]).to be_empty end end end