Browse Source

Void date validations

pull/303/head
baarkerlounger 3 years ago
parent
commit
a65073615f
  1. 58
      spec/models/case_log_spec.rb
  2. 49
      spec/models/validations/date_validations_spec.rb

58
spec/models/case_log_spec.rb

@ -354,60 +354,6 @@ RSpec.describe CaseLog do
end
end
context "when saving void date" do
it "must have less than 10 years between the tenancy start date and void" do
expect {
described_class.create!(
startdate: Date.new(2021, 10, 10),
property_void_date: Date.new(2009, 10, 10),
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(
startdate: Date.new(2021, 10, 10),
property_void_date: Date.new(2015, 10, 10),
owning_organisation:,
managing_organisation:,
)
}.not_to raise_error
end
it "must be before the tenancy start date" do
expect {
described_class.create!(
startdate: Date.new(2021, 10, 10),
property_void_date: Date.new(2021, 10, 11),
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(
startdate: Date.new(2021, 10, 10),
property_void_date: Date.new(2019, 10, 10),
owning_organisation:,
managing_organisation:,
)
}.not_to raise_error
end
it "must be before major repairs date if major repairs date provided" do
expect {
described_class.create!(
startdate: Date.new(2021, 10, 10),
mrcdate: Date.new(2019, 10, 10),
property_void_date: Date.new(2019, 11, 11),
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "when validating local authority" do
it "Has to be london if rent type london affordable rent" do
expect {
@ -572,6 +518,10 @@ RSpec.describe CaseLog do
it "validates property major repairs date" do
expect(validator).to receive(:validate_property_major_repairs)
end
it "validates property void date" do
expect(validator).to receive(:validate_property_void_date)
end
end
describe "status" do

49
spec/models/validations/date_validations_spec.rb

@ -98,4 +98,53 @@ RSpec.describe Validations::DateValidations do
end
end
end
describe "property void date" do
it "cannot be after the tenancy start date" do
record.startdate = Time.zone.local(2022, 1, 1)
record.property_void_date = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"])
.to include(match I18n.t("validations.property.void_date.before_tenancy_start"))
end
it "must be before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2022, 1, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty
end
it "cannot be more than 10 years before the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2012, 1, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"])
.to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start"))
end
it "must be within 10 years of the tenancy start date" do
record.startdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2012, 3, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty
end
context "when major repairs have been carried out" do
it "cannot be after major repairs date" do
record.mrcdate = Time.zone.local(2022, 1, 1)
record.property_void_date = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"])
.to include(match I18n.t("validations.property.void_date.after_mrcdate"))
end
it "must be before major repairs date" do
record.mrcdate = Time.zone.local(2022, 2, 1)
record.property_void_date = Time.zone.local(2022, 1, 1)
date_validator.validate_property_void_date(record)
expect(record.errors["property_void_date"]).to be_empty
end
end
end
end

Loading…
Cancel
Save