Browse Source

Extract more date validations previously under setup

pull/2738/head
Manny Dinssa 8 months ago
parent
commit
bd7331449c
  1. 8
      app/models/validations/date_validations.rb
  2. 4
      config/locales/en.yml
  3. 7
      config/locales/validations/lettings/date.en.yml
  4. 8
      spec/models/validations/date_validations_spec.rb

8
app/models/validations/date_validations.rb

@ -35,19 +35,19 @@ module Validations::DateValidations
return unless record.startdate && date_valid?("startdate", record) return unless record.startdate && date_valid?("startdate", record)
if record["voiddate"].present? && record.startdate < record["voiddate"] 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 end
if record["mrcdate"].present? && record.startdate < record["mrcdate"] 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 end
if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 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 end
if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650 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
end end

4
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}." "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." 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." 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." 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: 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_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}." 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}."

7
config/locales/validations/lettings/date.en.yml

@ -2,11 +2,18 @@ en:
validations: validations:
lettings: lettings:
date: 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: mrcdate:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date." 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." 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." 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." before_void_date: "Major repairs date must be after the void date if provided."
void_date: void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start 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." before_tenancy_start: "Enter a void date that is before the tenancy start date."

8
spec/models/validations/date_validations_spec.rb

@ -26,7 +26,7 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]) 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 end
it "validates that the tenancy start date is after the major repair date if it has a major repair date" do 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) record.mrcdate = Time.zone.local(2022, 2, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]) 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 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 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"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start"))
expect(record.errors["startdate"]) 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 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
@ -147,7 +147,7 @@ RSpec.describe Validations::DateValidations do
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.lettings.date.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"]) 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 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

Loading…
Cancel
Save