Testing Nested Resources Using RSpec

I am trying to create tests for nested resources in Rails. Corresponding route definition:

resources :communities do
  resources :contents, :type => 'Content'
end

Using RSpec and factory_girl, I try to start with testing, for example,

describe ContentsController do
  it 'should display a content item under a community' do
    content = FactoryGirl.create(:content)
    get :show, :community_id => content.community.id, :id => content.id
  end
end

These queries always result in

Failure/Error: get :show, :community_id => content.community.id, :id => content.id
 ActionController::RoutingError:
   No route matches {:community_id=>BSON::ObjectId('4e7773c6ac54c3d1ad000002'),
   :id=>BSON::ObjectId('4e7773c6ac54c3d1ad000001'), :controller=>"contents",
   :action=>"show"}

Over the course of my life, I cannot find a way to specify a route to an embedded resource with RSpec. Am I fundamentally wrong with something here?

Update: corresponding part of rake routes:

    community_contents GET    /communities/:community_id/contents(.:format)             {:action=>"index", :controller=>"contents"}
                       POST   /communities/:community_id/contents(.:format)             {:action=>"create", :controller=>"contents"}
 new_community_content GET    /communities/:community_id/contents/new(.:format)         {:action=>"new", :controller=>"contents"}
edit_community_content GET    /communities/:community_id/contents/:id/edit(.:format)    {:action=>"edit", :controller=>"contents"}
     community_content GET    /communities/:community_id/contents/:id(.:format)         {:action=>"show", :controller=>"contents"}
                       PUT    /communities/:community_id/contents/:id(.:format)         {:action=>"update", :controller=>"contents"}
                       DELETE /communities/:community_id/contents/:id(.:format)         {:action=>"destroy", :controller=>"contents"}
+5
source share
1 answer

, content.community.id : community_id, mongo, BSON:: ObjectId. to_param :

get :show, :community_id => content.community.to_param, :id => content.to_param
+3

All Articles