assert_recognizes
- 1.0.0
- 1.1.6
- 1.2.6 (0)
- 2.0.3 (10)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- What's this?
assert_recognizes(expected_options, path, extras={}, message=nil)
public
Asserts that the routing of the given path was handled correctly and that the parsed options match.
assert_recognizes({:controller => 'items', :action => 'index'}, 'items') # check the default action assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list') # check a specific action assert_recognizes({:controller => 'items', :action => 'list', :id => '1'}, 'items/list/1') # check an action with a parameter
Pass a hash in the second argument to specify the request method. This is useful for routes requiring a specific HTTP method. The hash should contain a :path with the incoming request path and a :method containing the required HTTP verb.
# assert that POSTing to /items will call the create action on ItemsController assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post})
You can also pass in "extras" with a hash containing URL parameters that would normally be in the query string. This can be used to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the extras argument, appending the query string on the path directly will not work. For example:
# assert that a path of '/items/list/1?view=print' returns the correct options assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" })
Small notice about recognize urls with specific HTTP verbs
This is wrong ruby syntax:
assert_recognizes {:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}
Parentheses are obligatory in this case:
assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post})