Skip to content

Instantly share code, notes, and snippets.

@data-doge
Created December 5, 2014 03:20
Show Gist options
  • Save data-doge/ac5d356bdf6bec3a0460 to your computer and use it in GitHub Desktop.
Save data-doge/ac5d356bdf6bec3a0460 to your computer and use it in GitHub Desktop.
week7-shi
###CART_CONTROLLER_SPEC
describe "method calls" do
before { @product = create(:product) }
it "new cart is passed current_user" do
expect(Cart).to receive(:new).with(@current_user).and_call_original
patch :remove_product, {id: @product.id}
end
it "calls the cart's remove method with product as the parameter" do
cart = instance_double(Cart)
allow(Cart).to receive(:new).and_return(cart)
expect(cart).to receive(:remove).with(@product)
patch :remove_product, {id: @product.id}
end
end
###CART CONTROLLER
def remove_product
@cart = Cart.new(current_user)
@product = Product.find(params[:id])
@cart.remove(@product)
redirect_to "/cart/show"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment