summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-21 16:43:11 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-21 16:43:11 -0700
commit5b148d997d081473b6b4f7533778c771768a575c (patch)
tree66d0ce384536d7745c64e0f7543974094c1f6a2e
parente16679a1197d52f93fd373931873b9e8bfbd98fa (diff)
downloadchef-5b148d997d081473b6b4f7533778c771768a575c.tar.gz
Make sure we can compare keys in dicts
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/macos_userdefaults.rb3
-rw-r--r--spec/unit/resource/macos_user_defaults_spec.rb5
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 431fa67eaa..835e28a39c 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -84,7 +84,8 @@ class Chef
property :value, [Integer, Float, String, TrueClass, FalseClass, Hash, Array],
description: "The value of the key. Note: If you set the `type` property to `bool` we'll automatically try to convert various `String` forms of the Boolean true/false that Apple accepts in the defaults command: 0/1, 'TRUE'/'FALSE,' 'true'/false', 'YES'/'NO', or 'yes'/'no'.",
- required: [:write]
+ required: [:write],
+ coerce: proc { |v| v.is_a?(Hash) ? v.transform_keys(&:to_s) : v } # make sure keys are all strings for comparison
property :type, String,
description: "The value type of the preference key.",
diff --git a/spec/unit/resource/macos_user_defaults_spec.rb b/spec/unit/resource/macos_user_defaults_spec.rb
index f0d1aa6a53..490a938230 100644
--- a/spec/unit/resource/macos_user_defaults_spec.rb
+++ b/spec/unit/resource/macos_user_defaults_spec.rb
@@ -30,6 +30,11 @@ describe Chef::Resource::MacosUserDefaults do
expect(resource.domain).to eql("NSGlobalDomain")
end
+ it "the value property coerces keys in hashes to symbols so we can compare them with plist data" do
+ resource.value "User": "/Library/Managed Installs/way_fake.log"
+ expect(resource.value).to eq({ "User" => "/Library/Managed Installs/way_fake.log" })
+ end
+
it "the host property defaults to nil" do
expect(resource.host).to be_nil
end