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? if record.sales?
record.errors.add "relat#{n}", I18n.t("validations.sales.household.relat.one_partner") record.errors.add "relat#{n}", I18n.t("validations.sales.household.relat.one_partner")
else 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 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." cannot_be_student: "Person cannot be a student if they are aged 16-19 but are not a child."
relat: relat:
child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16." 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." 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: student_16_19:
cannot_be_child: 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 end
describe "reason for leaving last settled home validations" do 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(:main_field_label) { "reason" }
let(:other_field_label) { "reasonother" } let(:other_field_label) { "reasonother" }
let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) } let(:expected_error) { I18n.t(field, main_field_label:, other_field_label:) }
context "when reason is other" do 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 it "validates that a reason is provided" do
record.reason = 20 record.reason = 20
@ -251,14 +251,14 @@ RSpec.describe Validations::HouseholdValidations do
record.hhmemb = 0 record.hhmemb = 0
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]) 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 end
it "validates that the number of household members cannot be more than 8" do it "validates that the number of household members cannot be more than 8" do
record.hhmemb = 9 record.hhmemb = 9
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]) 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 end
it "expects that the number of other household members is between the min and max" do 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" record.relat3 = "P"
household_validator.validate_partner_count(record) household_validator.validate_partner_count(record)
expect(record.errors["relat2"]) 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"]) 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"]) 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 end
it "expects that a tenant can have a partner" do it "expects that a tenant can have a partner" do

Loading…
Cancel
Save