diff options
-rw-r--r-- | lib/chef/resource/plist.rb | 9 | ||||
-rw-r--r-- | spec/functional/resource/plist_spec.rb | 25 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/chef/resource/plist.rb b/lib/chef/resource/plist.rb index 6783ae5f51..d316d81b2a 100644 --- a/lib/chef/resource/plist.rb +++ b/lib/chef/resource/plist.rb @@ -84,7 +84,7 @@ class Chef converge_if_changed :path do converge_by "create new plist: '#{new_resource.path}'" do file new_resource.path do - content {}.to_plist + content({}.to_plist) owner new_resource.owner group new_resource.group mode new_resource.mode if property_is_set?(:mode) @@ -188,7 +188,12 @@ class Chef sep = " " arg = case subcommand.to_s when "add" - type_to_commandline_string(value) + if value.is_a?(Hash) + sep = ":" + value.map { |k, v| "#{k} #{type_to_commandline_string(v)}" } + else + type_to_commandline_string(value) + end when "set" if value.is_a?(Hash) sep = ":" diff --git a/spec/functional/resource/plist_spec.rb b/spec/functional/resource/plist_spec.rb new file mode 100644 index 0000000000..324a01c0c6 --- /dev/null +++ b/spec/functional/resource/plist_spec.rb @@ -0,0 +1,25 @@ +require "spec_helper" +require "plist" + +describe Chef::Resource::PlistResource, :macos_only, requires_root: true do + include RecipeDSLHelper + + let(:global_prefs) do + File.join(Dir.mktmpdir, ".GlobalPreferences.plist") + end + + before(:each) do + FileUtils.rm_f global_prefs + end + + context "make Monday the first DOW" do + it "creates a new plist with a hash value" do + plist global_prefs do + entry "AppleFirstWeekday" + value(gregorian: 4) + end + expect(File.exist?(global_prefs)) + expect(shell_out!("/usr/libexec/PlistBuddy -c 'Print :\"AppleFirstWeekday\":gregorian' \"#{global_prefs}\"").stdout.to_i).to eq(4) + end + end +end |