-
Notifications
You must be signed in to change notification settings - Fork 21
Testing and pretty_urls
cch1 writes:
One of the warts in RC is the need to forensically determine the resource from the current request. IIRC, this is done by examining the request path, extracting hints from its segments and comparing with the RC configuration. Until Rails exposes the matched named route and the genesis of that named route, there is no better way that I can see.
One of the side effects of this approach is that pretty URLs (/login in lieu of /session/new, for example) require an extra hint or two in the form of extra parameters (resource_path and resource_method) to guide RC to the resource. And from the “push down here and watch it pop up there” files, we now have a testing problem.
Rails uses several custom assertions for Integration testing that can really help you ensure that your app is pushing your users around to the right places. They work by allowing you to compare the path with the url_for options. But because of RC’s hack with extra parameters for pretty URLs, you need to remember to lug around the :resource_path and :resource_method options as well. U-G-L-Y.
Try these as a workaround:
def resource_path
request.path_parameters[:resource_path] || path
end
def resource_method
request.path_parameters[:resource_method] || method
end
Now you can do this:
assert_recognizes({:controller => 'session', :action => 'new'}, resource_path)`
instead of this:
assert_recognizes({:controller => 'session', :action => 'new', :resource_path => '/session/new'}, path)