|
29 | 29 | it "defaults gem uri to /WEB-INF/gems" do |
30 | 30 | expect( layout.gem_uri ).to eq '/WEB-INF/gems' |
31 | 31 |
|
32 | | - layout.stub(:app_uri).and_return '/WEB-INF' |
| 32 | + @rack_context.should_receive(:getRealPath).with("/WEB-INF/gems").and_return "/gems" |
| 33 | + |
33 | 34 | expect( layout.gem_path ).to eq '/gems' |
34 | 35 | end |
35 | 36 |
|
36 | 37 | it "sets gem path based on gem.path context init param" do |
37 | 38 | @rack_context.should_receive(:getInitParameter).with("gem.path").and_return "/WEB-INF/.gems" |
38 | 39 | expect( layout.gem_uri ).to eq "/WEB-INF/.gems" |
39 | 40 |
|
40 | | - layout.instance_variable_set :@app_uri, "/WEB-INF" |
41 | | - expect( layout.gem_path ).to eq "/.gems" |
| 41 | + @rack_context.should_receive(:getRealPath).with("/WEB-INF/.gems").and_return "file:/tmp/WEB-INF/.gems" |
| 42 | + |
| 43 | + expect( layout.gem_path ).to eq "file:/tmp/WEB-INF/.gems" |
42 | 44 | end |
43 | 45 |
|
44 | 46 | it "handles gem path correctly when app uri ends with /" do |
| 47 | + layout.instance_variable_set :@app_uri, "/WEB-INF/" |
45 | 48 | layout.instance_variable_set :@gem_uri, "/WEB-INF/.gems" |
46 | | - expect( layout.gem_path ).to eq "/.gems" |
| 49 | + |
| 50 | + @rack_context.should_receive(:getRealPath).with("/WEB-INF/.gems").and_return ".gems" |
| 51 | + |
| 52 | + expect( layout.gem_path ).to eq ".gems" |
47 | 53 | end |
48 | 54 |
|
49 | 55 | it "handles gem path correctly when app uri not relative" do |
|
63 | 69 |
|
64 | 70 | shared_examples "FileSystemLayout" do |
65 | 71 |
|
66 | | - it "sets app and public uri defaults based on a typical Rails app" do |
| 72 | + it "sets app and public uri defaults based on a typical (Rails/Rack) app" do |
67 | 73 | expect( layout.app_uri ).to eq '.' |
68 | | - expect( layout.public_uri ).to eq './public' |
| 74 | + expect( layout.public_uri ).to eq 'public' |
69 | 75 |
|
70 | 76 | expect( layout.app_path ).to eq Dir.pwd |
71 | 77 | expect( layout.public_path ).to eq "#{Dir.pwd}/public" |
72 | 78 | end |
73 | 79 |
|
74 | 80 | it "sets public uri using context param" do |
| 81 | + @rack_context.should_receive(:getRealPath).with("static").and_return File.expand_path("static") |
75 | 82 | @rack_context.should_receive(:getInitParameter).with("public.root").and_return "static" |
76 | 83 | expect( layout.public_uri ).to eq 'static' |
77 | 84 | expect( layout.public_path ).to eq "#{Dir.pwd}/static" |
|
84 | 91 | end |
85 | 92 |
|
86 | 93 | it "sets gem path based on gem.home context init param" do |
| 94 | + @rack_context.should_receive(:getRealPath).with("gem/home").and_return File.expand_path("gem/home") |
87 | 95 | @rack_context.should_receive(:getInitParameter).with("gem.home").and_return "gem/home" |
88 | 96 | expect( layout.gem_uri ).to eq "gem/home" |
89 | 97 | expect( layout.gem_path ).to eq File.expand_path("gem/home") |
|
96 | 104 | expect( layout.gem_path ).to be nil |
97 | 105 | end |
98 | 106 |
|
| 107 | + it "expands public path relative to application root" do |
| 108 | + layout.instance_variable_set :@app_uri, '/opt/deploys/main' |
| 109 | + expect( layout.public_path ).to eq "/opt/deploys/main/public" |
| 110 | + end |
| 111 | + |
| 112 | + it "expands public path relative to application root (unless absolute)" do |
| 113 | + @rack_context.should_receive(:getInitParameter).with("public.root").and_return "/home/public/root" |
| 114 | + expect( layout.public_path ).to eq "/home/public/root" |
| 115 | + end |
| 116 | + |
99 | 117 | end |
100 | 118 |
|
101 | 119 | describe JRuby::Rack::FileSystemLayout do |
102 | 120 |
|
103 | | - let(:layout) { JRuby::Rack::FileSystemLayout.new(@rack_context) } |
| 121 | + let(:layout) do |
| 122 | + @rack_context.stub(:getRealPath) { |path| path } |
| 123 | + JRuby::Rack::FileSystemLayout.new(@rack_context) |
| 124 | + end |
104 | 125 |
|
105 | 126 | it_behaves_like "FileSystemLayout" |
106 | 127 |
|
|
113 | 134 | describe "deprecated-constant" do |
114 | 135 |
|
115 | 136 | it "still works" do |
116 | | - expect(lambda { |
117 | | - expect(JRuby::Rack::RailsFilesystemLayout).to be JRuby::Rack::FileSystemLayout |
118 | | - }).to_not raise_error |
| 137 | + expect(JRuby::Rack::RailsFilesystemLayout).to be JRuby::Rack::FileSystemLayout |
119 | 138 | end |
120 | 139 |
|
121 | 140 | end |
|
124 | 143 |
|
125 | 144 | describe JRuby::Rack::RailsFileSystemLayout do |
126 | 145 |
|
127 | | - let(:layout) { JRuby::Rack::RailsFileSystemLayout.new(@rack_context) } |
| 146 | + let(:layout) do |
| 147 | + @rack_context.stub(:getRealPath) { |path| path } |
| 148 | + JRuby::Rack::RailsFileSystemLayout.new(@rack_context) |
| 149 | + end |
128 | 150 |
|
129 | 151 | it_behaves_like "FileSystemLayout" |
130 | 152 |
|
|
134 | 156 | expect( layout.app_path ).to eq File.expand_path("../rails", Dir.pwd) |
135 | 157 | end |
136 | 158 |
|
137 | | -end |
| 159 | +end if defined? JRuby::Rack::RailsFileSystemLayout |
0 commit comments