Browse Source

CLDC-4269: update depends_on for person_known and update tests

pull/3332/head
Nat Dean-Lewis 2 weeks ago
parent
commit
be85adde90
  1. 5
      app/models/form/lettings/pages/person_known.rb
  2. 12
      spec/models/validations/household_validations_spec.rb

5
app/models/form/lettings/pages/person_known.rb

@ -2,7 +2,10 @@ class Form::Lettings::Pages::PersonKnown < ::Form::Page
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "person_#{person_index}_known" @id = "person_#{person_index}_known"
@depends_on = (person_index..8).map { |index| { "hhmemb" => index } } @depends_on = [{ "hhmemb" => {
"operator" => ">=",
"operand" => @person_index,
} }]
@person_index = person_index @person_index = person_index
end end

12
spec/models/validations/household_validations_spec.rb

@ -252,18 +252,18 @@ 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.shared.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: 15))
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 15" do
record.hhmemb = 9 record.hhmemb = 16
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.shared.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: 15))
end end
it "expects that the number of other household members is between the min and max" do it "expects that the number of household members is between the min and max" do
record.hhmemb = 5 record.hhmemb = 11
household_validator.validate_numeric_min_max(record) household_validator.validate_numeric_min_max(record)
expect(record.errors["hhmemb"]).to be_empty expect(record.errors["hhmemb"]).to be_empty
end end

Loading…
Cancel
Save