Has anyone found a workable solution to this yet?

Gianpi says: Solved the functional test issue

I decided to redirect to the current_cart (method created in the ApplicationController, which will bring the user to their current cart in the session), and then solved the functional test issue with this:

WRT getting back to the cart redirect_to :back works

Sam Says

I used Diogo’s solution to redirect to different places. However I can’t seem to get the testing and fixtures to work. The controller seems to have a new empty cart instead of my non-empty fixture cart, which causes my test to fail.

How to modify test/code so that the fixture can work with the session mechanism?

Steve Says

I had trouble with testing too, also using a ‘return to store if cart empty else return to cart’ style. It seems to be around the cart and sessions – or rather testing and using the current_cart method. This worked for me though:

line_items_controller.rb

def destroy
@line_item = LineItem.find(params[:id])
@line_item.destroy
respond_to do |format|
# check for any line_items that reference the current cart.
# using 'current_cart' as the parameter will fail in the test.
if LineItem.find_by_cart_id(@line_item.cart_id).nil?
format.html { redirect_to store_url,
notice: 'Your cart is currently empty' }
else
format.html { redirect_to current_cart,
notice: 'Line item removed' }
end
format.json { head :ok }
end
end

Now for my tests. I added an extra element (three) to the line_items fixture. I also created a separate test for the store_url redirection.