diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-06-05 21:02:41 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-06-05 21:02:41 -0700 |
commit | 28d097d48a346826806186a78b17f520c8533c1a (patch) | |
tree | 0d1f44bc2705ac7e1ff18a71d284984a3a9ca4ce /spec/unit/resource_spec.rb | |
parent | e13dd0665df1f9c11674d5dc99de108dbacd2f2a (diff) | |
download | chef-28d097d48a346826806186a78b17f520c8533c1a.tar.gz |
Streamline the map locking process with a resource level flag.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Diffstat (limited to 'spec/unit/resource_spec.rb')
-rw-r--r-- | spec/unit/resource_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 67b8f59ff4..7dc2c83c5d 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -1144,4 +1144,38 @@ end it { is_expected.to eq [:two, :one] } end end + + describe ".preview_resource" do + let(:klass) { Class.new(Chef::Resource) } + + before do + allow(Chef::DSL::Resources).to receive(:add_resource_dsl).with(:test_resource) + end + + it "defaults to false" do + expect(klass.preview_resource).to eq false + end + + it "can be set to true" do + klass.preview_resource(true) + expect(klass.preview_resource).to eq true + end + + it "does not affect provides by default" do + expect(Chef.resource_handler_map).to receive(:set).with(:test_resource, klass, {canonical: true}) + klass.resource_name(:test_resource) + end + + it "adds allow_cookbook_override when true" do + expect(Chef.resource_handler_map).to receive(:set).with(:test_resource, klass, {canonical: true, allow_cookbook_override: true}) + klass.preview_resource(true) + klass.resource_name(:test_resource) + end + + it "allows manually overriding back to false" do + expect(Chef.resource_handler_map).to receive(:set).with(:test_resource, klass, {allow_cookbook_override: false}) + klass.preview_resource(true) + klass.provides(:test_resource, allow_cookbook_override: false) + end + end end |