Browse Source

add voiddate_date_in_soft_range? and major_repairs_date_in_soft_range? methods

pull/820/head
Kat 3 years ago
parent
commit
47735b6500
  1. 8
      app/models/validations/soft_validations.rb
  2. 32
      spec/models/validations/soft_validations_spec.rb

8
app/models/validations/soft_validations.rb

@ -62,6 +62,14 @@ module Validations::SoftValidations
end end
end end
def major_repairs_date_in_soft_range?
mrcdate.present? && startdate.present? && mrcdate.between?(startdate.to_date - 3650, startdate.to_date - 730)
end
def voiddate_date_in_soft_range?
voiddate.present? && startdate.present? && voiddate.between?(startdate.to_date - 3650, startdate.to_date - 730)
end
private private
def details_known_or_lead_tenant?(tenant_number) def details_known_or_lead_tenant?(tenant_number)

32
spec/models/validations/soft_validations_spec.rb

@ -205,4 +205,36 @@ RSpec.describe Validations::SoftValidations do
end end
end end
end end
describe "major repairs date soft validations" do
context "when the major repairs date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2013, 2, 1))
expect(record.major_repairs_date_in_soft_range?).to be true
end
end
context "when the major repairs date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), mrcdate: Time.zone.local(2021, 2, 1))
expect(record.major_repairs_date_in_soft_range?).to be false
end
end
end
describe "void date soft validations" do
context "when the void date is within 10 years of the tenancy start date" do
it "shows the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2013, 2, 1))
expect(record.voiddate_date_in_soft_range?).to be true
end
end
context "when the void date is less than 2 years before the tenancy start date" do
it "does not show the interruption screen" do
record.update!(startdate: Time.zone.local(2022, 2, 1), voiddate: Time.zone.local(2021, 2, 1))
expect(record.voiddate_date_in_soft_range?).to be false
end
end
end
end end

Loading…
Cancel
Save