Skip to content

Commit

Permalink
allow to boot when RAILS_ROOT/public directory does not exist (closes j…
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jan 21, 2016
1 parent 4281a98 commit d81684b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/ruby/jruby/rack/app_layout.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#--
# Copyright (c) 2012-2016 Karol Bucek, LTD.
# Copyright (c) 2010-2012 Engine Yard, Inc.
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
# This source code is available under the MIT license.
Expand Down
16 changes: 8 additions & 8 deletions src/main/ruby/jruby/rack/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#--
# Copyright (c) 2012-2016 Karol Bucek, LTD.
# Copyright (c) 2010-2012 Engine Yard, Inc.
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
# This source code is available under the MIT license.
Expand All @@ -11,26 +12,25 @@
module JRuby::Rack
class Railtie < ::Rails::Railtie

# settings Rails.public_path in an initializer seems "too" late @see #99
config.before_configuration do |app|
paths, public = app.config.paths, Pathname.new(JRuby::Rack.public_path)
paths = app.config.paths; public = JRuby::Rack.public_path
if paths.respond_to?(:'[]') && paths.respond_to?(:keys)
# Rails 3.1/3.2/4.0: paths["app/controllers"] style
# Rails 3.1/3.2/4.x: paths["app/controllers"] style
old_public = Pathname.new(paths['public'].to_a.first)
javascripts = Pathname.new(paths['public/javascripts'].to_a.first)
stylesheets = Pathname.new(paths['public/stylesheets'].to_a.first)
paths['public'] = public.to_s
paths['public'] = public.to_s; public = Pathname.new(public)
paths['public/javascripts'] = public.join(javascripts.relative_path_from(old_public)).to_s
paths['public/stylesheets'] = public.join(stylesheets.relative_path_from(old_public)).to_s
else
# Rails 3.0: old paths.app.controllers style
old_public = Pathname.new(paths.public.to_a.first)
javascripts = Pathname.new(paths.public.javascripts.to_a.first)
stylesheets = Pathname.new(paths.public.stylesheets.to_a.first)
paths.public = public.to_s
paths.public = public.to_s; public = Pathname.new(public)
paths.public.javascripts = public.join(javascripts.relative_path_from(old_public)).to_s
paths.public.stylesheets = public.join(stylesheets.relative_path_from(old_public)).to_s
end
end if public # nil if /public does not exist
end

# TODO prefix initializers with 'jruby_rack.' !?
Expand Down Expand Up @@ -64,8 +64,8 @@ class Railtie < ::Rails::Railtie
# - when a *config.relative_url_root* is set we should not interfere ...
if ( env_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] ) &&
!( app.config.respond_to?(:relative_url_root) && app.config.relative_url_root )
if ( config = app.config ).action_controller
config.action_controller.relative_url_root = env_url_root
if action_controller = app.config.action_controller
action_controller.relative_url_root = env_url_root
elsif defined?(ActionController::Base) &&
ActionController::Base.respond_to?(:relative_url_root=)
# setting the config affects *ActionController::Base.relative_url_root*
Expand Down
16 changes: 16 additions & 0 deletions src/spec/ruby/jruby/rack/rails_booter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@
paths['public/stylesheets'].should == public_path.join("stylesheets").to_s
end

it "works when JRuby::Rack.public_path is nil (public does not exist)" do
paths = %w( public public/javascripts public/stylesheets ).inject({}) do
|hash, path| hash[ path ] = [ path.sub('public', 'NO-SUCH-DiR') ]; hash
end
app = double("app"); app.stub_chain(:config, :paths).and_return(paths)
JRuby::Rack.public_path = nil

before_config = Rails::Railtie.config.__before_configuration.first
before_config.should_not be nil
before_config.call(app)

paths['public'].should == [ public_path = "NO-SUCH-DiR" ]
paths['public/javascripts'].should == [ File.join(public_path, "javascripts") ]
paths['public/stylesheets'].should ==[ File.join(public_path, "stylesheets") ]
end

it "should not set the PUBLIC_ROOT constant" do
lambda { PUBLIC_ROOT }.should raise_error
end
Expand Down

0 comments on commit d81684b

Please sign in to comment.