instance method
with_routing
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
with_routing()
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
Source
# File actionpack/lib/action_controller/test_process.rb, line 545
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
Defined in actionpack/lib/action_controller/test_process.rb line 545
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::TestProcess