Browse Source

feat: merge with main, improve date behaviour

pull/1232/head
natdeanlewissoftwire 3 years ago
parent
commit
9d6d904bba
  1. 12
      app/models/validations/sales/sale_information_validations.rb
  2. 14
      config/locales/en.yml
  3. 8
      spec/models/validations/sales/sale_information_validations_spec.rb

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

@ -10,11 +10,15 @@ module Validations::Sales::SaleInformationValidations
def validate_exchange_date(record)
return unless record.exdate && record.saledate
record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_before_saledate")) if record.exdate > record.saledate
return if (record.saledate.to_date - record.exdate.to_date).to_i / 365 < 1
if record.exdate > record.saledate
record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_before_saledate"))
record.errors.add(:saledate, I18n.t("validations.sale_information.saledate.must_be_after_exdate"))
end
record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate"))
if record.saledate.to_date - record.exdate.to_date > 1.year.in_days
record.errors.add(:exdate, I18n.t("validations.sale_information.exdate.must_be_less_than_1_year_from_saledate"))
record.errors.add(:saledate, I18n.t("validations.sale_information.saledate.must_be_less_than_1_year_from_exdate"))
end
end
def validate_previous_property_unit_type(record)

14
config/locales/en.yml

@ -416,19 +416,15 @@ en:
during_deactivated_period: "The location is already deactivated during this date, please enter a different date"
sale_information:
exdate:
must_be_before_saledate:
Contract exchange date must be less than 1 year before completion date
must_be_less_than_1_year_from_saledate:
Contract exchange date must be less than 1 year before completion date
must_be_before_saledate: "Contract exchange date must be less than 1 year before completion date"
must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before completion date"
saledate:
must_be_after_exdate: "Completion date must be less than 1 year after contract exchange date"
must_be_less_than_1_year_from_exdate: "Completion date must be less than 1 year after contract exchange date"
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"
completion_exchange:
exchange_before_completion: "Exchange date must be before completion date"
completion_after_exchange: "Completion date must be after exchange date"
exchange_after_one_year_before_completion: "Exchange date must be less than 1 year before completion date"
completion_before_one_year_after_exchange: "Completion date must be less than 1 year after exchange date"
soft_validations:
net_income:
title_text: "Net income is outside the expected range based on the lead tenant’s working situation"

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

@ -111,12 +111,15 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
context "when exdate more than 1 year before saledate" do
let(:record) { build(:sales_log, exdate: 2.years.ago, saledate: 1.month.ago) }
it "does not add the error" do
it "adds error" do
sale_information_validator.validate_exchange_date(record)
expect(record.errors[:exdate]).to eq(
["Contract exchange date must be less than 1 year before completion date"],
)
expect(record.errors[:saledate]).to eq(
["Completion date must be less than 1 year after contract exchange date"],
)
end
end
@ -129,6 +132,9 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors[:exdate]).to eq(
["Contract exchange date must be less than 1 year before completion date"],
)
expect(record.errors[:saledate]).to eq(
["Completion date must be less than 1 year after contract exchange date"],
)
end
end

Loading…
Cancel
Save