Skip to content

Commit d81684b

Browse files
committed
allow to boot when RAILS_ROOT/public directory does not exist (closes #197)
1 parent 4281a98 commit d81684b

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/main/ruby/jruby/rack/app_layout.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#--
2+
# Copyright (c) 2012-2016 Karol Bucek, LTD.
23
# Copyright (c) 2010-2012 Engine Yard, Inc.
34
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
45
# This source code is available under the MIT license.

src/main/ruby/jruby/rack/rails/railtie.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#--
2+
# Copyright (c) 2012-2016 Karol Bucek, LTD.
23
# Copyright (c) 2010-2012 Engine Yard, Inc.
34
# Copyright (c) 2007-2009 Sun Microsystems, Inc.
45
# This source code is available under the MIT license.
@@ -11,26 +12,25 @@
1112
module JRuby::Rack
1213
class Railtie < ::Rails::Railtie
1314

14-
# settings Rails.public_path in an initializer seems "too" late @see #99
1515
config.before_configuration do |app|
16-
paths, public = app.config.paths, Pathname.new(JRuby::Rack.public_path)
16+
paths = app.config.paths; public = JRuby::Rack.public_path
1717
if paths.respond_to?(:'[]') && paths.respond_to?(:keys)
18-
# Rails 3.1/3.2/4.0: paths["app/controllers"] style
18+
# Rails 3.1/3.2/4.x: paths["app/controllers"] style
1919
old_public = Pathname.new(paths['public'].to_a.first)
2020
javascripts = Pathname.new(paths['public/javascripts'].to_a.first)
2121
stylesheets = Pathname.new(paths['public/stylesheets'].to_a.first)
22-
paths['public'] = public.to_s
22+
paths['public'] = public.to_s; public = Pathname.new(public)
2323
paths['public/javascripts'] = public.join(javascripts.relative_path_from(old_public)).to_s
2424
paths['public/stylesheets'] = public.join(stylesheets.relative_path_from(old_public)).to_s
2525
else
2626
# Rails 3.0: old paths.app.controllers style
2727
old_public = Pathname.new(paths.public.to_a.first)
2828
javascripts = Pathname.new(paths.public.javascripts.to_a.first)
2929
stylesheets = Pathname.new(paths.public.stylesheets.to_a.first)
30-
paths.public = public.to_s
30+
paths.public = public.to_s; public = Pathname.new(public)
3131
paths.public.javascripts = public.join(javascripts.relative_path_from(old_public)).to_s
3232
paths.public.stylesheets = public.join(stylesheets.relative_path_from(old_public)).to_s
33-
end
33+
end if public # nil if /public does not exist
3434
end
3535

3636
# TODO prefix initializers with 'jruby_rack.' !?
@@ -64,8 +64,8 @@ class Railtie < ::Rails::Railtie
6464
# - when a *config.relative_url_root* is set we should not interfere ...
6565
if ( env_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] ) &&
6666
!( app.config.respond_to?(:relative_url_root) && app.config.relative_url_root )
67-
if ( config = app.config ).action_controller
68-
config.action_controller.relative_url_root = env_url_root
67+
if action_controller = app.config.action_controller
68+
action_controller.relative_url_root = env_url_root
6969
elsif defined?(ActionController::Base) &&
7070
ActionController::Base.respond_to?(:relative_url_root=)
7171
# setting the config affects *ActionController::Base.relative_url_root*

src/spec/ruby/jruby/rack/rails_booter_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@
262262
paths['public/stylesheets'].should == public_path.join("stylesheets").to_s
263263
end
264264

265+
it "works when JRuby::Rack.public_path is nil (public does not exist)" do
266+
paths = %w( public public/javascripts public/stylesheets ).inject({}) do
267+
|hash, path| hash[ path ] = [ path.sub('public', 'NO-SUCH-DiR') ]; hash
268+
end
269+
app = double("app"); app.stub_chain(:config, :paths).and_return(paths)
270+
JRuby::Rack.public_path = nil
271+
272+
before_config = Rails::Railtie.config.__before_configuration.first
273+
before_config.should_not be nil
274+
before_config.call(app)
275+
276+
paths['public'].should == [ public_path = "NO-SUCH-DiR" ]
277+
paths['public/javascripts'].should == [ File.join(public_path, "javascripts") ]
278+
paths['public/stylesheets'].should ==[ File.join(public_path, "stylesheets") ]
279+
end
280+
265281
it "should not set the PUBLIC_ROOT constant" do
266282
lambda { PUBLIC_ROOT }.should raise_error
267283
end

0 commit comments

Comments
 (0)