diff options
author | Thom May <thom@may.lt> | 2015-11-12 10:07:30 +0000 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-11-12 10:07:30 +0000 |
commit | f4a47f9e248d99fe6c284bcbff7c2b05d6dd0484 (patch) | |
tree | 0775ce6882d47f093201a57f49ee65fde6941e25 | |
parent | b0dbe243d469cc36477ba8102b74a8456b6f276d (diff) | |
parent | af7379d0beeceacf0c7806ac1811a472dbc15a3b (diff) | |
download | chef-f4a47f9e248d99fe6c284bcbff7c2b05d6dd0484.tar.gz |
Merge pull request #4064 from josb/master
Use the initializer to avoid NoMethodError on nil.include?
-rw-r--r-- | lib/chef/knife/core/node_presenter.rb | 2 | ||||
-rw-r--r-- | lib/chef/node.rb | 8 | ||||
-rw-r--r-- | lib/chef/recipe.rb | 8 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 18 | ||||
-rw-r--r-- | spec/unit/resource/chef_gem_spec.rb | 2 |
6 files changed, 21 insertions, 19 deletions
diff --git a/lib/chef/knife/core/node_presenter.rb b/lib/chef/knife/core/node_presenter.rb index d9ea8c7669..5192c53f51 100644 --- a/lib/chef/knife/core/node_presenter.rb +++ b/lib/chef/knife/core/node_presenter.rb @@ -125,7 +125,7 @@ ROLES summarized << <<-SUMMARY #{key('Recipes:')} #{Array(node[:recipes]).join(', ')} #{key('Platform:')} #{node[:platform]} #{node[:platform_version]} -#{key('Tags:')} #{Array(node[:tags]).join(', ')} +#{key('Tags:')} #{node.tags.join(', ')} SUMMARY if config[:medium_output] || config[:long_output] summarized +=<<-MORE diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 83ec7e2550..b04e607624 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -376,12 +376,12 @@ class Chef normal[:tags] end - def tag(*tags) - tags.each do |tag| - self.normal[:tags].push(tag.to_s) unless self[:tags].include? tag.to_s + def tag(*args) + args.each do |tag| + tags.push(tag.to_s) unless tags.include? tag.to_s end - self[:tags] + tags end # Extracts the run list from +attrs+ and applies it. Returns the remaining attributes diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb index 262560f754..0f9bf2655b 100644 --- a/lib/chef/recipe.rb +++ b/lib/chef/recipe.rb @@ -97,10 +97,8 @@ class Chef # true<TrueClass>:: If all the parameters are present # false<FalseClass>:: If any of the parameters are missing def tagged?(*tags) - return false if run_context.node[:tags].nil? - tags.each do |tag| - return false unless run_context.node[:tags].include?(tag) + return false unless run_context.node.tags.include?(tag) end true end @@ -111,10 +109,10 @@ class Chef # tags<Array>:: A list of tags # # === Returns - # tags<Array>:: The current list of run_context.node[:tags] + # tags<Array>:: The current list of run_context.node.tags def untag(*tags) tags.each do |tag| - run_context.node.normal[:tags].delete(tag) + run_context.node.tags.delete(tag) end end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 17e085a465..4b57a93009 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -793,7 +793,7 @@ describe Chef::Node do end it "should not set the tags attribute to an empty array if it is already defined" do - node.normal[:tags] = [ "radiohead" ] + node.tag("radiohead") node.consume_external_attrs(@ohai_data, {}) expect(node.tags).to eql([ "radiohead" ]) end diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index ea3ab44c16..b242f28e11 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -35,7 +35,7 @@ describe Chef::Recipe do let(:cookbook_collection) { Chef::CookbookCollection.new(cookbook_loader) } let(:node) do - Chef::Node.new.tap {|n| n.normal[:tags] = [] } + Chef::Node.new end let(:events) do @@ -615,21 +615,25 @@ describe Chef::Recipe do end end + it "should initialize tags to an empty Array" do + expect(node.tags).to eql([]) + end + it "should set tags via tag" do recipe.tag "foo" - expect(node[:tags]).to include("foo") + expect(node.tags).to include("foo") end it "should set multiple tags via tag" do recipe.tag "foo", "bar" - expect(node[:tags]).to include("foo") - expect(node[:tags]).to include("bar") + expect(node.tags).to include("foo") + expect(node.tags).to include("bar") end it "should not set the same tag twice via tag" do recipe.tag "foo" recipe.tag "foo" - expect(node[:tags]).to eql([ "foo" ]) + expect(node.tags).to eql([ "foo" ]) end it "should return the current list of tags from tag with no arguments" do @@ -653,13 +657,13 @@ describe Chef::Recipe do it "should remove a tag from the tag list via untag" do recipe.tag "foo" recipe.untag "foo" - expect(node[:tags]).to eql([]) + expect(node.tags).to eql([]) end it "should remove multiple tags from the tag list via untag" do recipe.tag "foo", "bar" recipe.untag "bar", "foo" - expect(node[:tags]).to eql([]) + expect(node.tags).to eql([]) end end diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb index 7352a8f5fe..fe788075fd 100644 --- a/spec/unit/resource/chef_gem_spec.rb +++ b/spec/unit/resource/chef_gem_spec.rb @@ -52,7 +52,7 @@ describe Chef::Resource::ChefGem, "gem_binary" do context "when building the resource" do let(:node) do - Chef::Node.new.tap {|n| n.normal[:tags] = [] } + Chef::Node.new end let(:run_context) do |