Browse Source

Add missing ecstat validation

pull/420/head
baarkerlounger 3 years ago
parent
commit
0ef6a11945
  1. 3
      app/models/validations/household_validations.rb
  2. 2
      config/locales/en.yml
  3. 9
      spec/models/validations/household_validations_spec.rb

3
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

2
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"

9
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

Loading…
Cancel
Save