Browse Source

Add previous property bedsit validations

pull/1219/head
Kat 3 years ago
parent
commit
3051862f01
  1. 9
      app/models/validations/sales/sale_information_validations.rb
  2. 5
      config/locales/en.yml
  3. 22
      spec/models/validations/sales/sale_information_validations_spec.rb

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" record.errors.add :hodate, "Practical completion or handover date must be before exchange date"
end end
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 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" before_deactivation: "This location was deactivated on %{date}. The reactivation date must be on or after deactivation date"
deactivation: deactivation:
during_deactivated_period: "The location is already deactivated during this date, please enter a different date" 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: soft_validations:
net_income: net_income:

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

@ -108,4 +108,26 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end 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 end

Loading…
Cancel
Save