Created
December 5, 2014 03:20
-
-
Save data-doge/ac5d356bdf6bec3a0460 to your computer and use it in GitHub Desktop.
week7-shi
This file contains 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
###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