Method: ActionController::TestProcess#with_routing
- Defined in:
- lib/action_controller/test_process.rb
#with_routing ⇒ Object
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 map.draw { map.connect ... }:
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
503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/action_controller/test_process.rb', line 503 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 |