Browse Source

CLDC-867 Add previous bedrooms validations (#1219)

* Add previous property bedsit validations

* Add min and max for frombeds
pull/1215/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
1bf8373a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/form/sales/questions/previous_bedrooms.rb
  2. 9
      app/models/validations/sales/sale_information_validations.rb
  3. 5
      config/locales/en.yml
  4. 6
      spec/models/form/sales/questions/previous_bedrooms_spec.rb
  5. 22
      spec/models/validations/sales/sale_information_validations_spec.rb

3
app/models/form/sales/questions/previous_bedrooms.rb

@ -6,7 +6,8 @@ class Form::Sales::Questions::PreviousBedrooms < ::Form::Question
@header = "How many bedrooms did the property have?"
@type = "numeric"
@width = 5
@min = 0
@min = 1
@max = 6
@hint_text = "For bedsits enter 1"
end
end

9
app/models/validations/sales/sale_information_validations.rb

@ -14,4 +14,13 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :hodate, "Practical completion or handover date must be before exchange date"
end
end
def validate_previous_property_unit_type(record)
return unless record.fromprop && record.frombeds
if record.frombeds != 1 && record.fromprop == 2
record.errors.add :frombeds, I18n.t("validations.sale_information.previous_property_beds.property_type_bedsit")
record.errors.add :fromprop, I18n.t("validations.sale_information.previous_property_type.property_type_bedsit")
end
end
end

5
config/locales/en.yml

@ -408,6 +408,11 @@ en:
before_deactivation: "This location was deactivated on %{date}. The reactivation date must be on or after deactivation date"
deactivation:
during_deactivated_period: "The location is already deactivated during this date, please enter a different date"
sale_information:
previous_property_beds:
property_type_bedsit: "Bedsit bedroom maximum 1"
previous_property_type:
property_type_bedsit: "A bedsit can not have more than 1 bedroom"
soft_validations:
net_income:

6
spec/models/form/sales/questions/previous_bedrooms_spec.rb

@ -40,6 +40,10 @@ RSpec.describe Form::Sales::Questions::PreviousBedrooms, type: :model do
end
it "has correct min" do
expect(question.min).to eq(0)
expect(question.min).to eq(1)
end
it "has correct max" do
expect(question.max).to eq(6)
end
end

22
spec/models/validations/sales/sale_information_validations_spec.rb

@ -108,4 +108,26 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
end
describe "#validate_previous_property_unit_type" do
context "when number of bedrooms is <= 1" do
let(:record) { FactoryBot.build(:sales_log, frombeds: 1, fromprop: 2) }
it "does not add an error if it's a bedsit" do
sale_information_validator.validate_previous_property_unit_type(record)
expect(record.errors).to be_empty
end
end
context "when number of bedrooms is > 1" do
let(:record) { FactoryBot.build(:sales_log, frombeds: 2, fromprop: 2) }
it "does add an error if it's a bedsit" do
sale_information_validator.validate_previous_property_unit_type(record)
expect(record.errors["fromprop"]).to include(I18n.t("validations.sale_information.previous_property_type.property_type_bedsit"))
expect(record.errors["frombeds"]).to include(I18n.t("validations.sale_information.previous_property_beds.property_type_bedsit"))
end
end
end
end

Loading…
Cancel
Save