diff --git a/app/models/form/sales/questions/number_of_others_in_property.rb b/app/models/form/sales/questions/number_of_others_in_property.rb index 3eb1f34e6..cf590291b 100644 --- a/app/models/form/sales/questions/number_of_others_in_property.rb +++ b/app/models/form/sales/questions/number_of_others_in_property.rb @@ -7,5 +7,7 @@ class Form::Sales::Questions::NumberOfOthersInProperty < ::Form::Question @type = "numeric" @hint_text = "You can provide details for a maximum of 4 other people." @width = 2 + @min = 0 + @max = 4 end end diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index ef241301c..c7af23299 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -1,14 +1,6 @@ module Validations::Sales::HouseholdValidations include Validations::SharedValidations - def validate_number_of_other_people_living_in_the_property(record) - return if record.hholdcount.blank? - - unless record.hholdcount >= 0 && record.hholdcount <= 4 - record.errors.add :hholdcount, I18n.t("validations.numeric.within_range", field: "Number of other people living in the property", min: 0, max: 4) - end - end - def validate_household_number_of_other_members(record) (2..6).each do |n| validate_person_age_matches_relationship(record, n) diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index cdb0ac001..8452b9a52 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -114,8 +114,6 @@ private record.errors.add question.id.to_sym, I18n.t("validations.numeric.within_range", field:, min:, max:) elsif min record.errors.add question.id.to_sym, I18n.t("validations.numeric.above_min", field:, min:) - else - record.errors.add question.id.to_sym, I18n.t("validations.numeric.below_max", field:, max:) end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 5dd6202b6..c78363352 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -133,7 +133,6 @@ en: numeric: within_range: "%{field} must be between %{min} and %{max}" above_min: "%{field} must be at least %{min}" - below_max: "%{field} must be at most %{max}" date: invalid_date: "Enter a date in the correct format, for example 31 1 2022" outside_collection_window: "Enter a date within the current collection windows" diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index 5b227c36d..46ea1dc31 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -5,48 +5,6 @@ RSpec.describe Validations::Sales::HouseholdValidations do let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } } - describe "#validate_number_of_other_people_living_in_the_property" do - context "when within permitted bounds" do - let(:record) { build(:sales_log, hholdcount: 2) } - - it "does not add an error" do - household_validator.validate_number_of_other_people_living_in_the_property(record) - - expect(record.errors[:hholdcount]).not_to be_present - end - end - - context "when blank" do - let(:record) { build(:sales_log, hholdcount: nil) } - - it "does not add an error" do - household_validator.validate_number_of_other_people_living_in_the_property(record) - - expect(record.errors[:hholdcount]).not_to be_present - end - end - - context "when below lower bound" do - let(:record) { build(:sales_log, hholdcount: -1) } - - it "adds an error" do - household_validator.validate_number_of_other_people_living_in_the_property(record) - - expect(record.errors[:hholdcount]).to be_present - end - end - - context "when higher than upper bound" do - let(:record) { build(:sales_log, hholdcount: 5) } - - it "adds an error" do - household_validator.validate_number_of_other_people_living_in_the_property(record) - - expect(record.errors[:hholdcount]).to be_present - end - end - end - describe "household member validations" do let(:record) { build(:sales_log) }