summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-07 10:03:07 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-07 10:03:07 -0800
commit7b0ec41b478c757522cb9c16aa061955bdf746bd (patch)
tree254df9e3ce3ad02956d2fc6d50f236c9cd1d6102
parent767e9ad1e1332bb49dee5e9ed23db17bdf87d2e2 (diff)
downloadchef-7b0ec41b478c757522cb9c16aa061955bdf746bd.tar.gz
add back the Array form of setting supports
bonus fix: i believe the array form was mutating the default values, it should stop doing that now. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/resource/mount.rb3
-rw-r--r--lib/chef/resource/service.rb4
-rw-r--r--spec/unit/resource/mount_spec.rb14
-rw-r--r--spec/unit/resource/service_spec.rb9
4 files changed, 26 insertions, 4 deletions
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb
index 32ffee931b..2aca8432dd 100644
--- a/lib/chef/resource/mount.rb
+++ b/lib/chef/resource/mount.rb
@@ -31,7 +31,8 @@ class Chef
allowed_actions :mount, :umount, :unmount, :remount, :enable, :disable
# this is a poor API please do not re-use this pattern
- property :supports, Hash, default: { remount: false }
+ property :supports, Hash, default: { remount: false },
+ coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
def initialize(name, run_context = nil)
super
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 77c99fbdc6..d9f0969ecb 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -30,7 +30,9 @@ class Chef
allowed_actions :enable, :disable, :start, :stop, :restart, :reload,
:mask, :unmask
- property :supports, Hash, default: { restart: nil, reload: nil, status: nil }
+ # this is a poor API please do not re-use this pattern
+ property :supports, Hash, default: { restart: nil, reload: nil, status: nil },
+ coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
def initialize(name, run_context = nil)
super
diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb
index 50e706cfd5..832f7644ac 100644
--- a/spec/unit/resource/mount_spec.rb
+++ b/spec/unit/resource/mount_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2009-2017, Chef Software Inc.
+# Copyright:: Copyright 2009-2016, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -87,6 +87,11 @@ describe Chef::Resource::Mount do
expect(@resource.options).to be_a_kind_of(Array)
end
+ it "should allow options attribute as an array" do
+ @resource.options %w{ro nosuid}
+ expect(@resource.options).to be_a_kind_of(Array)
+ end
+
it "should allow options to be sent as a delayed evaluator" do
@resource.options Chef::DelayedEvaluator.new { %w{rw noexec} }
expect(@resource.options).to eql(%w{rw noexec})
@@ -139,6 +144,13 @@ describe Chef::Resource::Mount do
expect(@resource.supports).to eq(support_hash)
end
+ it "should allow you to set feature support as an array" do
+ support_array = [ :remount ]
+ support_hash = { :remount => true }
+ @resource.supports(support_array)
+ expect(@resource.supports).to eq(support_hash)
+ end
+
it "should allow you to set feature support as a hash" do
support_hash = { :remount => true }
@resource.supports(support_hash)
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb
index fd38fb2faf..8d661e2a7a 100644
--- a/spec/unit/resource/service_spec.rb
+++ b/spec/unit/resource/service_spec.rb
@@ -144,8 +144,15 @@ describe Chef::Resource::Service do
expect(@resource.supports).to eq(support_hash)
end
+ it "should allow you to set what features this resource supports as a array" do
+ support_array = [ :status, :restart ]
+ support_hash = { :status => true, :restart => true }
+ @resource.supports(support_array)
+ expect(@resource.supports).to eq(support_hash)
+ end
+
it "should allow you to set what features this resource supports as a hash" do
- support_hash = { :status => true, :restart => true, :reload => false }
+ support_hash = { :status => true, :restart => true }
@resource.supports(support_hash)
expect(@resource.supports).to eq(support_hash)
end