summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-16 11:14:20 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-16 11:14:20 -0700
commitbc5227d5ac004800a30b7b1353fa7461b132f2cb (patch)
tree3b3b7ba372639dbdf744407289464957d49a95fc
parentb08c9010c387c762a6fa82fa9ae8c2a5e5c8594d (diff)
downloadchef-bc5227d5ac004800a30b7b1353fa7461b132f2cb.tar.gz
Ensure :nothing is in the list of allowed actions for an LWRP
-rw-r--r--lib/chef/resource.rb6
-rw-r--r--lib/chef/resource/lwrp_base.rb2
-rw-r--r--spec/integration/recipes/recipe_dsl_spec.rb44
-rw-r--r--spec/unit/lwrp_spec.rb8
4 files changed, 52 insertions, 8 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 7fe8a52d95..8b8d5cf05e 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -965,7 +965,7 @@ class Chef
#
# @param actions [Array<Symbol>] The list of actions to add to allowed_actions.
#
- # @return [Arrau<Symbol>] The list of actions, as symbols.
+ # @return [Array<Symbol>] The list of actions, as symbols.
#
def self.allowed_actions(*actions)
@allowed_actions ||=
@@ -974,10 +974,10 @@ class Chef
else
[ :nothing ]
end
- @allowed_actions |= actions
+ @allowed_actions |= actions.map { |v| v.to_sym }
end
def self.allowed_actions=(value)
- @allowed_actions = value
+ @allowed_actions = value.map { |v| v.to_sym }.uniq
end
#
diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb
index c486233020..86e22dd92b 100644
--- a/lib/chef/resource/lwrp_base.rb
+++ b/lib/chef/resource/lwrp_base.rb
@@ -86,7 +86,7 @@ class Chef
# Does not include superclass's action list when appending.
def actions(*action_names)
if !action_names.empty? && !@allowed_actions
- self.allowed_actions = action_names
+ self.allowed_actions = [ :nothing ] + action_names
else
allowed_actions(*action_names)
end
diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb
index 3f4bf9fd5f..05ae72e688 100644
--- a/spec/integration/recipes/recipe_dsl_spec.rb
+++ b/spec/integration/recipes/recipe_dsl_spec.rb
@@ -754,4 +754,48 @@ describe "Recipe DSL methods" do
end
end
end
+
+ before(:all) { Namer.current_index = 0 }
+ before { Namer.current_index += 1 }
+
+ context "with an LWRP that declares actions" do
+ let(:resource_class) {
+ Class.new(Chef::Resource::LWRPBase) do
+ provides :"recipe_dsl_spec#{Namer.current_index}"
+ actions :create
+ end
+ }
+ let(:resource) {
+ resource_class.new("blah", run_context)
+ }
+ it "The actions are part of actions along with :nothing" do
+ expect(resource_class.actions).to eq [ :nothing, :create ]
+ end
+ it "The actions are part of allowed_actions along with :nothing" do
+ expect(resource.allowed_actions).to eq [ :nothing, :create ]
+ end
+
+ context "and a subclass that declares more actions" do
+ let(:subresource_class) {
+ Class.new(Chef::Resource::LWRPBase) do
+ provides :"recipe_dsl_spec_sub#{Namer.current_index}"
+ actions :delete
+ end
+ }
+ let(:subresource) {
+ subresource_class.new("subblah", run_context)
+ }
+
+ it "The parent class actions are not part of actions" do
+ expect(subresource_class.actions).to eq [ :nothing, :delete ]
+ end
+ it "The parent class actions are not part of allowed_actions" do
+ expect(subresource.allowed_actions).to eq [ :nothing, :delete ]
+ end
+ it "The parent class actions do not change" do
+ expect(resource_class.actions).to eq [ :nothing, :create ]
+ expect(resource.allowed_actions).to eq [ :nothing, :create ]
+ end
+ end
+ end
end
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 34c6f6f1c5..83105ac233 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -409,13 +409,13 @@ describe "LWRP" do
end
end
- context "when the child does not defined the methods" do
+ context "when the child does not define the methods" do
let(:child) do
Class.new(parent)
end
it "delegates #actions to the parent" do
- expect(child.actions).to eq([:eat, :sleep])
+ expect(child.actions).to eq([:nothing, :eat, :sleep])
end
it "delegates #default_action to the parent" do
@@ -432,7 +432,7 @@ describe "LWRP" do
end
it "does not delegate #actions to the parent" do
- expect(child.actions).to eq([:dont_eat, :dont_sleep])
+ expect(child.actions).to eq([:nothing, :dont_eat, :dont_sleep])
end
it "does not delegate #default_action to the parent" do
@@ -457,7 +457,7 @@ describe "LWRP" do
it "amends actions when they are already defined" do
raise_if_deprecated!
- expect(child.actions).to eq([:eat, :sleep, :drink])
+ expect(child.actions).to eq([:nothing, :eat, :sleep, :drink])
end
end
end