Browse Source

validations

pull/683/head
Dushan Despotovic 3 years ago
parent
commit
c75603755d
  1. 4
      app/models/validations/date_validations.rb
  2. 6
      config/initializers/feature_toggle.rb
  3. 2
      config/locales/en.yml
  4. 25
      spec/models/validations/date_validations_spec.rb

4
app/models/validations/date_validations.rb

@ -35,6 +35,10 @@ module Validations::DateValidations
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end
if FeatureToggle.startdate_two_week_validation_enabled? && (record.startdate > Time.zone.today + 14)
record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_14_days_after")
end
if record.scheme_id.present?
scheme_end_date = Scheme.find(record.scheme_id).end_date
if scheme_end_date.present? && (record.startdate > scheme_end_date)

6
config/initializers/feature_toggle.rb

@ -4,4 +4,10 @@ class FeatureToggle
false
end
def self.startdate_two_week_validation_enabled?
return true if Rails.env.production?
false
end
end

2
config/locales/en.yml

@ -62,7 +62,7 @@ en:
intermediate_rent_product_name:
blank: "Enter name of other intermediate rent product"
startdate:
later_than_or_14_days_before: "The start date of a supported housing tenancy must be 14 days before today or later"
later_than_14_days_after: "The tenancy start date must be not be later than 14 days from today's date"
before_scheme_end_date: "The start date of a supported housing tenancy must be before the supported housing scheme end date"
property:

25
spec/models/validations/date_validations_spec.rb

@ -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

Loading…
Cancel
Save