diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-15 17:27:11 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-23 15:26:14 -0700 |
commit | 705e22b975196baa6decf23f9c3a7e676d6aefc4 (patch) | |
tree | bac88ce7328d23a9c31e6f49114249ac7f396985 | |
parent | 0a29c389d8dbc7c61fed13671e636480b8dd850e (diff) | |
download | chef-705e22b975196baa6decf23f9c3a7e676d6aefc4.tar.gz |
Freeze default constants
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 1 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 3edc761ffc..c1a792b235 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -316,6 +316,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 8c01bf7b49..326948713b 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -367,10 +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 - # TODO this isn't really great behavior, but it's noted here so we find out - # if it changed. 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 |