From a6e94547e84ae692a084a95f2c3ba02d513edf3e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 23 May 2014 09:56:33 -0700 Subject: use the request object since we have it stop hardcoding hash keys and use the accessors provided on the request object. --- actionpack/lib/action_dispatch/journey/router.rb | 17 +++++++++-------- actionpack/test/dispatch/routing_test.rb | 8 +++----- actionpack/test/journey/router_test.rb | 4 +++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index c34b44409e..5e1fc55d36 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -55,17 +55,18 @@ module ActionDispatch end def call(env) - env['PATH_INFO'] = Utils.normalize_path(env['PATH_INFO']) - req = request_class.new(env) + req.path_info = Utils.normalize_path(req.path_info) + find_routes(env, req).each do |match, parameters, route| - set_params = req.path_parameters - script_name, path_info = env.values_at('SCRIPT_NAME', 'PATH_INFO') + set_params = req.path_parameters + path_info = req.path_info + script_name = req.script_name unless route.path.anchored - env['SCRIPT_NAME'] = (script_name.to_s + match.to_s).chomp('/') - env['PATH_INFO'] = match.post_match + req.script_name = (script_name.to_s + match.to_s).chomp('/') + req.path_info = match.post_match end req.path_parameters = set_params.merge parameters @@ -73,8 +74,8 @@ module ActionDispatch status, headers, body = route.app.call(env) if 'pass' == headers['X-Cascade'] - env['SCRIPT_NAME'] = script_name - env['PATH_INFO'] = path_info + req.script_name = script_name + req.path_info = path_info req.path_parameters = set_params next end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 051431ce26..ccc3839212 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3368,15 +3368,13 @@ end class TestAltApp < ActionDispatch::IntegrationTest class AltRequest - attr_accessor :path_parameters + attr_accessor :path_parameters, :path_info, :script_name def initialize(env) @path_parameters = {} @env = env - end - - def path_info - "/" + @path_info = "/" + @script_name = "" end def request_method diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 9a8d644f7b..98cd6b0d34 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -12,7 +12,9 @@ module ActionDispatch def setup @app = StubDispatcher.new @routes = Routes.new - @router = Router.new(@routes, {}) + @router = Router.new(@routes, { + :request_class => ActionDispatch::Request + }) @formatter = Formatter.new(@routes) end -- cgit v1.2.3