# Rspec routing\_spec failing on nested singular resource

**URL:** <https://www.ruby-forum.com/t/rspec-routing-spec-failing-on-nested-singular-resource/141382>\
**Category:** Rails\
**Created:** [June 25, 2008, 8:50am UTC](https://www.ruby-forum.com/t/rspec-routing-spec-failing-on-nested-singular-resource/141382 "2008-06-25T08:50:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [June 25, 2008, 8:50am UTC](https://www.ruby-forum.com/t/rspec-routing-spec-failing-on-nested-singular-resource/141382/1 "2008-06-25T08:50:32Z")

</div>

This should be easy to solve; I’m trying to get an Rspec routing\_spec  
working with a singular nested resource;

map.resources :users do |user|  
user.resource :profile  
end

All the tests in the profile\_routing\_spec seem to be failing because  
they can’t match the routes, for example;

# The spec

describe ProfileController do  
describe “route generation” do

```
it "should map { :controller => 'profile', :action => 'show',

```

:user\_id =\> ‘1’ } to /user/1/profile" do  
route\_for(:controller =\> “profile”, :action =\> “show”, :user\_id =\>  
1).should == “/user/1/profile”  
end

# The failed spec message

should map { :controller =\> ‘profile’, :action =\> ‘show’, :user\_id =\>  
‘1’ } to /user/1/profile  
expected: “/user/1/profile”,  
got: “/profile/show?user\_id=1” (using ==)

The spec seems to be turning the user\_id (in the params) in to a query  
on the profile resource, rather than using it to find the parent user  
resource.

This is how ‘rake routes’ looks:

```
                       POST /users/:user_id/profile

```

{:action=\>“create”, :controller=\>“profiles”}  
POST /users/:user\_id/profile.:format  
{:action=\>“create”, :controller=\>“profiles”}  
new\_user\_profile GET /users/:user\_id/profile/new  
{:action=\>“new”, :controller=\>“profiles”}  
formatted\_new\_user\_profile GET /users/:user\_id/profile/new.:format  
{:action=\>“new”, :controller=\>“profiles”}  
edit\_user\_profile GET /users/:user\_id/profile/edit  
{:action=\>“edit”, :controller=\>“profiles”}  
formatted\_edit\_user\_profile GET /users/:user\_id/profile/edit.:format  
{:action=\>“edit”, :controller=\>“profiles”}  
user\_profile GET /users/:user\_id/profile  
{:action=\>“show”, :controller=\>“profiles”}  
formatted\_user\_profile GET /users/:user\_id/profile.:format  
{:action=\>“show”, :controller=\>“profiles”}  
PUT /users/:user\_id/profile  
{:action=\>“update”, :controller=\>“profiles”}  
PUT /users/:user\_id/profile.:format  
{:action=\>“update”, :controller=\>“profiles”}  
DELETE /users/:user\_id/profile  
{:action=\>“destroy”, :controller=\>“profiles”}  
DELETE /users/:user\_id/profile.:format  
{:action=\>“destroy”, :controller=\>“profiles”}

Any ideas?
