Created
January 16, 2009 14:35
-
-
Save dchelimsky/47941 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Cart < ActiveRecord::Base | |
has_many :items, :class_name => 'CartItem', :dependent => :destroy | |
# ... | |
def empty! | |
items.each(&:destroy) | |
self | |
end | |
end |
This file contains hidden or 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
describe Cart, "with some items" do | |
before do | |
@cart = Factory(:cart) | |
@cart.items << CartItem.new(:price => 10.0, :quantity => 2) | |
@cart.items << CartItem.new(:price => 10.0, :quantity => 1) | |
end | |
# ... | |
it "can empty itself" do | |
@cart.empty! | |
@cart.item_count.should == 0 | |
end | |
end | |
# Fails: | |
# 'Cart with some items can empty itself' FAILED | |
# expected: 0, | |
# got: 3 (using ==) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment