Browse Source

Add max beds validation (#337)

pull/340/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
8ac58aed3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/property_validations.rb
  2. 1
      config/locales/en.yml
  3. 8
      spec/models/validations/property_validations_spec.rb

4
app/models/validations/property_validations.rb

@ -118,5 +118,9 @@ module Validations::PropertyValidations
record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared")
end end
end end
if record.beds.present? && record.beds > 12
record.errors.add :beds, I18n.t("validations.property.beds.over_max")
end
end end
end end

1
config/locales/en.yml

@ -68,6 +68,7 @@ en:
one_three_bedroom_single_tenant_shared: "A shared house with less than two tenants must have 1 to 3 bedrooms" one_three_bedroom_single_tenant_shared: "A shared house with less than two tenants must have 1 to 3 bedrooms"
beds: beds:
negative: "Number of bedrooms has to be greater than 0" negative: "Number of bedrooms has to be greater than 0"
over_max: "Number of bedrooms cannot be more than 12"
financial: financial:
tshortfall: tshortfall:

8
spec/models/validations/property_validations_spec.rb

@ -137,6 +137,14 @@ RSpec.describe Validations::PropertyValidations do
expect(record.errors["beds"]).to include(I18n.t("validations.property.beds.negative")) expect(record.errors["beds"]).to include(I18n.t("validations.property.beds.negative"))
end end
end end
context "when a room number higher than 12 has been entered" do
it "adds an error" do
record.beds = 13
property_validator.validate_shared_housing_rooms(record)
expect(record.errors["beds"]).to include(I18n.t("validations.property.beds.over_max"))
end
end
end end
describe "#validate_la" do describe "#validate_la" do

Loading…
Cancel
Save