I’ve added the correct code to decrement the cart items for the Playtime exercise at the end of the Dash of Ajax chapter. My solution was based on the one found here:
But am really struggling with functional tests for the controller. Basically the decrement controller works like this:
def decrement @cart = current_cart @line_item = @cart.decrement_line_item_quantity(params[:id]) # passing in line_item.id ...
When i try to run a simple unit test on this in functional/line_items_controller_test:
test "should decrement line_item" do xhr :post, :decrement, id: products(:ruby).id assert_response :success end
I get an error “ Couldn’t find LineItem with id=207281424 [WHERE “line_items”.”cart_id” = 980190963]” I assume its because the cart its trying to decrement in the controller is in the session, not being defined in the test. I’ve stared at this for a few hours - tried creating a cart in the functional test, but nothing seems to work. Anyone have any ideas? Or is my approach in the controller wrong in terms of being able to run functional tests on it? Thanks!