Browse Source

feat: add ten year validations to startdate too

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

8
app/models/validations/date_validations.rb

@ -46,6 +46,14 @@ module Validations::DateValidations
record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date") record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date")
end end
if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_void_date")
end
if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_mrc_date")
end
location_during_startdate_validation(record, :startdate) location_during_startdate_validation(record, :startdate)
scheme_during_startdate_validation(record, :startdate) scheme_during_startdate_validation(record, :startdate)
end end

3
config/locales/en.yml

@ -173,6 +173,9 @@ en:
after_void_date: "Enter a tenancy start date that is after the void date" after_void_date: "Enter a tenancy start date that is after the void date"
after_major_repair_date: "Enter a tenancy start date that is after the major repair date" after_major_repair_date: "Enter a tenancy start date that is after the major repair date"
year_not_two_digits: Tenancy start year must be 2 digits year_not_two_digits: Tenancy start year must be 2 digits
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date"
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date"
location: location:
deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered." deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered."
reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date" reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date"

8
spec/models/validations/date_validations_spec.rb

@ -232,8 +232,11 @@ RSpec.describe Validations::DateValidations do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.mrcdate = Time.zone.local(2012, 1, 1) record.mrcdate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
date_validator.validate_startdate(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start"))
expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_mrc_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -241,6 +244,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2012, 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
expect(record.errors["startdate"]).to be_empty
end end
context "when reason for vacancy is first let of property" do context "when reason for vacancy is first let of property" do
@ -299,8 +303,11 @@ RSpec.describe Validations::DateValidations do
record.startdate = Time.zone.local(2022, 2, 1) record.startdate = Time.zone.local(2022, 2, 1)
record.voiddate = Time.zone.local(2012, 1, 1) record.voiddate = Time.zone.local(2012, 1, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
date_validator.validate_startdate(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start"))
expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_void_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -308,6 +315,7 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2012, 3, 1) record.voiddate = Time.zone.local(2012, 3, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]).to be_empty expect(record.errors["voiddate"]).to be_empty
expect(record.errors["startdate"]).to be_empty
end end
context "when major repairs have been carried out" do context "when major repairs have been carried out" do

Loading…
Cancel
Save