微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

编辑操作的测试用例错误参数 id 不存在

如何解决编辑操作的测试用例错误参数 id 不存在

这是 line_items_controller.rb

<prososition>

测试编辑操作

  before_action :set_line_item,only: [:show,:edit,:update,:destroy]

 def edit
  end
  private
    # Use callbacks to share common setup or constraints between actions.
    def set_line_item
      @line_item = LineItem.find(params[:id])
    end

错误

  describe "GET /edit" do
    let!(:user) { create(:user) }
    before do
      sign_in(user) # Factory Bot user
    end
    it "render a successful response" do
      line_item = build(:line_item)
      order = build(:order)   
      product = build(:product)
      line_item.order_id = order
      line_item.product_id = product
      line_item.cart_id = 1
      line_item.save
      get edit_line_item_url(line_item)
      expect(response).to be_successful
    end
  end

当我传入 url 时,id 166 存在。 谁能帮我解决这个问题。 谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。