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:
parent
a0cb8cdee4
commit
4f8b133917
3 changed files with 5 additions and 1 deletions
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue