8585
8686 shared_examples_for 'a rails app' , :shared => true do
8787
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
8991
9092 it "initializes pooling when min/max set" do
9193 servlet_context . addInitParameter ( 'jruby.min.runtimes' , '1' )
127129 rack_factory . should be_a ( RackApplicationFactory )
128130 rack_factory . should be_a ( SharedRackApplicationFactory )
129131 rack_factory . realFactory . should be_a ( RailsRackApplicationFactory )
132+ end
130133
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 )
132142 end
133143
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
134192 end
135193
136194 def expect_to_have_monkey_patched_chunked
@@ -146,8 +204,6 @@ def expect_to_have_monkey_patched_chunked
146204 should_eval_as_eql_to script , "1\n second"
147205 end
148206
149- ENV_COPY = ENV . to_h
150-
151207 def initialize_rails ( env = nil , servlet_context = @servlet_context )
152208 if ! servlet_context || servlet_context . is_a? ( String )
153209 base = servlet_context . is_a? ( String ) ? servlet_context : nil
@@ -160,19 +216,23 @@ def initialize_rails(env = nil, servlet_context = @servlet_context)
160216 servlet_context . addInitParameter ( "jruby.runtime.env" , the_env )
161217
162218 yield ( servlet_context , listener ) if block_given?
219+
163220 listener . contextInitialized javax . servlet . ServletContextEvent . new ( servlet_context )
164221 @rack_context = servlet_context . getAttribute ( "rack.context" )
165222 @rack_factory = servlet_context . getAttribute ( "rack.factory" )
166- @servlet_context || = servlet_context
223+ @servlet_context = servlet_context
167224 end
168225
169226 def new_servlet_context ( base_path = nil )
170227 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 ) }
172229 servlet_context
173230 end
174231
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
176236
177237 GEMFILES_DIR = File . expand_path ( '../../../gemfiles' , STUB_DIR )
178238
@@ -181,4 +241,11 @@ def copy_gemfile(name) # e.g. 'rails30'
181241 FileUtils . cp File . join ( GEMFILES_DIR , "#{ name } .gemfile.lock" ) , File . join ( STUB_DIR , "#{ name } /WEB-INF/Gemfile.lock" )
182242 end
183243
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+
184251end
0 commit comments