diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 1cffc05734..3ac826df52 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -152,7 +152,7 @@ class CheckoutController < Spree::CheckoutController # Overriding Spree's methods def raise_insufficient_quantity flash[:error] = t(:spree_inventory_error_flash_for_insufficient_quantity) - redirect_to main_app.shop_path + redirect_to cart_path end def redirect_to_paypal_express_form_if_needed diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index b1c8856f8d..2cd959a1b4 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -46,6 +46,22 @@ feature "As a consumer I want to check out my cart", js: true do distributor.shipping_methods << sm3 end + describe "when I have an out of stock product in my cart" do + before do + Spree::Config.set allow_backorders: false + variant.on_hand = 0 + variant.save! + end + + it "returns me to the cart with an error message" do + visit checkout_path + + page.should_not have_selector 'closing', text: "Checkout now" + page.should have_selector 'closing', text: "Your shopping cart" + page.should have_content "An item in your cart has become unavailable" + end + end + context "on the checkout page" do before do visit checkout_path