The code works fine but i can't understand why the test fails.
This is my test:
ab
and this is the new action in Orders controller:
test "requires item in cart" do
get :new
assert_redirected_to store_path
assert_equal flash[:notice], 'Your cart is empty'
end
and i get an error:
def new
if @cart.line_items.empty?
redirect_to store_url, notice: "Your cart is empty"
return
end
@order = Order.new
end
models associations:
"test_requires_item_in_cart", OrdersControllerTest, 2015-07-28 20:21:48 +0300]
test_requires_item_in_cart#OrdersControllerTest (1438104108.20s)
NoMethodError: NoMethodError: undefined method `line_items' for 3:Fixnum
and
class LineItem < ActiveRecord::Base
belongs_to :product
belongs_to :cart
I think the problem is that the test cannot recognize the association between @cart and line_items in controller.
Any help?