From dad20240946ac2af90847c4518268b89b4cf02c8 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sat, 22 Apr 2017 12:06:02 +0530 Subject: [PATCH] FIX: do not impose default min/max validation on hidden site setting --- lib/validators/integer_setting_validator.rb | 4 ++-- .../validators/integer_setting_validator_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/validators/integer_setting_validator.rb b/lib/validators/integer_setting_validator.rb index 2af3dafb201..185eb0a7994 100644 --- a/lib/validators/integer_setting_validator.rb +++ b/lib/validators/integer_setting_validator.rb @@ -1,8 +1,8 @@ class IntegerSettingValidator def initialize(opts={}) @opts = opts - @opts[:min] = 0 unless @opts[:min].present? - @opts[:max] = 20000 unless @opts[:max].present? + @opts[:min] = 0 unless @opts[:min].present? || @opts[:hidden] + @opts[:max] = 20000 unless @opts[:max].present? || @opts[:hidden] end def valid_value?(val) diff --git a/spec/components/validators/integer_setting_validator_spec.rb b/spec/components/validators/integer_setting_validator_spec.rb index 53da3017546..db0b1cd2810 100644 --- a/spec/components/validators/integer_setting_validator_spec.rb +++ b/spec/components/validators/integer_setting_validator_spec.rb @@ -97,5 +97,14 @@ describe IntegerSettingValidator do expect(validator.valid_value?(-2)).to eq(false) end end + + context "when setting is hidden" do + subject(:validator) { described_class.new(hidden: true) } + + it "does not impose default validations" do + expect(validator.valid_value?(-1)).to eq(true) + expect(validator.valid_value?(20001)).to eq(true) + end + end end end