aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/engine.rb11
-rw-r--r--railties/lib/rails/engine/configuration.rb5
-rw-r--r--railties/lib/rails/railtie/configuration.rb2
-rw-r--r--railties/test/railties/engine_test.rb26
5 files changed, 41 insertions, 5 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index a20208f8d5..14669f47b7 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -11,7 +11,7 @@ module Rails
:encoding, :consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger,
:preload_frameworks, :reload_plugins,
- :secret_token, :serve_static_assets, :session_options,
+ :secret_token, :session_options,
:time_zone, :whiny_nils
def initialize(*)
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index c0607950b5..409502cb08 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -152,13 +152,22 @@ module Rails
end
def app
- @app ||= config.middleware.build(endpoint)
+ @app ||= begin
+ config.middleware = config.middleware.merge_into(default_middleware_stack)
+ config.middleware.build(endpoint)
+ end
end
def endpoint
self.class.endpoint || routes
end
+ def default_middleware_stack
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
+ middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets
+ end
+ end
+
def call(env)
app.call(env)
end
diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb
index 0c91796fc9..b1adbe1f22 100644
--- a/railties/lib/rails/engine/configuration.rb
+++ b/railties/lib/rails/engine/configuration.rb
@@ -5,12 +5,13 @@ module Rails
class Configuration < ::Rails::Railtie::Configuration
attr_reader :root
attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths
- attr_accessor :middleware, :plugins
+ attr_accessor :middleware, :plugins, :serve_static_assets
def initialize(root=nil)
super()
@root = root
- @middleware = ActionDispatch::MiddlewareStack.new
+ @serve_static_assets = true
+ @middleware = Rails::Configuration::MiddlewareStackProxy.new
end
def paths
diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb
index 4e6f94c534..96d9bd0da2 100644
--- a/railties/lib/rails/railtie/configuration.rb
+++ b/railties/lib/rails/railtie/configuration.rb
@@ -78,4 +78,4 @@ module Rails
end
end
end
-end \ No newline at end of file
+end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index a2d46f02e7..b2e7be9749 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -127,5 +127,31 @@ module RailtiesTest
assert Bukkits::Engine.config.yaffle_loaded
end
+
+ test "engine can serve files" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ class Bukkits
+ class Engine < ::Rails::Engine
+ paths.public = "#{File.join(@plugin.path, "lib/bukkits/public")}"
+ config.serve_static_assets = true
+ end
+ end
+ RUBY
+
+ @plugin.write "lib/bukkits/public/omg.txt", <<-RUBY
+ OMG
+ RUBY
+
+ boot_rails
+
+ Rails::Application.routes.draw do |map|
+ mount(Bukkits::Engine => "/bukkits")
+ end
+
+ env = Rack::MockRequest.env_for("/bukkits/omg.txt")
+ response = Rails::Application.call(env)
+
+ assert_equal response[2].path, File.join(@plugin.path, "lib/bukkits/public/omg.txt")
+ end
end
end