Browse Source

feat: add voiddate/mrcdate validation to mrcdate too

pull/1440/head
natdeanlewissoftwire 3 years ago
parent
commit
2930e44a93
  1. 1
      app/models/validations/date_validations.rb
  2. 1
      config/locales/en.yml
  3. 4
      spec/models/validations/date_validations_spec.rb

1
app/models/validations/date_validations.rb

@ -27,6 +27,7 @@ module Validations::DateValidations
if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
record.errors.add :voiddate, I18n.t("validations.property.void_date.after_mrcdate")
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_void_date")
end
end

1
config/locales/en.yml

@ -200,6 +200,7 @@ en:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date"
not_first_let: "Major repairs date must not be completed if the tenancy is a first let"
ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date"
before_void_date: "Major repairs date must be after the void date if provided"
void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date"
before_tenancy_start: "Enter a void date that is before the tenancy start date"

4
spec/models/validations/date_validations_spec.rb

@ -311,12 +311,14 @@ RSpec.describe Validations::DateValidations do
end
context "when major repairs have been carried out" do
it "cannot be after major repairs date" do
it "void_date cannot be after major repairs date" do
record.mrcdate = Time.zone.local(2022, 1, 1)
record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.after_mrcdate"))
expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.before_void_date"))
end
it "must be before major repairs date" do

Loading…
Cancel
Save