diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-16 11:40:03 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-16 11:40:03 -0700 |
commit | d3b3ff2be6c96c9412a8df5dca29cc121f069815 (patch) | |
tree | ebb59686d6b4ddda207b28d901096d5529ceabef | |
parent | bc5227d5ac004800a30b7b1353fa7461b132f2cb (diff) | |
download | chef-d3b3ff2be6c96c9412a8df5dca29cc121f069815.tar.gz |
Support arrays as input to actions / allowed_actionsjk/3535
-rw-r--r-- | lib/chef/resource.rb | 4 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 3 | ||||
-rw-r--r-- | spec/unit/lwrp_spec.rb | 39 |
3 files changed, 43 insertions, 3 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 8b8d5cf05e..e89dede609 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -974,10 +974,10 @@ class Chef else [ :nothing ] end - @allowed_actions |= actions.map { |v| v.to_sym } + @allowed_actions |= actions.flatten end def self.allowed_actions=(value) - @allowed_actions = value.map { |v| v.to_sym }.uniq + @allowed_actions = value.uniq end # diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index 86e22dd92b..ef3c2b5bba 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -85,8 +85,9 @@ class Chef # Adds +action_names+ to the list of valid actions for this resource. # Does not include superclass's action list when appending. def actions(*action_names) + action_names = action_names.flatten if !action_names.empty? && !@allowed_actions - self.allowed_actions = [ :nothing ] + action_names + self.allowed_actions = ([ :nothing ] + action_names).uniq else allowed_actions(*action_names) end diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 83105ac233..784ff966cd 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -462,6 +462,45 @@ describe "LWRP" do end end + describe "when actions is set to an array" do + let(:resource_class) do + Class.new(Chef::Resource::LWRPBase) do + actions [ :eat, :sleep ] + end + end + let(:resource) do + resource_class.new('blah') + end + it "actions includes those actions" do + expect(resource_class.actions).to eq [ :nothing, :eat, :sleep ] + end + it "allowed_actions includes those actions" do + expect(resource_class.allowed_actions).to eq [ :nothing, :eat, :sleep ] + end + it "resource.allowed_actions includes those actions" do + expect(resource.allowed_actions).to eq [ :nothing, :eat, :sleep ] + end + end + + describe "when allowed_actions is set to an array" do + let(:resource_class) do + Class.new(Chef::Resource::LWRPBase) do + allowed_actions [ :eat, :sleep ] + end + end + let(:resource) do + resource_class.new('blah') + end + it "actions includes those actions" do + expect(resource_class.actions).to eq [ :nothing, :eat, :sleep ] + end + it "allowed_actions includes those actions" do + expect(resource_class.allowed_actions).to eq [ :nothing, :eat, :sleep ] + end + it "resource.allowed_actions includes those actions" do + expect(resource.allowed_actions).to eq [ :nothing, :eat, :sleep ] + end + end end describe "Lightweight Chef::Provider" do |