我目前正在通过敏捷开发与Rails 5,并且遇到了我的测试问题。也就是说,在期望产品的地方存在关联不匹配但获得字符串。我已经尝试将line_items_controller_test.rb中的line_items_controller_test.rb从@ line_item.product修复到@ line_item.product_id,但无济于事,并且尽可能多地挖掘了我的技能。Rails 5失败测试ActiveRecord :: AssociationTypeMismatch
这里是我的测试文件line_items_controller_test.rb
test "should update line_item" do
patch line_item_url(@line_item), params: { line_item: { cart_id: @line_item.cart_id, product: @line_item.product } }
assert_redirected_to line_item_url(@line_item)
end
,并从终端
Error:
LineItemsControllerTest#test_should_update_line_item:
ActiveRecord::AssociationTypeMismatch: Product(#70143083725900) expected, got String(#70143078473840)
app/controllers/line_items_controller.rb:47:in `block in update'
app/controllers/line_items_controller.rb:46:in `update'
test/controllers/line_items_controller_test.rb:40:in `block in <class:LineItemsControllerTest>'
bin/rails test test/controllers/line_items_controller_test.rb:39
我的测试结果失败,这里是它提到47和46的控制器本身开头的respond_to
def update
respond_to do |format|
if @line_item.update(line_item_params)
format.html { redirect_to @line_item, notice: 'Line item was successfully updated.' }
format.json { render :show, status: :ok, location: @line_item }
else
format.html { render :edit }
format.json { render json: @line_item.errors, status: :unprocessable_entity }
end
end
end
让我知道是否有任何更多的信息,你需要。您也可以查看我的回购https://github.com/jamesemcc/depot
你可以发布'line_item_params'方法吗? – Pavan
您是否可以更新应用程序中的订单项? –