Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8039 (closed defect: fixed)

Opened 1 year ago

Last modified 7 months ago

[PATCH] assert_routing doesn't like path argument as a hash

Reported by: packagethief Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: test assertions routing
Cc:

Description

This patch fixes that assert_routing doesn't behave as expected when +path+ is sent as a hash. assert_routing first calls assert_recognizes, (which can deal with the path as a hash), and then calls assert_generates (which can't).

This patch simply extracts the value :path value (if path is a hash) before sending it as an argument to assert_generates.

path = path[:path] if path.is_a? Hash
assert_generates(path, options, defaults, extras, message)

Includes test (which fails as follows without the patch):

def test_assert_routing_with_path_as_hash
  assert_routing({:path => 'content', :method => :get}, :controller => 'content', :action => 'index')
end

1) Failure:
test_assert_routing_with_path_as_hash(TestTest)
    [./test/controller/test_test.rb:325:in `test_assert_routing_with_path_as_hash'
     /usr/local/lib/ruby/gems/1.8/gems/mocha-0.4.0/lib/mocha/test_case_adapter.rb:19:in `__send__'
     /usr/local/lib/ruby/gems/1.8/gems/mocha-0.4.0/lib/mocha/test_case_adapter.rb:19:in `run']:
The generated path <"/content"> did not match <"/pathcontentmethodget">

Attachments

assert_routing_with_path_as_hash.diff (1.1 kB) - added by packagethief on 04/09/07 23:33:39.
assert_routing_with_method.patch (2.1 kB) - added by mpalmer on 01/29/08 04:04:55.
Improved patch against current Rails

Change History

04/09/07 23:33:39 changed by packagethief

  • attachment assert_routing_with_path_as_hash.diff added.

01/29/08 04:04:55 changed by mpalmer

  • attachment assert_routing_with_method.patch added.

Improved patch against current Rails

01/29/08 04:07:22 changed by mpalmer

I've just attached new patch which has better tests (it actually makes sure that the :method is being used instead of just ignoring it) and it provides an additional example in the documentation for assert_routing to show that it now can accept that sort of hash. It's against [8642].

01/29/08 10:52:25 changed by thewoolleyman

Didn't actually try it, but looks clean.

+1

01/29/08 14:15:55 changed by rsanheim

+1.

This always has driven me crazy when testing routing.

01/30/08 01:25:47 changed by nzkoz

  • status changed from new to closed.
  • resolution set to fixed.

(In [8748]) Make assert_routing aware of the HTTP method used. Closes #8039 [mpalmer]

02/10/08 01:09:10 changed by nzkoz

(In [8836]) 2-0-stable: Make assert_routing aware of the HTTP method used. References #8039 [mpalmer]

Merging [8748]