Skip to content

Instantly share code, notes, and snippets.

@lmarburger
Created January 20, 2009 18:46
Show Gist options
  • Save lmarburger/49598 to your computer and use it in GitHub Desktop.
Save lmarburger/49598 to your computer and use it in GitHub Desktop.
require 'test_helper'
class CartsControllerTest < ActionController::TestCase
context "Adding a wine" do
context "without a quantity" do
setup { create_cart :wine_id => @mock_wine_id = 1 }
should_assign_to :wine_id
should_redirect_to 'wines_path'
should "add to cart" do
assert_not_nil get_cart[@mock_wine_id]
end
should "set quantity to 1" do
assert_equal 1, get_cart[@mock_wine_id]
end
should "store cart data in the session" do
assert_equal(get_cart.wines, get_cart_data_from_session)
end
end
context "with a quantity" do
setup { create_cart :wine_id => @mock_wine_id = 1, :wine_quantity => @mock_wine_quantity = 2 }
should "add to cart" do
assert_not_nil get_cart[@mock_wine_id]
end
should "add the correct quantity" do
assert_equal @mock_wine_quantity, get_cart[@mock_wine_id]
end
should "update cart in session" do
assert_equal(get_cart.wines, get_cart_data_from_session)
end
end
end
private
def create_cart(data = {})
post :create, data
end
def get_cart
assigns(:cart)
end
def get_cart_data_from_session
session[:cart]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment