问题
I have a Story resource nested in a User resource. How do I fix this generate functional test?
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 solution still have the story_url problem
回答1:
You need to provide the user id it is nested in:
post :create, story: @story.attributes, user_id: @user.id
The path may be something like,
user_story_path(@user.id, assigns(:story))
来源:https://stackoverflow.com/questions/8021693/functional-test-and-nested-resource