diff options
author | danielsdeleo <dan@opscode.com> | 2012-12-26 11:04:49 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2012-12-26 13:01:12 -0800 |
commit | f132b98c4faddcaee5002105a6aa647bbb549c19 (patch) | |
tree | 91085a87a59f1c9148157d6917eca73e30319457 | |
parent | 4f3ae7200f693b3c5ad7278534aa0844b1bd225d (diff) | |
download | chef-f132b98c4faddcaee5002105a6aa647bbb549c19.tar.gz |
[CHEF-3724] correctly query the recipes attribute in Node#recipe?
Also, coerce node[:recipes] to an Array so that Node#recipe? will work
correctly when the recipes attribute has not been set.
-rw-r--r-- | lib/chef/node.rb | 2 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index d079c8aeff..a2bffcc172 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -241,7 +241,7 @@ class Chef # # NOTE: It's used by cookbook authors def recipe?(recipe_name) - run_list.include?(recipe_name) || self[recipes].include?(recipe_name) + run_list.include?(recipe_name) || Array(self[:recipes]).include?(recipe_name) end # Returns true if this Node expects a given role, false if not. diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index f8cfd39deb..d785f84c73 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -404,6 +404,36 @@ describe Chef::Node do end end + describe "when querying for recipes in the run list" do + context "when a recipe is in the top level run list" do + before do + node.run_list << "recipe[nginx::module]" + end + + it "finds the recipe" do + node.recipe?("nginx::module").should be_true + end + + it "does not find a recipe not in the run list" do + node.recipe?("nginx::other_module").should be_false + end + end + context "when a recipe is in the expanded run list only" do + before do + node.run_list << "role[base]" + node.automatic_attrs[:recipes] = [ "nginx::module" ] + end + + it "finds a recipe in the expanded run list" do + node.recipe?("nginx::module").should be_true + end + + it "does not find a recipe that's not in the run list" do + node.recipe?("nginx::other_module").should be_false + end + end + end + describe "when clearing computed state at the beginning of a run" do before do node.default[:foo] = "default" |