我有一个简单的购物车应用程序,我正在尝试测试以下方法:
def add(item_id)
item = Product.find(item_id)
args = {
:product_id=>item.id,
:seller_id=>item.shop_id,
:price =>item.price
}
cart_items<<CartItem.create(args)
end
def remove(item_id)
cart_items.where(:product_id=>item_id).map(&:destroy)
end这东西的规格是
it "should remove a product from the cart" do
cart = Cart.new
item = Product.create(:price=>3450,:id=>1,:shop_id=>1)
cart.add(item.id)
cart.should_not be_empty
cart.remove(item.id)
cart.should be_empty
end无论我做什么,我都不能让它通过。cart_item.length始终等于1。不确定为什么会发生这种情况。请帮帮忙。
发布于 2011-05-21 22:52:56
我怀疑问题在于您没有在任何时候将购物车保存到数据库中。
发布于 2011-05-21 07:00:25
我经常发现这是因为您在删除项后没有从数据库重新加载。
cart.reload
cart.should be_emptyhttps://stackoverflow.com/questions/6078348
复制相似问题