diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-12-12 18:09:44 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-12-12 18:09:44 -0600 |
commit | ee395fe626760e897abd9e881b54d3cc3f407d31 (patch) | |
tree | 9d79bb4defa4c8a13009deb856e00c5125e63710 /actionpack/lib/action_dispatch/testing/assertions/routing.rb | |
parent | 96deabace71d5cb3ee12c7b99e459db5e2acb1a6 (diff) | |
download | rails-ee395fe626760e897abd9e881b54d3cc3f407d31.tar.gz rails-ee395fe626760e897abd9e881b54d3cc3f407d31.tar.bz2 rails-ee395fe626760e897abd9e881b54d3cc3f407d31.zip |
TestProcess belongs in AD
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions/routing.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/routing.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 4bc5275e04..794fb888b7 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -126,6 +126,46 @@ module ActionDispatch assert_generates(path.is_a?(Hash) ? path[:path] : path, options, defaults, extras, message) end + # A helper to make it easier to test different route configurations. + # This method temporarily replaces ActionController::Routing::Routes + # with a new RouteSet instance. + # + # The new instance is yielded to the passed block. Typically the block + # will create some routes using <tt>map.draw { map.connect ... }</tt>: + # + # with_routing do |set| + # set.draw do |map| + # map.connect ':controller/:action/:id' + # assert_equal( + # ['/content/10/show', {}], + # map.generate(:controller => 'content', :id => 10, :action => 'show') + # end + # end + # end + # + def with_routing + real_routes = ActionController::Routing::Routes + ActionController::Routing.module_eval { remove_const :Routes } + + temporary_routes = ActionController::Routing::RouteSet.new + ActionController::Routing.module_eval { const_set :Routes, temporary_routes } + + yield temporary_routes + ensure + if ActionController::Routing.const_defined? :Routes + ActionController::Routing.module_eval { remove_const :Routes } + end + ActionController::Routing.const_set(:Routes, real_routes) if real_routes + end + + def method_missing(selector, *args, &block) + if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector) + @controller.send(selector, *args, &block) + else + super + end + end + private # Recognizes the route for a given path. def recognized_request_for(path, request_method = nil) |