|
1 | 1 |
|
2 | 2 | require File.expand_path('spec_helper', File.dirname(__FILE__) + '/../..') |
3 | | -require 'fileutils' |
4 | | -require 'jruby' |
5 | 3 |
|
6 | 4 | java_import org.jruby.rack.RackContext |
7 | 5 | java_import org.jruby.rack.servlet.ServletRackContext |
|
15 | 13 |
|
16 | 14 | describe "integration" do |
17 | 15 |
|
| 16 | + before(:all) { require 'fileutils' } |
| 17 | + |
18 | 18 | #after(:all) { JRuby::Rack.context = nil } |
19 | 19 |
|
20 | 20 | describe 'rack (lambda)' do |
|
90 | 90 |
|
91 | 91 | shared_examples_for 'a rails app', :shared => true do |
92 | 92 |
|
93 | | - let(:servlet_context) do |
94 | | - servlet_context = org.jruby.rack.mock.MockServletContext.new base_path |
95 | | - servlet_context.logger = raise_logger |
96 | | - set_compat_version servlet_context |
97 | | - servlet_context |
98 | | - end |
| 93 | + let(:servlet_context) { new_servlet_context(base_path) } |
99 | 94 |
|
100 | 95 | it "initializes (pooling by default)" do |
101 | 96 | listener = org.jruby.rack.rails.RailsServletContextListener.new |
|
318 | 313 |
|
319 | 314 | end |
320 | 315 |
|
| 316 | + describe 'rails 4.1', :lib => :rails41 do |
| 317 | + |
| 318 | + before(:all) do name = :rails41 # copy_gemfile : |
| 319 | + FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile"), File.join(STUB_DIR, "#{name}/Gemfile") |
| 320 | + FileUtils.cp File.join(GEMFILES_DIR, "#{name}.gemfile.lock"), File.join(STUB_DIR, "#{name}/Gemfile.lock") |
| 321 | + Dir.chdir File.join(STUB_DIR, name.to_s) |
| 322 | + end |
| 323 | + |
| 324 | + def prepare_servlet_context(servlet_context) |
| 325 | + servlet_context.addInitParameter('rails.root', "#{STUB_DIR}/rails41") |
| 326 | + servlet_context.addInitParameter('jruby.rack.layout_class', 'FileSystemLayout') |
| 327 | + end |
| 328 | + |
| 329 | + def base_path; "file://#{STUB_DIR}/rails41" end |
| 330 | + # let(:base_path) { "file://#{STUB_DIR}/rails41" } |
| 331 | + |
| 332 | + it_should_behave_like 'a rails app' |
| 333 | + |
| 334 | + context "initialized" do |
| 335 | + |
| 336 | + before(:all) { initialize_rails 'production', base_path } |
| 337 | + after(:all) { restore_rails } |
| 338 | + |
| 339 | + it "loaded rack ~> 1.5" do |
| 340 | + @runtime = @rack_factory.getApplication.getRuntime |
| 341 | + should_eval_as_not_nil "defined?(Rack.release)" |
| 342 | + should_eval_as_eql_to "Rack.release.to_s[0, 3]", '1.5' |
| 343 | + end |
| 344 | + |
| 345 | + it "booted with a servlet logger" do |
| 346 | + @runtime = @rack_factory.getApplication.getRuntime |
| 347 | + should_eval_as_not_nil "defined?(Rails)" |
| 348 | + should_eval_as_not_nil "Rails.logger" |
| 349 | + # NOTE: TaggedLogging is a module that extends the instance now : |
| 350 | + should_eval_as_eql_to "Rails.logger.is_a? ActiveSupport::TaggedLogging", true |
| 351 | + should_eval_as_eql_to "Rails.logger.instance_variable_get(:'@logdev').dev.class.name", |
| 352 | + 'JRuby::Rack::ServletLog' |
| 353 | + should_eval_as_eql_to "Rails.logger.level", Logger::INFO |
| 354 | + end |
| 355 | + |
| 356 | + it "sets up public_path (as for a war)" do |
| 357 | + @runtime = @rack_factory.getApplication.getRuntime |
| 358 | + should_eval_as_eql_to "Rails.public_path.to_s", "#{STUB_DIR}/rails41/public" |
| 359 | + end |
| 360 | + |
| 361 | + end |
| 362 | + |
| 363 | + end |
| 364 | + |
321 | 365 | describe 'rails 2.3', :lib => :rails23 do |
322 | 366 |
|
323 | 367 | before(:all) do |
@@ -411,11 +455,15 @@ def restore_rails |
411 | 455 | def new_servlet_context(base_path = nil) |
412 | 456 | servlet_context = org.jruby.rack.mock.MockServletContext.new base_path |
413 | 457 | servlet_context.logger = raise_logger |
414 | | - set_compat_version servlet_context |
| 458 | + prepare_servlet_context servlet_context |
415 | 459 | servlet_context |
416 | 460 | end |
417 | 461 |
|
418 | | - def set_compat_version(servlet_context = @servlet_context) |
| 462 | + def prepare_servlet_context(servlet_context) |
| 463 | + set_compat_version servlet_context |
| 464 | + end |
| 465 | + |
| 466 | + def set_compat_version(servlet_context = @servlet_context); require 'jruby' |
419 | 467 | compat_version = JRuby.runtime.getInstanceConfig.getCompatVersion # RUBY1_9 |
420 | 468 | servlet_context.addInitParameter("jruby.compat.version", compat_version.to_s) |
421 | 469 | end |
|
0 commit comments