|
|
@ -21,22 +21,6 @@ RSpec.describe Validations::DateValidations do |
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "validates that the tenancy start date is after the void date if it has a void date" do |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2022, 1, 1) |
|
|
|
|
|
|
|
record.voiddate = Time.zone.local(2022, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.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 |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2022, 1, 1) |
|
|
|
|
|
|
|
record.mrcdate = Time.zone.local(2022, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.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 |
|
|
|
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 |
|
|
|
record.startdate = Time.zone.today - 30.days |
|
|
|
record.startdate = Time.zone.today - 30.days |
|
|
|
record.scheme = scheme |
|
|
|
record.scheme = scheme |
|
|
@ -59,6 +43,8 @@ RSpec.describe Validations::DateValidations do |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
expect(record.errors["mrcdate"]) |
|
|
|
expect(record.errors["mrcdate"]) |
|
|
|
.to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")) |
|
|
|
.to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.startdate.after_major_repair_date")) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "must be before the tenancy start date" do |
|
|
|
it "must be before the tenancy start date" do |
|
|
@ -68,23 +54,44 @@ RSpec.describe Validations::DateValidations do |
|
|
|
expect(record.errors["mrcdate"]).to be_empty |
|
|
|
expect(record.errors["mrcdate"]).to be_empty |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "cannot be more than 10 years before the tenancy start date" do |
|
|
|
context "with 2024 logs or earlier" do |
|
|
|
record.startdate = Time.zone.local(2022, 2, 1) |
|
|
|
it "cannot be more than 10 years before the tenancy start date" do |
|
|
|
record.mrcdate = Time.zone.local(2012, 1, 1) |
|
|
|
record.startdate = Time.zone.local(2024, 2, 1) |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
record.mrcdate = Time.zone.local(2014, 1, 31) |
|
|
|
date_validator.validate_startdate(record) |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
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.lettings.date.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 |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2024, 2, 1) |
|
|
|
|
|
|
|
record.mrcdate = Time.zone.local(2014, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
|
|
|
|
expect(record.errors["mrcdate"]).to be_empty |
|
|
|
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "must be within 10 years of the tenancy start date" do |
|
|
|
context "with 2025 logs or later" do |
|
|
|
record.startdate = Time.zone.local(2022, 2, 1) |
|
|
|
it "cannot be more than 20 years before the tenancy start date" do |
|
|
|
record.mrcdate = Time.zone.local(2012, 3, 1) |
|
|
|
record.startdate = Time.zone.local(2026, 2, 1) |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
record.mrcdate = Time.zone.local(2006, 1, 31) |
|
|
|
expect(record.errors["mrcdate"]).to be_empty |
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
expect(record.errors["mrcdate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.mrcdate.twenty_years_before_tenancy_start")) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.startdate.twenty_years_after_mrc_date")) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "must be within 20 years of the tenancy start date" do |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2026, 2, 1) |
|
|
|
|
|
|
|
record.mrcdate = Time.zone.local(2006, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_property_major_repairs(record) |
|
|
|
|
|
|
|
expect(record.errors["mrcdate"]).to be_empty |
|
|
|
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when reason for vacancy is first let of property" do |
|
|
|
context "when reason for vacancy is first let of property" do |
|
|
@ -130,6 +137,8 @@ RSpec.describe Validations::DateValidations do |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
expect(record.errors["voiddate"]) |
|
|
|
expect(record.errors["voiddate"]) |
|
|
|
.to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start")) |
|
|
|
.to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start")) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.startdate.after_void_date")) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "must be before the tenancy start date" do |
|
|
|
it "must be before the tenancy start date" do |
|
|
@ -139,23 +148,45 @@ RSpec.describe Validations::DateValidations do |
|
|
|
expect(record.errors["voiddate"]).to be_empty |
|
|
|
expect(record.errors["voiddate"]).to be_empty |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "cannot be more than 10 years before the tenancy start date" do |
|
|
|
context "with 2024 logs or earlier" do |
|
|
|
record.startdate = Time.zone.local(2022, 2, 1) |
|
|
|
it "cannot be more than 10 years before the tenancy start date" do |
|
|
|
record.voiddate = Time.zone.local(2012, 1, 1) |
|
|
|
record.startdate = Time.zone.local(2024, 2, 1) |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
record.voiddate = Time.zone.local(2014, 1, 31) |
|
|
|
date_validator.validate_startdate(record) |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
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.lettings.date.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 |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2024, 2, 1) |
|
|
|
|
|
|
|
record.voiddate = Time.zone.local(2014, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
|
|
|
|
expect(record.errors["voiddate"]).to be_empty |
|
|
|
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "must be within 10 years of the tenancy start date" do |
|
|
|
context "with 2025 logs or later" do |
|
|
|
record.startdate = Time.zone.local(2022, 2, 1) |
|
|
|
it "cannot be more than 20 years before the tenancy start date" do |
|
|
|
record.voiddate = Time.zone.local(2012, 3, 1) |
|
|
|
record.startdate = Time.zone.local(2026, 2, 1) |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
record.voiddate = Time.zone.local(2006, 1, 31) |
|
|
|
expect(record.errors["voiddate"]).to be_empty |
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
|
|
|
expect(record.errors["voiddate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.void_date.twenty_years_before_tenancy_start")) |
|
|
|
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
|
|
|
.to include(match I18n.t("validations.lettings.date.startdate.twenty_years_after_void_date")) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "must be within 20 years of the tenancy start date" do |
|
|
|
|
|
|
|
record.startdate = Time.zone.local(2026, 2, 1) |
|
|
|
|
|
|
|
record.voiddate = Time.zone.local(2006, 2, 1) |
|
|
|
|
|
|
|
date_validator.validate_property_void_date(record) |
|
|
|
|
|
|
|
expect(record.errors["voiddate"]).to be_empty |
|
|
|
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when major repairs have been carried out" do |
|
|
|
context "when major repairs have been carried out" do |
|
|
|