Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pass routes via env['action_dispatch.routes'], it's needed by routes …

…to determine if it should generate prefix for mounted apps
  • Loading branch information...
commit 628b94fbc81cb02b753d0f717a875219853b5764 1 parent 28016d3
@drogus drogus authored
View
4 railties/lib/rails/application.rb
@@ -125,10 +125,10 @@ def call(env)
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
View
8 railties/lib/rails/engine.rb
@@ -159,7 +159,13 @@ def endpoint
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
View
22 railties/test/railties/engine_test.rb
@@ -177,5 +177,27 @@ class Engine < ::Rails::Engine
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
Please sign in to comment.
Something went wrong with that request. Please try again.