diff options
-rw-r--r-- | lib/puppet/file_serving/terminus_helper.rb | 11 | ||||
-rwxr-xr-x | spec/unit/file_serving/terminus_helper.rb | 21 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb index 598a5007a..b51e27297 100644 --- a/lib/puppet/file_serving/terminus_helper.rb +++ b/lib/puppet/file_serving/terminus_helper.rb @@ -9,7 +9,16 @@ require 'puppet/file_serving/fileset' module Puppet::FileServing::TerminusHelper # Create model instances for all files in a fileset. def path2instances(request, path) - args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = request.options[param] if request.options[param]; hash } + args = [:links, :ignore, :recurse].inject({}) do |hash, param| + if request.options.include?(param) # use 'include?' so the values can be false + hash[param] = request.options[param] + elsif request.options.include?(param.to_s) + hash[param] = request.options[param.to_s] + end + hash[param] = true if hash[param] == "true" + hash[param] = false if hash[param] == "false" + hash + end Puppet::FileServing::Fileset.new(path, args).files.collect do |file| inst = model.new(path, :relative_path => file) inst.links = request.options[:links] if request.options[:links] diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb index e504a51be..7f08aeb7e 100755 --- a/spec/unit/file_serving/terminus_helper.rb +++ b/spec/unit/file_serving/terminus_helper.rb @@ -31,6 +31,27 @@ describe Puppet::FileServing::TerminusHelper do @helper.path2instances(@request, "/my/file") end + it "should pass :recurse, :ignore, and :links settings on to the fileset if present with the keys stored as strings" do + fileset = mock 'fileset', :files => [] + Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset) + @request.stubs(:options).returns("links" => :a, "ignore" => :b, "recurse" => :c) + @helper.path2instances(@request, "/my/file") + end + + it "should convert the string 'true' to the boolean true when setting options" do + fileset = mock 'fileset', :files => [] + Puppet::FileServing::Fileset.expects(:new).with("/my/file", :recurse => true).returns(fileset) + @request.stubs(:options).returns(:recurse => "true") + @helper.path2instances(@request, "/my/file") + end + + it "should convert the string 'false' to the boolean false when setting options" do + fileset = mock 'fileset', :files => [] + Puppet::FileServing::Fileset.expects(:new).with("/my/file", :recurse => false).returns(fileset) + @request.stubs(:options).returns(:recurse => "false") + @helper.path2instances(@request, "/my/file") + end + describe "when creating instances" do before do @request.stubs(:key).returns "puppet://host/mount/dir" |