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"}
あなたはどのようなレーキルートを投稿できますか? grepコミュニティがあなたに与えることは? – corroded
元の質問に更新されました。 – Sami
それは奇妙な見ているidです。工場の定義で何が起こっているのかを示すことができますか? – zetetic