1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/usr/bin/env ruby
#
# Created by Luke Kanies on 2007-10-22.
# Copyright (c) 2007. All rights reserved.
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/terminus_helper'
describe Puppet::FileServing::TerminusHelper do
before do
@helper = Object.new
@helper.extend(Puppet::FileServing::TerminusHelper)
@model = mock 'model'
@helper.stubs(:model).returns(@model)
end
it "should use a fileset to find paths" do
fileset = mock 'fileset', :files => []
Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset)
@helper.path2instances("url", "/my/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)
@helper.path2instances("url", "/my/file", :links => :a, :ignore => :b, :recurse => :c)
end
end
describe Puppet::FileServing::TerminusHelper, " when creating instances" do
before do
@helper = Object.new
@helper.extend(Puppet::FileServing::TerminusHelper)
@model = mock 'model'
@helper.stubs(:model).returns(@model)
@key = "puppet://host/mount/dir"
@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(@key, "/my/file").length.should == 2
end
it "should set each instance's key to be the original key plus the file-specific path" do
@model.expects(:new).with { |key, options| key == @key + "/one" }.returns(:one)
@model.expects(:new).with { |key, options| key == @key + "/two" }.returns(:two)
@helper.path2instances(@key, "/my/file")
end
it "should set each returned instance's path to the original path" do
@model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:one)
@model.expects(:new).with { |key, options| options[:path] == "/my/file" }.returns(:two)
@helper.path2instances(@key, "/my/file")
end
it "should set each returned instance's relative path to the file-specific path" do
@model.expects(:new).with { |key, options| options[:relative_path] == "one" }.returns(:one)
@model.expects(:new).with { |key, options| options[:relative_path] == "two" }.returns(:two)
@helper.path2instances(@key, "/my/file")
end
it "should set the links value on each instance if one is provided" do
one = mock 'one', :links= => :manage
two = mock 'two', :links= => :manage
@model.expects(:new).returns(one)
@model.expects(:new).returns(two)
@helper.path2instances(@key, "/my/file", :links => :manage)
end
end
|