From ba2124eb0825b7f690e4b8d3c3d2f6be6f069ff1 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 3 Mar 2023 14:30:56 +0000 Subject: [PATCH] feat: add feature flag --- app/models/validations/setup_validations.rb | 2 +- config/initializers/feature_toggle.rb | 4 ++++ .../validations/setup_validations_spec.rb | 24 +++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index ff17706bb..a192ad0dd 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -5,7 +5,7 @@ module Validations::SetupValidations def validate_startdate_setup(record) return unless record.startdate && date_valid?("startdate", record) - unless record.startdate.between?(active_collection_start_date, current_collection_end_date) + if FeatureToggle.startdate_validation_enabled? && !record.startdate.between?(active_collection_start_date, current_collection_end_date) record.errors.add :startdate, validation_error_message end end diff --git a/config/initializers/feature_toggle.rb b/config/initializers/feature_toggle.rb index a7651919f..0092188f4 100644 --- a/config/initializers/feature_toggle.rb +++ b/config/initializers/feature_toggle.rb @@ -8,6 +8,10 @@ class FeatureToggle Rails.env.production? || Rails.env.test? || Rails.env.staging? end + def self.startdate_validation_enabled? + !Rails.env.test? + end + def self.startdate_two_week_validation_enabled? Rails.env.production? || Rails.env.test? || Rails.env.staging? end diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index 55aa94a04..ce8ac1dc3 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -6,6 +6,10 @@ RSpec.describe Validations::SetupValidations do let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:record) { FactoryBot.create(:lettings_log) } + before do + allow(FeatureToggle).to receive(:startdate_validation_enabled?).and_return(true) + end + describe "tenancy start date" do context "when in 22/23 collection" do context "when in the crossover period" do @@ -94,7 +98,7 @@ RSpec.describe Validations::SetupValidations do record.irproduct_other = nil setup_validator.validate_irproduct_other(record) expect(record.errors["irproduct_other"]) - .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) + .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) end it "adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product" do @@ -102,7 +106,7 @@ RSpec.describe Validations::SetupValidations do record.irproduct_other = "" setup_validator.validate_irproduct_other(record) expect(record.errors["irproduct_other"]) - .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) + .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) end it "Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product" do @@ -128,7 +132,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_scheme(record) expect(record.errors["scheme_id"]) - .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) + .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) end it "produces no error when tenancy start date is during an active location period" do @@ -153,7 +157,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_scheme(record) expect(record.errors["scheme_id"]) - .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) + .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) end it "produces no error when tenancy start date is during an active location period" do @@ -180,7 +184,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_scheme(record) expect(record.errors["scheme_id"]) - .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) + .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) end end @@ -197,7 +201,7 @@ RSpec.describe Validations::SetupValidations do record.scheme = scheme setup_validator.validate_scheme(record) expect(record.errors["scheme_id"]) - .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 August 2022")) + .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 August 2022")) end it "produces no error when tenancy start date is during an active scheme period" do @@ -223,7 +227,7 @@ RSpec.describe Validations::SetupValidations do record.scheme = scheme setup_validator.validate_scheme(record) expect(record.errors["scheme_id"]) - .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 September 2022")) + .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 September 2022")) end it "produces no error when tenancy start date is during an active scheme period" do @@ -250,7 +254,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_location(record) expect(record.errors["location_id"]) - .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) + .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) end it "produces no error when tenancy start date is during an active location period" do @@ -275,7 +279,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_location(record) expect(record.errors["location_id"]) - .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) + .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) end it "produces no error when tenancy start date is during an active location period" do @@ -302,7 +306,7 @@ RSpec.describe Validations::SetupValidations do record.location = location setup_validator.validate_location(record) expect(record.errors["location_id"]) - .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) + .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) end end end