功能测试和嵌套资源 [英] Functional test and nested resource

查看:40
本文介绍了功能测试和嵌套资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套在用户资源中的故事资源.如何修复此生成功能测试?

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 解决方案仍然存在 story_url 问题

DGM solution still have the story_url problem

推荐答案

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

You need to provide the user id it is nested in:

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

路径可能类似于,

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

这篇关于功能测试和嵌套资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆