2011-09-19 6 views
5

Railsでネストされたリソースのテストを作成しようとしています。関連するルート定義は次のとおりです:RSpecでネストされたリソースをテストする

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

RSpecとfactory_girlを使用して、私はテストを始めようとしています。

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 

これらの要求は、常に私はRSpecのとネストされたリソースへのルートを指定する方法を見つけることができない私の人生のために

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"} 

になります。基本的に何かここで間違っているのですか?

アップデート:私はあなたのようにcontent.community.idを渡していることがわかり

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"} 
+0

あなたはどのようなレーキルートを投稿できますか? grepコミュニティがあなたに与えることは? – corroded

+0

元の質問に更新されました。 – Sami

+2

それは奇妙な見ているidです。工場の定義で何が起こっているのかを示すことができますか? – zetetic

答えて

3

:すくいルートの関連する部分はありcommunity_id、そのオブジェクトが特定されるのmongo文書のように見えますBSON :: ObjectIdを使用します。代わりにto_paramを次のように使用してください。

get :show, :community_id => content.community.to_param, :id => content.to_param 
関連する問題