Functional Test and Nested Resource

I have a Story resource nested in a user resource. How can I fix this generated 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 has story_url problem

+4
source share
1 answer

You need to specify the user ID in which it is embedded:

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

The path may be something like

 user_story_path(@user.id, assigns(:story)) 
+6
source

Source: https://habr.com/ru/post/1379786/


All Articles