From b18f22d15c28fc5fe634928d59148c932bba4696 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <aaron.patterson@gmail.com> Date: Sun, 25 May 2014 14:26:48 -0700 Subject: pass the request object to the application --- actionpack/lib/action_dispatch/journey/router.rb | 2 +- actionpack/lib/action_dispatch/routing/mapper.rb | 5 ++--- actionpack/test/journey/router_test.rb | 7 +++++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index 2ead6a4eb3..8ec223afc3 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -39,7 +39,7 @@ module ActionDispatch req.path_parameters = set_params.merge parameters - status, headers, body = route.app.call(req.env) + status, headers, body = route.app.serve(req) if 'pass' == headers['X-Cascade'] req.script_name = script_name diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 702d998447..08a5e7c637 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -42,9 +42,8 @@ module ActionDispatch end end - def call(env) - req = @request.new(env) - matches?(req) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ] + def serve(req) + matches?(req) ? @app.call(req.env) : [ 404, {'X-Cascade' => 'pass'}, [] ] ensure req.reset_parameters end diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 561c547b44..1a2106a3c5 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -218,13 +218,16 @@ module ActionDispatch end def test_clear_trailing_slash_from_script_name_on_root_unanchored_routes + route_set = Routing::RouteSet.new + mapper = Routing::Mapper.new route_set + strexp = Router::Strexp.new("/", {}, ['/', '.', '?'], false) path = Path::Pattern.new strexp app = lambda { |env| [200, {}, ['success!']] } - @router.routes.add_route(app, path, {}, {}, {}) + mapper.get '/weblog', :to => app env = rack_env('SCRIPT_NAME' => '', 'PATH_INFO' => '/weblog') - resp = @router.serve rails_env env + resp = route_set.call env assert_equal ['success!'], resp.last assert_equal '', env['SCRIPT_NAME'] end -- cgit v1.2.3