aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-02-24 16:01:03 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-02-25 17:53:00 -0800
commit226dfc2681c98deaf14e4ae82e973d1d5caedd68 (patch)
treedf761036bb714f3b9c10bb1eced20322aad953a7 /actionpack/lib/action_dispatch/testing
parent76237f163ff7ad2a64af926030e3449c547cafa2 (diff)
downloadrails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.tar.gz
rails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.tar.bz2
rails-226dfc2681c98deaf14e4ae82e973d1d5caedd68.zip
WIP: Remove the global router
Diffstat (limited to 'actionpack/lib/action_dispatch/testing')
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb27
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb10
2 files changed, 20 insertions, 17 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
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 14c7ff642b..3b9d8b0318 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -188,11 +188,11 @@ module ActionDispatch
unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = singleton_class
- ActionDispatch::Routing::Routes.install_helpers(klass)
+ # ActionDispatch::Routing::Routes.install_helpers(klass)
# the helpers are made protected by default--we make them public for
# easier access during testing and troubleshooting.
- klass.module_eval { public *ActionDispatch::Routing::Routes.named_routes.helpers }
+ # klass.module_eval { public *ActionDispatch::Routing::Routes.named_routes.helpers }
@named_routes_configured = true
end
end
@@ -224,9 +224,13 @@ module ActionDispatch
# Returns the URL for the given options, according to the rules specified
# in the application's routes.
def url_for(options)
+ # ROUTES TODO: @app.router is not guaranteed to exist, so a generic Rack
+ # application will not work here. This means that a generic Rack application
+ # integration test cannot call url_for, since the application will not have
+ # #router on it.
controller ?
controller.url_for(options) :
- generic_url_rewriter.rewrite(options)
+ generic_url_rewriter.rewrite(SharedTestRoutes, options)
end
private