diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-04 10:27:26 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-23 15:23:02 -0700 |
commit | 2d7f1282c63ca6480f363603608e9d3cdf38116e (patch) | |
tree | ad00eb51bf0fd996d3e6e375b2ebdad9bcb20a70 | |
parent | 6e4783f4e71681c7a6fefedde3e71fd60b1488a3 (diff) | |
download | chef-2d7f1282c63ca6480f363603608e9d3cdf38116e.tar.gz |
Ensure validators don't run against initial values
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 1 | ||||
-rw-r--r-- | spec/unit/property/validation_spec.rb | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 9cd70eede7..142c582cdd 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -252,6 +252,7 @@ class Chef # Compare the way "case" would (i.e. `===`) def _pv_is(opts, key, to_be, raise_error: true) + return true if !opts.has_key?(key.to_s) && !opts.has_key?(key.to_sym) value = _pv_opts_lookup(opts, key) to_be = [ to_be ].flatten(1) to_be.each do |tb| diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index d37d23b437..14be7dc271 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -74,6 +74,9 @@ describe "Chef::Resource.property validation" do def self.validation_test(validation, success_values, failure_values, getter_values=[], *tags) with_property ":x, #{validation}", *tags do + it "gets nil when retrieving the initial (non-set) value" do + expect(resource.x).to be_nil + end success_values.each do |v| it "value #{v.inspect} is valid" do resource.instance_eval { @x = 'default' } |