85
85
86
86
shared_examples_for 'a rails app' , :shared => true do
87
87
88
- let ( :servlet_context ) { new_servlet_context ( base_path ) }
88
+ let ( :servlet_context ) do
89
+ new_servlet_context ( base_path ) . tap { |servlet_context | prepare_servlet_context ( servlet_context ) }
90
+ end
89
91
90
92
it "initializes pooling when min/max set" do
91
93
servlet_context . addInitParameter ( 'jruby.min.runtimes' , '1' )
127
129
rack_factory . should be_a ( RackApplicationFactory )
128
130
rack_factory . should be_a ( SharedRackApplicationFactory )
129
131
rack_factory . realFactory . should be_a ( RailsRackApplicationFactory )
132
+ end
130
133
131
- rack_factory . getApplication . should be_a ( DefaultRackApplication )
134
+ end
135
+
136
+ describe 'rails 7.2' , lib : :rails72 do
137
+
138
+ before ( :all ) do name = :rails72 # copy_gemfile :
139
+ FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile" ) , File . join ( STUB_DIR , "#{ name } /Gemfile" )
140
+ FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile.lock" ) , File . join ( STUB_DIR , "#{ name } /Gemfile.lock" )
141
+ Dir . chdir File . join ( STUB_DIR , name . to_s )
132
142
end
133
143
144
+ def base_path ; "#{ STUB_DIR } /rails72" end
145
+
146
+ it_should_behave_like 'a rails app'
147
+
148
+ context "initialized" do
149
+
150
+ before ( :all ) do
151
+ initialize_rails ( 'production' , "file://#{ base_path } " ) do |servlet_context , _ |
152
+ prepare_servlet_context ( servlet_context )
153
+ end
154
+ end
155
+ after ( :all ) { restore_rails }
156
+
157
+ it "loaded rack ~> 2.2" do
158
+ @runtime = @rack_factory . getApplication . getRuntime
159
+ should_eval_as_not_nil "defined?(Rack.release)"
160
+ should_eval_as_eql_to "Rack.release.to_s[0, 3]" , '2.2'
161
+ end
162
+
163
+ it "booted with a servlet logger" do
164
+ @runtime = @rack_factory . getApplication . getRuntime
165
+ should_eval_as_not_nil "defined?(Rails)"
166
+ should_eval_as_not_nil "Rails.logger"
167
+
168
+ # Rails 7.x wraps the default in a ActiveSupport::BroadcastLogger
169
+ should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::BroadcastLogger" , true
170
+ should_eval_as_eql_to "Rails.logger.broadcasts.size" , 1
171
+ should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? JRuby::Rack::Logger" , true
172
+ # NOTE: TaggedLogging is a module that extends the logger instance:
173
+ should_eval_as_eql_to "Rails.logger.broadcasts.first.is_a? ActiveSupport::TaggedLogging" , true
174
+
175
+ # production.rb: config.log_level = 'info'
176
+ should_eval_as_eql_to "Rails.logger.level" , Logger ::INFO
177
+ should_eval_as_eql_to "Rails.logger.broadcasts.first.level" , Logger ::INFO
178
+
179
+ unwrap_logger = "logger = Rails.logger.broadcasts.first;"
180
+ # sanity check logger-silence works:
181
+ should_eval_as_eql_to "#{ unwrap_logger } logger.silence { logger.warn('from-integration-spec') }" , true
182
+
183
+ should_eval_as_eql_to "#{ unwrap_logger } logger.real_logger.is_a?(org.jruby.rack.logging.ServletContextLogger)" , true
184
+ end
185
+
186
+ it "sets up public_path" do
187
+ @runtime = @rack_factory . getApplication . getRuntime
188
+ should_eval_as_eql_to "Rails.public_path.to_s" , "#{ base_path } /public"
189
+ end
190
+
191
+ end
134
192
end
135
193
136
194
def expect_to_have_monkey_patched_chunked
@@ -146,8 +204,6 @@ def expect_to_have_monkey_patched_chunked
146
204
should_eval_as_eql_to script , "1\n second"
147
205
end
148
206
149
- ENV_COPY = ENV . to_h
150
-
151
207
def initialize_rails ( env = nil , servlet_context = @servlet_context )
152
208
if ! servlet_context || servlet_context . is_a? ( String )
153
209
base = servlet_context . is_a? ( String ) ? servlet_context : nil
@@ -160,19 +216,23 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
160
216
servlet_context . addInitParameter ( "jruby.runtime.env" , the_env )
161
217
162
218
yield ( servlet_context , listener ) if block_given?
219
+
163
220
listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
164
221
@rack_context = servlet_context . getAttribute ( "rack.context" )
165
222
@rack_factory = servlet_context . getAttribute ( "rack.factory" )
166
- @servlet_context || = servlet_context
223
+ @servlet_context = servlet_context
167
224
end
168
225
169
226
def new_servlet_context ( base_path = nil )
170
227
servlet_context = org . jruby . rack . mock . RackLoggingMockServletContext . new base_path
171
- servlet_context . logger = raise_logger
228
+ servlet_context . logger = raise_logger ( :WARN ) . tap { | logger | logger . setEnabled ( false ) }
172
229
servlet_context
173
230
end
174
231
175
- private
232
+ def prepare_servlet_context ( servlet_context )
233
+ servlet_context . addInitParameter ( 'rails.root' , base_path )
234
+ servlet_context . addInitParameter ( 'jruby.rack.layout_class' , 'FileSystemLayout' )
235
+ end
176
236
177
237
GEMFILES_DIR = File . expand_path ( '../../../gemfiles' , STUB_DIR )
178
238
@@ -181,4 +241,11 @@ def copy_gemfile(name) # e.g. 'rails30'
181
241
FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile.lock" ) , File . join ( STUB_DIR , "#{ name } /WEB-INF/Gemfile.lock" )
182
242
end
183
243
244
+ ENV_COPY = ENV . to_h
245
+
246
+ def restore_rails
247
+ ENV [ 'RACK_ENV' ] = ENV_COPY [ 'RACK_ENV' ] if ENV . key? ( 'RACK_ENV' )
248
+ ENV [ 'RAILS_ENV' ] = ENV_COPY [ 'RAILS_ENV' ] if ENV . key? ( 'RAILS_ENV' )
249
+ end
250
+
184
251
end
0 commit comments