|
10 | 10 |
|
11 | 11 | describe JRuby::Rack::RailsBooter do |
12 | 12 |
|
13 | | - let(:booter) do |
14 | | - real_logger = org.jruby.rack.logging.BufferLogger.new |
15 | | - JRuby::Rack.logger = JRuby::Rack::Logger.new real_logger |
16 | | - JRuby::Rack::RailsBooter.new JRuby::Rack.context = @rack_context |
| 13 | + let(:real_logger) do |
| 14 | + org.jruby.rack.logging.BufferLogger.new |
17 | 15 | end |
18 | 16 |
|
19 | | - let(:rails_booter) do |
20 | | - rails_booter = booter; def rails_booter.rails2?; nil end; rails_booter |
| 17 | + let(:booter) do |
| 18 | + JRuby::Rack.logger = JRuby::Rack::Logger.new(real_logger) |
| 19 | + JRuby::Rack.context = @rack_context |
| 20 | + JRuby::Rack::RailsBooter.new @rack_context |
21 | 21 | end |
22 | 22 |
|
23 | 23 | after { JRuby::Rack.context = nil; JRuby::Rack.logger = nil } |
24 | 24 |
|
25 | 25 | it "should determine RAILS_ROOT from the 'rails.root' init parameter" do |
26 | 26 | @rack_context.should_receive(:getInitParameter).with("rails.root").and_return "/WEB-INF" |
27 | 27 | @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "./WEB-INF" |
28 | | - rails_booter.boot! |
29 | | - rails_booter.app_path.should == "./WEB-INF" |
| 28 | + booter.boot! |
| 29 | + booter.app_path.should == "./WEB-INF" |
30 | 30 | end |
31 | 31 |
|
32 | 32 | before do |
|
41 | 41 |
|
42 | 42 | it "should default rails path to /WEB-INF" do |
43 | 43 | @rack_context.should_receive(:getRealPath).with("/WEB-INF").and_return "/usr/apps/WEB-INF" |
44 | | - rails_booter.boot! |
45 | | - rails_booter.app_path.should == "/usr/apps/WEB-INF" |
| 44 | + booter.boot! |
| 45 | + booter.app_path.should == "/usr/apps/WEB-INF" |
46 | 46 | end |
47 | 47 |
|
48 | 48 | it "leaves ENV['RAILS_ENV'] as is if it was already set" do |
49 | 49 | ENV['RAILS_ENV'] = 'staging' |
50 | | - rails_booter.boot! |
| 50 | + booter.boot! |
51 | 51 | ENV['RAILS_ENV'].should == 'staging' |
52 | | - rails_booter.rails_env.should == "staging" |
| 52 | + booter.rails_env.should == "staging" |
53 | 53 | end |
54 | 54 |
|
55 | 55 | it "determines RAILS_ENV from the 'rails.env' init parameter" do |
56 | 56 | ENV['RAILS_ENV'] = nil |
57 | 57 | @rack_context.should_receive(:getInitParameter).with("rails.env").and_return "test" |
58 | | - rails_booter.boot! |
59 | | - rails_booter.rails_env.should == "test" |
| 58 | + booter.boot! |
| 59 | + booter.rails_env.should == "test" |
60 | 60 | end |
61 | 61 |
|
62 | 62 | it "gets rails environment from rack environmnent" do |
63 | 63 | ENV.delete('RAILS_ENV') |
64 | 64 | ENV['RACK_ENV'] = 'development' |
65 | 65 | @rack_context.stub(:getInitParameter) |
66 | | - rails_booter.boot! |
67 | | - rails_booter.rails_env.should == 'development' |
| 66 | + booter.boot! |
| 67 | + booter.rails_env.should == 'development' |
68 | 68 | end |
69 | 69 |
|
70 | 70 | it "default RAILS_ENV to 'production'" do |
71 | 71 | ENV.delete('RAILS_ENV'); ENV.delete('RACK_ENV') |
72 | | - rails_booter.boot! |
73 | | - rails_booter.rails_env.should == "production" |
| 72 | + booter.boot! |
| 73 | + booter.rails_env.should == "production" |
74 | 74 | end |
75 | 75 |
|
76 | 76 | it "should set RAILS_RELATIVE_URL_ROOT based on the servlet context path" do |
77 | 77 | @rack_context.should_receive(:getContextPath).and_return '/myapp' |
78 | | - rails_booter.boot! |
| 78 | + booter.boot! |
79 | 79 | ENV['RAILS_RELATIVE_URL_ROOT'].should == '/myapp' |
80 | 80 | end |
81 | 81 |
|
82 | 82 | it "should append to RAILS_RELATIVE_URL_ROOT if 'rails.relative_url_append' is set" do |
83 | 83 | @rack_context.should_receive(:getContextPath).and_return '/myapp' |
84 | 84 | @rack_context.should_receive(:getInitParameter).with("rails.relative_url_append").and_return "/blah" |
85 | | - rails_booter.boot! |
| 85 | + booter.boot! |
86 | 86 | ENV['RAILS_RELATIVE_URL_ROOT'].should == '/myapp/blah' |
87 | 87 | end |
88 | 88 |
|
89 | 89 | it "should determine the public html root from the 'public.root' init parameter" do |
90 | 90 | @rack_context.should_receive(:getInitParameter).with("public.root").and_return "/blah" |
91 | 91 | @rack_context.should_receive(:getRealPath).with("/blah").and_return "." |
92 | | - rails_booter.boot! |
93 | | - rails_booter.public_path.should == "." |
| 92 | + booter.boot! |
| 93 | + booter.public_path.should == "." |
94 | 94 | end |
95 | 95 |
|
96 | 96 | it "should default public root to '/'" do |
97 | 97 | @rack_context.should_receive(:getRealPath).with("/").and_return "." |
98 | | - rails_booter.boot! |
99 | | - rails_booter.public_path.should == "." |
| 98 | + booter.boot! |
| 99 | + booter.public_path.should == "." |
100 | 100 | end |
101 | 101 |
|
102 | 102 | RAILS_ROOT_DIR = File.expand_path("../../../rails", __FILE__) |
@@ -211,6 +211,7 @@ def logger=(logger); @logger = logger; end |
211 | 211 | expect(rails_logger).to be_a(ActiveSupport::TaggedLogging) |
212 | 212 | if defined? ActiveSupport::LoggerSilence |
213 | 213 | expect(rails_logger).to be_a(ActiveSupport::LoggerSilence) |
| 214 | + expect(rails_logger.silencer).to be true |
214 | 215 | # sanity check silence works: |
215 | 216 | value_returned = rails_logger.silence(Logger::WARN) { |logger| logger.class.name } |
216 | 217 | expect(value_returned).to eql('JRuby::Rack::Logger') |
|
0 commit comments