function测试和嵌套资源

我有一个嵌套在用户资源中的Story资源。 如何修复此生成function测试?

test "should create story" do assert_difference('Story.count') do post :create, story: @story.attributes end assert_redirected_to story_path(assigns(:story)) end 

DGM解决方案仍然存在story_url问题

您需要提供嵌套在的用户ID:

 post :create, story: @story.attributes, user_id: @user.id 

路径可能是这样的,

 user_story_path(@user.id, assigns(:story))