diff options
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 8 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 22 |
3 files changed, 31 insertions, 3 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index fee99faf43..4ea828c549 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -125,10 +125,10 @@ module Rails end def env_defaults - @env_defaults ||= { + @env_defaults ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, "action_dispatch.secret_token" => config.secret_token - } + }) end def initializers diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 41b0a764e2..22a1a15bf5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -159,7 +159,13 @@ module Rails end def call(env) - app.call(env) + app.call(env.reverse_merge!(env_defaults)) + end + + def env_defaults + @env_defaults ||= { + "action_dispatch.routes" => routes + } end def routes diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index e8675daef0..4257a9fa83 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -177,5 +177,27 @@ module RailtiesTest assert Bukkits::Engine.config.environment_loaded end + + test "it passes router in env" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < ::Rails::Engine + endpoint lambda { |env| [200, {'Content-Type' => 'text/html'}, 'hello'] } + end + end + RUBY + + boot_rails + + env = Rack::MockRequest.env_for("/") + response = Bukkits::Engine.call(env) + + assert_equal Bukkits::Engine.routes, env['action_dispatch.routes'] + + env = Rack::MockRequest.env_for("/") + response = Rails.application.call(env) + + assert_equal Rails.application.routes, env['action_dispatch.routes'] + end end end |