|
|
|
@ -36,7 +36,7 @@ RSpec.describe Validations::DateValidations do
|
|
|
|
|
it "validates that 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 - 3.days |
|
|
|
|
record.scheme = scheme |
|
|
|
|
setup_validator.validate_startdate(record) |
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
.to include(match I18n.t("validations.setup.startdate.before_scheme_end_date")) |
|
|
|
|
end |
|
|
|
@ -44,16 +44,35 @@ RSpec.describe Validations::DateValidations 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.scheme = scheme |
|
|
|
|
setup_validator.validate_startdate(record) |
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces no startdate error for scheme end dates when the chosen scheme does not have an end date" do |
|
|
|
|
record.startdate = Time.zone.today |
|
|
|
|
record.scheme = scheme_no_end_date |
|
|
|
|
setup_validator.validate_startdate(record) |
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when in the production environment" do |
|
|
|
|
before do |
|
|
|
|
allow(Rails.env).to receive(:production?).and_return(true) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that the tenancy start date is not later than 14 days from the current date" do |
|
|
|
|
record.startdate = Time.zone.today + 15.days |
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
expect(record.errors["startdate"]) |
|
|
|
|
.to include(match I18n.t("validations.setup.startdate.later_than_14_days_after")) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces no error when tenancy start date is not later than 14 days from the current date" do |
|
|
|
|
record.startdate = Time.zone.today + 7.days |
|
|
|
|
date_validator.validate_startdate(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "major repairs date" do |
|
|
|
|