diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 7c6cdd5d2..d5b8b50f8 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -35,11 +35,10 @@ module Validations::DateValidations record.errors.add :startdate, I18n.t("validations.date.outside_collection_window") end - # if record.voiddate.present? - # if (record.startdate.to_date - record.voiddate.to_date).to_i.abs > 730 - # record.errors.add :startdate, I18n.t("validations.setup.startdate.voiddate_difference") - # end - # end + if record.startdate < Time.zone.today - 14 + record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_or_14_days_before") + + end if record.scheme_id.present? scheme_end_date = Scheme.find(record.scheme_id).end_date diff --git a/config/locales/en.yml b/config/locales/en.yml index e923ff8af..5d2e8ed29 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -62,10 +62,8 @@ en: intermediate_rent_product_name: blank: "Enter name of other intermediate rent product" startdate: - today_or_earlier: "The start date of a supported housing tenancy must be today or ealier" + later_than_or_14_days_before: "The start date of a supported housing tenancy must be 14 days before today or later" before_scheme_end_date: "The start date of a supported housing tenancy must be before the housing scheme end date" - voiddate_difference: "The difference between the tenancy start date and property void date must be 730 days or less" - mrcdate_difference: "The difference between the tenancy start date and major repais date must be 730 days or less" property: mrcdate: diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 6cb717fab..91041e8a8 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -33,6 +33,19 @@ RSpec.describe Validations::DateValidations do expect(record.errors["startdate"]).to be_empty end + it "validates that the tenancy start date is later than or 14 days before the current date" do + record.startdate = Time.zone.today - 15.days + setup_validator.validate_startdate(record) + expect(record.errors["startdate"]) + .to include(match I18n.t("validations.setup.startdate.later_than_or_14_days_before")) + end + + it "produces no error when the tenancy start date is later than or 14 days before the current date" do + record.startdate = Time.zone.today - 7.days + setup_validator.validate_startdate(record) + expect(record.errors["startdate"]).to be_empty + end + it "validates that the tenancy start date is before the end date of the chosen scheme if it has an end date" do record.startdate = Time.zone.today - 3.days record.scheme = scheme @@ -54,21 +67,6 @@ RSpec.describe Validations::DateValidations do setup_validator.validate_startdate(record) expect(record.errors["startdate"]).to be_empty end - - # it "validates that tenancy start date is less than 730 days away from the void date" do - # record.startdate = Time.zone.today - # record.voiddate = Time.zone.today - 3.years - # setup_validator.validate_startdate(record) - # expect(record.errors["startdate"]) - # .to include(match I18n.t("validations.setup.startdate.voiddate_difference")) - # end - - # it "produces no error tenancy start date is less than 730 days away from the void date" do - # record.startdate = Time.zone.today - # record.voiddate = Time.zone.today - 6.months - # setup_validator.validate_startdate(record) - # expect(record.errors["startdate"]).to be_empty - # end end describe "major repairs date" do