RSpec view tests and url_for

Ran into a problem with RSpec when trying to create a spec for a view that used an ActionView url helper that required additional parameters to generate the url.

route.edit_page ':site/edit', :conditions => { :method => :get }, :controller => 'webpages', :action => 'edit_page'
The above route sets params[:site] which is later used for url generation (using, edit_page_path). Investigation revealed however that url_for is not actually using params[] to get default values for urls, but actually @request.path_parameters:


ActionView::Helpers::UrlHelper.url_for()
  ActionController::Base.url_for()
    ActionController::UrlRewriter.rewrite()
       ActionController::UrlRewriter.rewrite_url()
         ActionController::UrlRewriter.rewrite_path()
           Routing::Routes.generate(options, @request.symbolized_path_parameters)
ViewExampleGroup#render doesn’t provide the facility to add anything to @request.path_parameters, like get/put and friends do in ControllerExampleGroup.
DChelimsky said file a feature request on lighthouse for it, but before I do that I want to do some further investigation and see whether this is needed for nested resources as well, which would make it a more compelling feature, and probably take a stab at patching it myself. 

You must be logged in to post a comment.