Permalink
Browse files

Checks item_type, as well as item_id, when searching for a cart item …

…for a specific object
  • Loading branch information...
1 parent 087fef7 commit f902356c560a8d0682c52f8f320edaa52c90b720 Guille Lopez committed Jan 30, 2013
@@ -8,7 +8,7 @@ module InstanceMethods
# Returns the cart item for the specified object
#
def item_for(object)
- shopping_cart_items.where(:item_id => object.id).first
+ shopping_cart_items.where(:item_id => object.id, :item_type => object.class.name).first
end
#
File renamed without changes.
@@ -21,7 +21,7 @@
describe :item_for do
context "no cart item exists for the object" do
before do
- shopping_cart_items.should_receive(:where).with(:item_id => object.id).and_return([])
+ shopping_cart_items.should_receive(:where).with(:item_id => object.id, :item_type => object.class.name).and_return([])
end
it "returns the shopping cart item object for the requested object" do
@@ -31,7 +31,7 @@
context "a cart item exists for the object" do
before do
- shopping_cart_items.should_receive(:where).with(:item_id => object.id).and_return([ item ])
+ shopping_cart_items.should_receive(:where).with(:item_id => object.id, :item_type => object.class.name).and_return([ item ])
end
it "returns that item" do

0 comments on commit f902356

Please sign in to comment.