method
assert_routing
v4.2.9 -
Show latest stable
-
1 note -
Class: ActionDispatch::Assertions::RoutingAssertions
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-23)
- 3.1.0 (0)
- 3.2.1 (-1)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-38)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (2)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
assert_routing(path, options, defaults={}, extras={}, message=nil)
public
Asserts that path and options match both ways; in other words, it verifies that path generates options and then that options generates path. This essentially combines assert_recognizes and assert_generates into one step.
The extras hash allows you to specify options that would normally be provided as a query string to the action. The message parameter allows you to specify a custom error message to display upon failure.
# Assert a basic route: a controller with the default action (index) assert_routing '/home', controller: 'home', action: 'index' # Test a route generated with a specific controller, action, and parameter (id) assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23 # Assert a basic route (controller + default action), with an error message if it fails assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly' # Tests a route, providing a defaults hash assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"} # Tests a route with a HTTP method assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
Register or
log in
to add new notes.
szeryf -
November 16, 2011
0 thanks
Examples in a readable format :)
Here are the above examples in a somewhat more readable format:
# Assert a basic route: a controller with the default action (index) assert_routing ‘/home’, :controller => ‘home’, :action => ‘index’ # Test a route generated with a specific controller, action, and parameter (id) assert_routing ‘/entries/show/23’, :controller => ‘entries’, :action => ‘show’, :id => 23 # Assert a basic route (controller + default action), with an error message if it fails assert_routing ‘/store’, { :controller => ‘store’, :action => ‘index’ }, {}, {}, ‘Route for store index not generated properly’ # Tests a route, providing a defaults hash assert_routing ‘controller/action/9’, {:id => “9”, :item => “square”}, {:controller => “controller”, :action => “action”}, {}, {:item => “square”} # Tests a route with a HTTP method assert_routing({ :method => ‘put’, :path => ‘/product/321’ }, { :controller => “product”, :action => “update”, :id => “321” })