我试图在Rails中为嵌套资源创建测试.相关的路线定义是:
resources :communities do
resources :contents, :type => 'Content'
end
Run Code Online (Sandbox Code Playgroud)
使用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
Run Code Online (Sandbox Code Playgroud)
这些请求总是导致
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"}
Run Code Online (Sandbox Code Playgroud)
对于我的生活,我找不到使用RSpec指定到嵌套资源的路径的方法.我在这里做了一些根本错误的事吗?
更新:佣金路线的相关部分是:
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", …Run Code Online (Sandbox Code Playgroud)