Handle undef for parameter argument

This commit adds better handling of the case where
undef is passed as the parameter value.

This works by converting '' into []
This commit is contained in:
Dan Bode 2012-08-13 18:52:00 -07:00 committed by Jeff McCune
parent a0cb8cdee4
commit 4f8b133917
3 changed files with 5 additions and 1 deletions

View file

@ -20,7 +20,9 @@ ENDOFDOC
) do |vals|
reference, params = vals
raise(ArgumentError, 'Must specify a reference') unless reference
params ||= {}
if (! params) || params == ''
params = {}
end
ret = false
if resource = findresource(reference.to_s)
matches = params.collect do |key, value|

View file

@ -26,6 +26,7 @@ describe 'defined_with_params' do
should run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true)
should run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true)
should run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false)
should run.with_params('User[dan]', '').and_return(true)
end
end
end

View file

@ -26,6 +26,7 @@ describe 'ensure_resource' do
it do
# these first three should not fail
should run.with_params('User', 'dan', {})
should run.with_params('User', 'dan', '')
should run.with_params('User', 'dan', {'ensure' => 'present'})
should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false})
# test that this fails