diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-05-10 06:00:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-10 06:00:31 -0700 |
commit | 488cf2bbffc170f5bd9df4c391e521e62aec9313 (patch) | |
tree | 2b42df14f09d179c2a171265dee568ca6cafcdcd | |
parent | a6c83a6c712ea5c1e02dffaca159cd540ca01481 (diff) | |
parent | 35977771fa4da04178590dc0e02e0c39c0e81fb0 (diff) | |
download | chef-488cf2bbffc170f5bd9df4c391e521e62aec9313.tar.gz |
Merge pull request #7234 from coderanger/role-huh
Switch Node#role? to use the attributes expansion instead of the run list
-rw-r--r-- | lib/chef/node.rb | 5 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 4391118f06..f03e0ca0b1 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -288,8 +288,11 @@ class Chef end # Returns true if this Node expects a given role, false if not. + # + # @param role_name [String] Role to check for + # @return [Boolean] def role?(role_name) - run_list.include?("role[#{role_name}]") + Array(self[:roles]).include?(role_name) end def primary_runlist diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index c9f3d7d1d2..3a43a155d5 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1160,16 +1160,16 @@ describe Chef::Node do describe "roles" do it "should allow you to query whether or not it has a recipe applied with role?" do - node.run_list << "role[sunrise]" + node.automatic["roles"] = %w{sunrise} expect(node.role?("sunrise")).to eql(true) expect(node.role?("not at home")).to eql(false) end it "should allow you to set roles with arguments" do - node.run_list << "role[one]" - node.run_list << "role[two]" + node.automatic["roles"] = %w{one two} expect(node.role?("one")).to eql(true) expect(node.role?("two")).to eql(true) + expect(node.role?("three")).to eql(false) end end |