From 7b0ec41b478c757522cb9c16aa061955bdf746bd Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 7 Mar 2017 10:03:07 -0800 Subject: 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 --- lib/chef/resource/mount.rb | 3 ++- lib/chef/resource/service.rb | 4 +++- spec/unit/resource/mount_spec.rb | 14 +++++++++++++- spec/unit/resource/service_spec.rb | 9 ++++++++- 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 () # Author:: Tyler Cloke () -# 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 -- cgit v1.2.1