Browse Source

Change property major repairs date validation from 2 years to 10

pull/820/head
Kat 3 years ago
parent
commit
2369fe8898
  1. 2
      app/models/validations/date_validations.rb
  2. 8
      spec/models/validations/date_validations_spec.rb

2
app/models/validations/date_validations.rb

@ -9,7 +9,7 @@ module Validations::DateValidations
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.not_first_let") record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.not_first_let")
end end
if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 730 if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.730_days_before_tenancy_start") record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.730_days_before_tenancy_start")
end end
end end

8
spec/models/validations/date_validations_spec.rb

@ -85,17 +85,17 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["mrcdate"]).to be_empty expect(record.errors["mrcdate"]).to be_empty
end end
it "cannot be more than 2 years before the tenancy start date" do it "cannot be more than 10 years before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2020, 1, 1) record.mrcdate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.730_days_before_tenancy_start")) .to include(match I18n.t("validations.property.mrcdate.730_days_before_tenancy_start"))
end end
it "must be within 2 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2020, 3, 1) record.mrcdate = Time.zone.local(2012, 3, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]).to be_empty expect(record.errors["mrcdate"]).to be_empty
end end

Loading…
Cancel
Save