Browse Source

feature toggle possible radio option validation

pull/1137/head
Phil Lee 3 years ago
parent
commit
74b208f216
  1. 2
      app/models/validations/shared_validations.rb
  2. 4
      config/initializers/feature_toggle.rb
  3. 13
      spec/models/validations/shared_validations_spec.rb

2
app/models/validations/shared_validations.rb

@ -70,6 +70,8 @@ module Validations::SharedValidations
end end
def validate_valid_radio_option(record) def validate_valid_radio_option(record)
return unless FeatureToggle.validate_valid_radio_options?
record.attributes.each do |question_id, _v| record.attributes.each do |question_id, _v|
question = record.form.get_question(question_id, record) question = record.form.get_question(question_id, record)

4
config/initializers/feature_toggle.rb

@ -30,4 +30,8 @@ class FeatureToggle
def self.upload_enabled? def self.upload_enabled?
!Rails.env.development? !Rails.env.development?
end end
def self.validate_valid_radio_options?
!(Rails.env.production? || Rails.env.staging?)
end
end end

13
spec/models/validations/shared_validations_spec.rb

@ -84,5 +84,18 @@ RSpec.describe Validations::SharedValidations do
expect(record.errors["needstype"]).to be_present expect(record.errors["needstype"]).to be_present
expect(record.errors["needstype"]).to eql(["Enter a valid value for needs type"]) expect(record.errors["needstype"]).to eql(["Enter a valid value for needs type"])
end end
context "when feature is toggled off" do
before do
allow(FeatureToggle).to receive(:validate_valid_radio_options?).and_return(false)
end
it "allows any values" do
record.needstype = 3
shared_validator.validate_valid_radio_option(record)
expect(record.errors["needstype"]).to be_empty
end
end
end end
end end

Loading…
Cancel
Save