From bd7331449c9e1753db5448ad479c0b061106a06e Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:17:27 +0000 Subject: [PATCH] Extract more date validations previously under setup --- app/models/validations/date_validations.rb | 8 ++++---- config/locales/en.yml | 4 ---- config/locales/validations/lettings/date.en.yml | 7 +++++++ spec/models/validations/date_validations_spec.rb | 8 ++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index 161b6c255..7462290b6 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -35,19 +35,19 @@ module Validations::DateValidations return unless record.startdate && date_valid?("startdate", record) if record["voiddate"].present? && record.startdate < record["voiddate"] - record.errors.add :startdate, I18n.t("validations.setup.startdate.after_void_date") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_void_date") end if record["mrcdate"].present? && record.startdate < record["mrcdate"] - record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date") 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") + record.errors.add :startdate, I18n.t("validations.lettings.date.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") + record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index ab8988a6e..a76f88d2b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -295,11 +295,7 @@ en: "Enter a date within the %{previous_start_year_short} to %{previous_end_year_short} or %{previous_end_year_short} to %{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}." later_than_14_days_after: "The tenancy start date must not be later than 14 days from today’s date." before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme." - 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." year_not_two_or_four_digits: "Tenancy start year must be 2 or 4 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." invalid_merged_organisations_start_date: same_organisation: "Enter a date when the owning and managing organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}." same_merge: "Enter a date when the owning and managing organisations were active. %{owning_organisation} and %{managing_organisation} became inactive on %{owning_organisation_merge_date} and were replaced by %{owning_absorbing_organisation}." diff --git a/config/locales/validations/lettings/date.en.yml b/config/locales/validations/lettings/date.en.yml index 37b0dcd9f..54c53996f 100644 --- a/config/locales/validations/lettings/date.en.yml +++ b/config/locales/validations/lettings/date.en.yml @@ -2,11 +2,18 @@ en: validations: lettings: date: + startdate: + 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." + 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." + mrcdate: 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." diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 099f0365e..f6c81a088 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -26,7 +26,7 @@ RSpec.describe Validations::DateValidations do record.voiddate = Time.zone.local(2022, 2, 1) date_validator.validate_startdate(record) expect(record.errors["startdate"]) - .to include(match I18n.t("validations.setup.startdate.after_void_date")) + .to include(match I18n.t("validations.lettings.date.startdate.after_void_date")) end it "validates that the tenancy start date is after the major repair date if it has a major repair date" do @@ -34,7 +34,7 @@ RSpec.describe Validations::DateValidations do record.mrcdate = Time.zone.local(2022, 2, 1) date_validator.validate_startdate(record) expect(record.errors["startdate"]) - .to include(match I18n.t("validations.setup.startdate.after_major_repair_date")) + .to include(match I18n.t("validations.lettings.date.startdate.after_major_repair_date")) end it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do @@ -76,7 +76,7 @@ RSpec.describe Validations::DateValidations do expect(record.errors["mrcdate"]) .to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start")) expect(record.errors["startdate"]) - .to include(match I18n.t("validations.setup.startdate.ten_years_after_mrc_date")) + .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date")) end it "must be within 10 years of the tenancy start date" do @@ -147,7 +147,7 @@ RSpec.describe Validations::DateValidations do expect(record.errors["voiddate"]) .to include(match I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start")) expect(record.errors["startdate"]) - .to include(match I18n.t("validations.setup.startdate.ten_years_after_void_date")) + .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_void_date")) end it "must be within 10 years of the tenancy start date" do