diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-02-24 16:01:03 -0800 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-02-25 17:53:00 -0800 |
commit | 226dfc2681c98deaf14e4ae82e973d1d5caedd68 (patch) | |
tree | df761036bb714f3b9c10bb1eced20322aad953a7 /actionpack/lib/action_dispatch/testing/assertions | |
parent | 76237f163ff7ad2a64af926030e3449c547cafa2 (diff) | |
download | rails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.tar.gz rails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.tar.bz2 rails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.zip |
WIP: Remove the global router
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/routing.rb | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index ada749bfe2..f281febbc5 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -80,7 +80,7 @@ module ActionDispatch expected_path = "/#{expected_path}" unless expected_path[0] == ?/ # Load routes.rb if it hasn't been loaded. - generated_path, extra_keys = ActionDispatch::Routing::Routes.generate_extras(options, defaults) + generated_path, extra_keys = @router.generate_extras(options, defaults) found_extras = options.reject {|k, v| ! extra_keys.include? k} msg = build_message(message, "found extras <?>, not <?>", found_extras, extras) @@ -142,22 +142,21 @@ module ActionDispatch # end # def with_routing - real_routes = ActionDispatch::Routing::Routes - ActionDispatch::Routing.module_eval { remove_const :Routes } - - temporary_routes = ActionDispatch::Routing::RouteSet.new - ActionDispatch::Routing.module_eval { const_set :Routes, temporary_routes } - - yield temporary_routes + old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new + old_controller, @controller = @controller, @controller.clone if @controller + # ROUTES TODO: Figure out this insanity + silence_warnings { ::ActionController.const_set(:UrlFor, @router.named_url_helpers) } + _router = @router + @controller.metaclass.send(:send, :include, @router.named_url_helpers) if @controller + yield @router ensure - if ActionDispatch::Routing.const_defined? :Routes - ActionDispatch::Routing.module_eval { remove_const :Routes } - end - ActionDispatch::Routing.const_set(:Routes, real_routes) if real_routes + @router = old_routes + @controller = old_controller if @controller + silence_warnings { ::ActionController.const_set(:UrlFor, @router.named_url_helpers) } if @router end def method_missing(selector, *args, &block) - if @controller && ActionDispatch::Routing::Routes.named_routes.helpers.include?(selector) + if @controller && @router.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super @@ -174,7 +173,7 @@ module ActionDispatch request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method request.path = path - params = ActionDispatch::Routing::Routes.recognize_path(path, { :method => request.method }) + params = @router.recognize_path(path, { :method => request.method }) request.path_parameters = params.with_indifferent_access request |