diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-15 17:27:11 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-18 15:26:09 -0700 |
commit | d4d4a7b5f5888dd01065e8b040a211ca6e8ace7e (patch) | |
tree | d352c77c6ce5a42f81d9d33328ff9a55f9331b03 | |
parent | 20a953d0dbc16d6a0f095a9bf0096175c3727ed9 (diff) | |
download | chef-d4d4a7b5f5888dd01065e8b040a211ca6e8ace7e.tar.gz |
Freeze default constants
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 1 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index c5836122a2..8b5df37186 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -322,6 +322,7 @@ class Chef def _pv_default(opts, key, default_value) value = _pv_opts_lookup(opts, key) if value.nil? + default_value = default_value.freeze if !default_value.is_a?(DelayedEvaluator) opts[key] = default_value end end diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index f048355269..04a542ea2c 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -367,9 +367,14 @@ describe "Chef::Resource.property" do expect(resource.x.object_id).to eq(value.object_id) end it "Multiple instances of x receive the exact same value" do - # Bleagh. But it's what we do. expect(resource.x.object_id).to eq(resource_class.new('blah2').x.object_id) end + it "The default value is frozen" do + expect(resource.x).to be_frozen + end + it "The default value cannot be written to" do + expect { resource.x[:a] = 1 }.to raise_error RuntimeError, /frozen/ + end end with_property ':x, default: lazy { {} }' do |