summaryrefslogtreecommitdiff
path: root/spec/unit/resource_spec.rb
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2015-06-26 15:01:23 -0700
committerNoah Kantrowitz <noah@coderanger.net>2015-06-29 10:51:58 -0700
commit116ca7f695fd5ec20bf24cb4114e9b6984a2b5b7 (patch)
treef8feb5ecc289e89acd5081ff29dc928743ba1613 /spec/unit/resource_spec.rb
parent1289161dd9b53a5e3c9f6c601f6552c452a3e5ad (diff)
downloadchef-116ca7f695fd5ec20bf24cb4114e9b6984a2b5b7.tar.gz
Rework Resource#action to match the 12.3 API.
This means it always coerces to an Array. Also ensures that Resource#action= goes through the same validation. Fixes #3604.
Diffstat (limited to 'spec/unit/resource_spec.rb')
-rw-r--r--spec/unit/resource_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 8b0baff921..44fe1e90a3 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -977,4 +977,42 @@ describe Chef::Resource do
end
end
+
+ describe "#action" do
+ let(:resource_class) do
+ Class.new(described_class) do
+ allowed_actions(%i{one two})
+ end
+ end
+ let(:resource) { resource_class.new('test', nil) }
+ subject { resource.action }
+
+ context "with a symbol action" do
+ before { resource.action(:one) }
+ it { is_expected.to eq [:one] }
+ end
+
+ context "with a string action" do
+ before { resource.action('two') }
+ it { is_expected.to eq [:two] }
+ end
+
+ context "with an array action" do
+ before { resource.action([:two, :one]) }
+ it { is_expected.to eq [:two, :one] }
+ end
+
+ context "with an assignment" do
+ before { resource.action = :one }
+ it { is_expected.to eq [:one] }
+ end
+
+ context "with an invalid action" do
+ it { expect { resource.action(:three) }.to raise_error Chef::Exceptions::ValidationFailed }
+ end
+
+ context "with an invalid assignment action" do
+ it { expect { resource.action = :three }.to raise_error Chef::Exceptions::ValidationFailed }
+ end
+ end
end