diff --git a/app/models/validations/date_validations.rb b/app/models/validations/date_validations.rb index dce5c1ef0..7462290b6 100644 --- a/app/models/validations/date_validations.rb +++ b/app/models/validations/date_validations.rb @@ -4,30 +4,30 @@ module Validations::DateValidations def validate_property_major_repairs(record) date_valid?("mrcdate", record) if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"] - record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_tenancy_start") + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start") end if is_rsnvac_first_let?(record) && record["mrcdate"].present? - record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.not_first_let") + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.not_first_let") end 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.ten_years_before_tenancy_start") + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start") end end def validate_property_void_date(record) if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 - record.errors.add :voiddate, I18n.t("validations.property.void_date.ten_years_before_tenancy_start") + record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start") end if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date - record.errors.add :voiddate, I18n.t("validations.property.void_date.before_tenancy_start") + record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start") end if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date - record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.property.void_date.after_mrcdate") - record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_void_date") + record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.lettings.date.void_date.after_mrcdate") + record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_void_date") end end @@ -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 a0d31fee5..5baa98338 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}." @@ -362,15 +358,6 @@ en: invalid: "UPRN must be 12 digits or less." uprn_known: invalid: "You must answer UPRN known?" - 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." - after_mrcdate: "Void date must be before the major repairs date if provided." la: la_invalid_for_org: "%{org_name} does not operate in %{la_name}." postcode_invalid_for_org: "Enter a postcode in an area covered by %{org_name}." diff --git a/config/locales/validations/lettings/date.en.yml b/config/locales/validations/lettings/date.en.yml new file mode 100644 index 000000000..54c53996f --- /dev/null +++ b/config/locales/validations/lettings/date.en.yml @@ -0,0 +1,20 @@ +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." + after_mrcdate: "Void date must be before the major repairs date if provided." diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 59be2537e..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 @@ -58,7 +58,7 @@ RSpec.describe Validations::DateValidations do record.mrcdate = Time.zone.local(2022, 2, 1) date_validator.validate_property_major_repairs(record) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.before_tenancy_start")) + .to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")) end it "must be before the tenancy start date" do @@ -74,9 +74,9 @@ RSpec.describe Validations::DateValidations do date_validator.validate_property_major_repairs(record) date_validator.validate_startdate(record) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start")) + .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 @@ -93,7 +93,7 @@ RSpec.describe Validations::DateValidations do record.mrcdate = Time.zone.local(2022, 1, 1) date_validator.validate_property_major_repairs(record) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.not_first_let")) + .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) end it "validates that no major repair date is provided for a conversion" do @@ -101,7 +101,7 @@ RSpec.describe Validations::DateValidations do record.mrcdate = Time.zone.local(2022, 1, 1) date_validator.validate_property_major_repairs(record) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.not_first_let")) + .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) end it "validates that no major repair date is provided for a leased property" do @@ -109,7 +109,7 @@ RSpec.describe Validations::DateValidations do record.mrcdate = Time.zone.local(2022, 1, 1) date_validator.validate_property_major_repairs(record) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.not_first_let")) + .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let")) end end @@ -129,7 +129,7 @@ RSpec.describe Validations::DateValidations do 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.before_tenancy_start")) + .to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start")) end it "must be before the tenancy start date" do @@ -145,9 +145,9 @@ RSpec.describe Validations::DateValidations do date_validator.validate_property_void_date(record) date_validator.validate_startdate(record) expect(record.errors["voiddate"]) - .to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) + .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 @@ -164,9 +164,9 @@ RSpec.describe Validations::DateValidations do 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")) + .to include(match I18n.t("validations.lettings.date.void_date.after_mrcdate")) expect(record.errors["mrcdate"]) - .to include(match I18n.t("validations.property.mrcdate.before_void_date")) + .to include(match I18n.t("validations.lettings.date.mrcdate.before_void_date")) end it "must be before major repairs date" do