I'm currently working through Agile Development with Rails 5 and have run into an issue with my testing. Namely, there is an association mismatch going on where it expects the Product but gets a String. I've tried fixing the line in my line_items_controller_test.rb from @line_item.product to @line_item.product_id to no avail and have poked around as much as I know how.
Here is my test file 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
and my test failure from the terminal
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
and here is the controller itself where it mentions 47 and 46 beginning with 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
Let me know if there's any more info you need. You can also check my repo at http://ift.tt/2gJNrIL
Aucun commentaire:
Enregistrer un commentaire