diff options
-rw-r--r-- | lib/puppet/file_serving/terminus_helper.rb | 10 | ||||
-rwxr-xr-x | spec/unit/file_serving/terminus_helper.rb | 40 |
2 files changed, 29 insertions, 21 deletions
diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb index b51e27297..5b993c9e0 100644 --- a/lib/puppet/file_serving/terminus_helper.rb +++ b/lib/puppet/file_serving/terminus_helper.rb @@ -8,7 +8,7 @@ require 'puppet/file_serving/fileset' # Define some common methods for FileServing termini. module Puppet::FileServing::TerminusHelper # Create model instances for all files in a fileset. - def path2instances(request, path) + def path2instances(request, *paths) 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] @@ -19,8 +19,12 @@ module Puppet::FileServing::TerminusHelper 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) + filesets = paths.collect do |path| + Puppet::FileServing::Fileset.new(path, args) + end + + Puppet::FileServing::Fileset.merge(*filesets).collect do |file, base_path| + inst = model.new(base_path, :relative_path => file) inst.links = request.options[:links] if request.options[:links] inst.collect inst diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb index 7f08aeb7e..c79261eca 100755 --- a/spec/unit/file_serving/terminus_helper.rb +++ b/spec/unit/file_serving/terminus_helper.rb @@ -16,38 +16,48 @@ describe Puppet::FileServing::TerminusHelper do @helper.stubs(:model).returns(@model) @request = stub 'request', :key => "url", :options => {} + + @fileset = stub 'fileset', :files => [], :path => "/my/file" + Puppet::FileServing::Fileset.stubs(:new).with("/my/file", {}).returns(@fileset) end it "should use a fileset to find paths" do - fileset = mock 'fileset', :files => [] - Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset) + @fileset = stub 'fileset', :files => [], :path => "/my/files" + Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(@fileset) @helper.path2instances(@request, "/my/file") end + it "should support finding across multiple paths by merging the filesets" do + first = stub 'fileset', :files => [], :path => "/first/file" + Puppet::FileServing::Fileset.expects(:new).with { |path, options| path == "/first/file" }.returns(first) + second = stub 'fileset', :files => [], :path => "/second/file" + Puppet::FileServing::Fileset.expects(:new).with { |path, options| path == "/second/file" }.returns(second) + + Puppet::FileServing::Fileset.expects(:merge).with(first, second).returns({}) + + @helper.path2instances(@request, "/first/file", "/second/file") + end + it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do - fileset = mock 'fileset', :files => [] - Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset) + Puppet::FileServing::Fileset.expects(:new).with { |path, options| options == {: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 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) + Puppet::FileServing::Fileset.expects(:new).with { |path, options| options == {: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) + Puppet::FileServing::Fileset.expects(:new).with { |path, options| options[: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) + Puppet::FileServing::Fileset.expects(:new).with { |path, options| options[:recurse] == false }.returns(@fileset) @request.stubs(:options).returns(:recurse => "false") @helper.path2instances(@request, "/my/file") end @@ -59,14 +69,8 @@ describe Puppet::FileServing::TerminusHelper do @one = stub 'one', :links= => nil, :collect => nil @two = stub 'two', :links= => nil, :collect => nil - @fileset = mock 'fileset', :files => %w{one two} - Puppet::FileServing::Fileset.expects(:new).returns(@fileset) - end - - it "should create an instance of the model for each path returned by the fileset" do - @model.expects(:new).returns(@one) - @model.expects(:new).returns(@two) - @helper.path2instances(@request, "/my/file").length.should == 2 + @fileset = stub 'fileset', :files => %w{one two}, :path => "/my/file" + Puppet::FileServing::Fileset.stubs(:new).returns(@fileset) end it "should set each returned instance's path to the original path" do |