我正在制作一个简单的测试项目来为我的测试做准备。我对嵌套资源相当陌生,在我的示例中,我有一个 newsitem,每个 newsitem 都有评论。
路由看起来像这样:
resources :comments
resources :newsitems do
resources :comments
end
我目前正在为评论设置功能测试,但遇到了一些问题。
这将获得新闻站点评论的索引。@newsitem 在 ofc 的设置中声明。
test "should get index" do
get :index,:newsitem_id => @newsitem
assert_response :success
assert_not_nil assigns(:newsitem)
end
但问题出在这里,在“应该得到新的”。
test "should get new" do
get new_newsitem_comment_path(@newsitem)
assert_response :success
end
我收到以下错误。
ActionController::RoutingError: No route matches {:controller=>"comments", :action=>"/newsitems/1/comments/new"}
但是当我查看路由表时,我看到了:
new_newsitem_comment GET /newsitems/:newsitem_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
我不能使用名称路径或我在这里做错了什么吗?
提前致谢。