Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created January 16, 2009 14:35
Show Gist options
  • Save dchelimsky/47941 to your computer and use it in GitHub Desktop.
Save dchelimsky/47941 to your computer and use it in GitHub Desktop.
class Cart < ActiveRecord::Base
has_many :items, :class_name => 'CartItem', :dependent => :destroy
# ...
def empty!
items.each(&:destroy)
self
end
end
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