ActionController::RoutingError -> Functional Tests and :path_prefix in routes.rb


#1

Hi,

I’m trying to write a test for my ProfilesController, which I mapped
in my routes.rb, using:

map.resource :profile, :path_prefix => ‘:account’

This way, I have routes like:

           profile POST   /:account/profile

{:controller=>“profiles”, :action=>“create”}
formatted_profile POST /:account/profile.:format
{:controller=>“profiles”, :action=>“create”}
new_profile GET /:account/profile/new
{:controller=>“profiles”, :action=>“new”}
formatted_new_profile GET /:account/profile/new.:format
{:controller=>“profiles”, :action=>“new”}
edit_profile GET /:account/profile/edit
{:controller=>“profiles”, :action=>“edit”}
formatted_edit_profile GET /:account/profile/edit.:format
{:controller=>“profiles”, :action=>“edit”}
GET /:account/profile
{:controller=>“profiles”, :action=>“show”}
GET /:account/profile.:format
{:controller=>“profiles”, :action=>“show”}
PUT /:account/profile
{:controller=>“profiles”, :action=>“update”}
PUT /:account/profile.:format
{:controller=>“profiles”, :action=>“update”}
DELETE /:account/profile
{:controller=>“profiles”, :action=>“destroy”}
DELETE /:account/profile.:format
{:controller=>“profiles”, :action=>“destroy”}

My problem is that, when running the following test:

def test_new
get :new
assert_redirected_to new_session_path
end

I get the error:

test_new(ProfilesControllerTest):
ActionController::RoutingError: No route matches
{:controller=>“profiles”, :action=>“new”}

I can’t understand why ‘get :new’ can’t find that route and, on the
other hand, ‘rake routes’ does recognize it.

This part of my application works fine (including :url => {:controller
=> ‘profiles’, :action => ‘create’} in the form_for tags). Though, I
don’t know how to write the proper tests. Do I have to pass any extra
parameter to ‘get’? Do you think is it a bit silly to use this
mapping?

Thanks in advance,

Pablo.