Functional test and nested resource

好久不见. 提交于 2020-01-02 06:18:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!