summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-03-04 19:18:32 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2015-03-20 14:38:03 -0700
commit6ffe92446118a9c56e793f42158f35d423d081a7 (patch)
tree897563ba2a509af1a2dbf297727751ec1c396cb7
parent377ec3040dd3ec2b4fc4b4e66d5ca71ab79dd1b7 (diff)
downloadchef-6ffe92446118a9c56e793f42158f35d423d081a7.tar.gz
Update PowershelTypeCoercions to call to_psobject
-rw-r--r--lib/chef/mixin/powershell_type_coercions.rb5
-rw-r--r--spec/unit/mixin/powershell_type_coercions_spec.rb6
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/chef/mixin/powershell_type_coercions.rb b/lib/chef/mixin/powershell_type_coercions.rb
index 580288c3a0..c5c035bb7c 100644
--- a/lib/chef/mixin/powershell_type_coercions.rb
+++ b/lib/chef/mixin/powershell_type_coercions.rb
@@ -39,13 +39,16 @@ class Chef
def translate_type(value)
translation = type_coercions[value.class]
- should_quote = true
translated_value = nil
if translation
should_quote = translation[:single_quoted]
translated_value = translation[:type].call(value)
+ elsif value.respond_to? :to_psobject
+ should_quote = false
+ translated_value = "(#{value.to_psobject})"
else
+ should_quote = true
translated_value = value.to_s
end
diff --git a/spec/unit/mixin/powershell_type_coercions_spec.rb b/spec/unit/mixin/powershell_type_coercions_spec.rb
index 4cca7e2f1f..a6b944adda 100644
--- a/spec/unit/mixin/powershell_type_coercions_spec.rb
+++ b/spec/unit/mixin/powershell_type_coercions_spec.rb
@@ -47,5 +47,11 @@ describe Chef::Mixin::PowershellTypeCoercions do
expect(test_class.translate_type({"a" => 1, "b" => 1.2, "c" => false, "d" => true
})).to eq("@{a=1;b=1.2;c=$false;d=$true}")
end
+
+ it 'should fall back :to_psobject if we have not defined at explicit rule' do
+ ps_obj = double("PSObject")
+ expect(ps_obj).to receive(:to_psobject).and_return('$true')
+ expect(test_class.translate_type(ps_obj)).to eq('($true)')
+ end
end
end