Created
February 8, 2009 06:44
-
-
Save miketierney/60275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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