Browse Source

Extract lettings household validation from shared validations

pull/2744/head
Manny Dinssa 8 months ago
parent
commit
fb164e3e30
  1. 2
      app/models/validations/shared_validations.rb
  2. 1
      config/locales/en.yml
  3. 7
      config/locales/validations/lettings/household.en.yml
  4. 14
      spec/models/validations/household_validations_spec.rb

2
app/models/validations/shared_validations.rb

@ -134,7 +134,7 @@ module Validations::SharedValidations
if record.sales?
record.errors.add "relat#{n}", I18n.t("validations.sales.household.relat.one_partner")
else
record.errors.add "relat#{n}", I18n.t("validations.household.relat.one_partner")
record.errors.add "relat#{n}", I18n.t("validations.lettings.household.relat.one_partner")
end
end
end

1
config/locales/en.yml

@ -521,7 +521,6 @@ en:
cannot_be_student: "Person cannot be a student if they are aged 16-19 but are not a child."
relat:
child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16."
one_partner: "Number of partners cannot be greater than 1."
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:
cannot_be_child:

7
config/locales/validations/lettings/household.en.yml

@ -0,0 +1,7 @@
en:
validations:
lettings:
household:
relat:
one_partner: "Number of partners cannot be greater than 1."

14
spec/models/validations/household_validations_spec.rb

@ -27,13 +27,13 @@ RSpec.describe Validations::HouseholdValidations do
end
describe "reason for leaving last settled home validations" do
let(:field) { "validations.other_field_not_required" }
let(:field) { "validations.shared.other_field_not_required" }
let(:main_field_label) { "reason" }
let(:other_field_label) { "reasonother" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when reason is other" do
let(:field) { "validations.other_field_missing" }
let(:field) { "validations.shared.other_field_missing" }
it "validates that a reason is provided" do
record.reason = 20
@ -251,14 +251,14 @@ RSpec.describe Validations::HouseholdValidations do
record.hhmemb = 0
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.numeric.within_range", field: "Number of household members", min: 1, max: 8))
.to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8))
end
it "validates that the number of household members cannot be more than 8" do
record.hhmemb = 9
household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"])
.to include(match I18n.t("validations.numeric.within_range", field: "Number of household members", min: 1, max: 8))
.to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8))
end
it "expects that the number of other household members is between the min and max" do
@ -276,11 +276,11 @@ RSpec.describe Validations::HouseholdValidations do
record.relat3 = "P"
household_validator.validate_partner_count(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.one_partner"))
.to include(match I18n.t("validations.lettings.household.relat.one_partner"))
expect(record.errors["relat3"])
.to include(match I18n.t("validations.household.relat.one_partner"))
.to include(match I18n.t("validations.lettings.household.relat.one_partner"))
expect(record.errors["relat4"])
.not_to include(match I18n.t("validations.household.relat.one_partner"))
.not_to include(match I18n.t("validations.lettings.household.relat.one_partner"))
end
it "expects that a tenant can have a partner" do

Loading…
Cancel
Save