Skip to content

Instantly share code, notes, and snippets.

@miketierney
Created February 8, 2009 06:44
Show Gist options
  • Save miketierney/60275 to your computer and use it in GitHub Desktop.
Save miketierney/60275 to your computer and use it in GitHub Desktop.
require 'test_helper'
class CartTest < ActiveSupport::TestCase
test "initialize" do
cart = Cart.new
assert_equal 0, cart.items.length
end
test "add product" do
cart = Cart.new
cart << products(:one)
assert_equal 1, cart.items.length
end
test "add multiple products" do
cart = Cart.new
cart << (products(:one))
cart << (products(:two))
assert_equal 2, cart.items.length
end
test "add product increments existing products" do
cart = Cart.new
5.times { cart << products(:one) }
assert_equal 5, cart.items.first.quantity
end
test "total price math check" do
cart = Cart.new
cart << products(:one)
cart << products(:two)
assert_equal products(:one).price + products(:two).price, cart.total_price
end
test "total quantity math check" do
cart = Cart.new
2.times{ cart << products(:one) }
cart << products(:two)
assert_equal 3, cart.total_items
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment