Skip to content

Commit

Permalink
use the request object since we have it
Browse files Browse the repository at this point in the history
stop hardcoding hash keys and use the accessors provided on the request
object.
  • Loading branch information
tenderlove committed May 23, 2014
1 parent 2fdddce commit a6e9454
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions actionpack/lib/action_dispatch/journey/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,27 @@ def initialize(routes, options)
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

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
Expand Down
8 changes: 3 additions & 5 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3368,15 +3368,13 @@ def expected_redirect_body(url)

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
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/journey/router_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class StubDispatcher < Routing::RouteSet::Dispatcher; end
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

Expand Down

0 comments on commit a6e9454

Please sign in to comment.