Browse Source

feat: add feature flag

pull/1318/head
natdeanlewissoftwire 2 years ago
parent
commit
ba2124eb08
  1. 2
      app/models/validations/setup_validations.rb
  2. 4
      config/initializers/feature_toggle.rb
  3. 4
      spec/models/validations/setup_validations_spec.rb

2
app/models/validations/setup_validations.rb

@ -5,7 +5,7 @@ module Validations::SetupValidations
def validate_startdate_setup(record) def validate_startdate_setup(record)
return unless record.startdate && date_valid?("startdate", 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 record.errors.add :startdate, validation_error_message
end end
end end

4
config/initializers/feature_toggle.rb

@ -8,6 +8,10 @@ class FeatureToggle
Rails.env.production? || Rails.env.test? || Rails.env.staging? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.startdate_validation_enabled?
!Rails.env.test?
end
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end

4
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(:setup_validator_class) { Class.new { include Validations::SetupValidations } }
let(:record) { FactoryBot.create(:lettings_log) } let(:record) { FactoryBot.create(:lettings_log) }
before do
allow(FeatureToggle).to receive(:startdate_validation_enabled?).and_return(true)
end
describe "tenancy start date" do describe "tenancy start date" do
context "when in 22/23 collection" do context "when in 22/23 collection" do
context "when in the crossover period" do context "when in the crossover period" do

Loading…
Cancel
Save