Browse Source

feat: rename i18n vars, add validations everywhere

pull/1178/head
natdeanlewissoftwire 3 years ago
parent
commit
8156289178
  1. 6
      app/models/validations/household_validations.rb
  2. 8
      app/models/validations/sales/household_validations.rb
  3. 15
      config/locales/en.yml
  4. 6
      spec/models/validations/household_validations_spec.rb
  5. 2
      spec/models/validations/sales/household_validations_spec.rb

6
app/models/validations/household_validations.rb

@ -177,9 +177,9 @@ private
return unless age && economic_status && relationship
if age >= 16 && age <= 19 && tenant_is_child?(relationship) && (!tenant_is_fulltime_student?(economic_status) && !tenant_economic_status_refused?(economic_status))
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:)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.not_student_16_19", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.not_student_16_19", person_num:)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.not_student_16_19", person_num:)
end
end

8
app/models/validations/sales/household_validations.rb

@ -25,8 +25,10 @@ private
return unless age && relationship
if age < 16 && person_is_partner?(relationship)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.partner_under_16")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.partner_under_16")
elsif age >= 20 && person_is_child?(relationship)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_20")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.child_over_20")
end
end
@ -37,8 +39,10 @@ private
relationship = record.public_send("relat#{person_num}")
return unless age && economic_status && relationship
if age >= 16 && age <= 19 && !person_is_child?(relationship) && person_is_fulltime_student?(economic_status)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19_sales")
if age >= 16 && age <= 19 && person_is_fulltime_student?(economic_status) && !person_is_child?(relationship)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19")
end
end

15
config/locales/en.yml

@ -297,7 +297,9 @@ en:
child_under_16_relat: "Answer cannot be under 16 as person %{person_num} is not a child of the lead tenant"
child_under_16: "Answer cannot be under 16 as person’s %{person_num} working situation is not ‘child under 16’"
child_over_16: "Answer cannot be over 16 as person’s %{person_num} working situation is ‘child under 16‘"
student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student"
child_over_20: "Answer cannot be 20 or over as the relationship is ‘child’"
not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student"
student_16_19: "Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’"
partner_under_16: "Cannot be under 16 if the relationship is partner"
lead:
over_20: "The lead tenant must be under 20 as you told us their housing situation immediately before this letting was a children’s home or foster care"
@ -305,16 +307,17 @@ en:
retired_over_70: "Person %{person_num} must be retired if over 70"
child_under_16: "Person’s %{person_num} working situation must be ’child under 16‘ as you told us they’re under 16"
child_over_16: "Answer cannot be ‘child under 16’ as you told us the person %{person_num} is older than 16"
student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19."
not_student_16_19: "Person’s %{person_num} working situation must be full-time student or prefers not to say as you told us they’re between 16 and 19."
student_16_19: "Person cannot be a student if they are aged 16-19 and but don't have relationship ‘child’"
retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65"
retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60"
relat:
partner_under_16: "Cannot be partner if the person's age is under 16"
partner_under_16: "Answer cannot be ‘partner’ if the person's age is under 16"
child_under_16: "Person’s relationship to tenant 1 must be ‘child’ as you told us they’re under 16"
child_over_20: "Relationship cannot be ‘child’ if the person's age is 20 or over"
child_over_20: "Answer cannot be ‘child’ if the person's age is 20 or over"
one_partner: "Number of partners cannot be greater than 1"
student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student"
student_16_19_sales: "Person must be a child if they are aged 16-19 and a student"
not_student_16_19: "Answer cannot be ‘child’ as you told us the person %{person_num} is between 16 and 19 and is not a full-time student"
student_16_19: "Answer must be ‘child’ if the person is aged 16-19 and a student"
housingneeds_a:
one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’"
prevten:

6
spec/models/validations/household_validations_spec.rb

@ -398,11 +398,11 @@ RSpec.describe Validations::HouseholdValidations do
record.ecstat2 = 1
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))
.to include(match I18n.t("validations.household.ecstat.not_student_16_19", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.student_16_19", person_num: 2))
.to include(match I18n.t("validations.household.age.not_student_16_19", person_num: 2))
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.student_16_19", person_num: 2))
.to include(match I18n.t("validations.household.relat.not_student_16_19", person_num: 2))
end
it "expects that person can be a full time student" do

2
spec/models/validations/sales/household_validations_spec.rb

@ -90,7 +90,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.student_16_19_sales"))
.to include(match I18n.t("validations.household.relat.student_16_19"))
end
end
end

Loading…
Cancel
Save