Permalink
Browse files

Prevent double submission of checkout confirm step

  • Loading branch information...
BDQ committed Sep 14, 2012
1 parent 25128e8 commit 84f91aa875d41fa1e77646c9cc25b321dab050cc
Showing with 35 additions and 10 deletions.
  1. +1 −0 core/app/views/spree/checkout/_confirm.html.erb
  2. +34 −10 core/spec/requests/checkout_spec.rb
@@ -8,4 +8,5 @@
<div class="form-buttons" data-hook="buttons">
<%= submit_tag t(:place_order), :class => 'continue button primary' %>
<script>disableSaveOnClick();</script>
</div>
@@ -7,16 +7,19 @@
end
context "visitor makes checkout as guest without registration" do
before(:each) do
Spree::Product.delete_all
@product = create(:product, :name => "RoR Mug")
@product.on_hand = 1
@product.save
create(:zone)
end
context "when backordering is disabled" do
before(:each) do
reset_spree_preferences do |config|
config.allow_backorders = false
end
Spree::Product.delete_all
@product = create(:product, :name => "RoR Mug")
@product.on_hand = 1
@product.save
create(:zone)
end
it "should warn the user about out of stock items" do
@@ -32,13 +35,23 @@
within(:css, "span.out-of-stock") { page.should have_content("Out of Stock") }
end
end
it "prevents double clicking the payment button on checkout", :js => true do
visit spree.root_path
click_link "RoR Mug"
click_button "add-to-cart-button"
click_link "Checkout"
context "and likes to double click buttons" do
before(:each) do
@order = create(:order_with_totals, :state => 'payment',
:bill_address => create(:address),
:ship_address => create(:address),
:shipping_method => create(:shipping_method))
@order.reload
@order.update!
@order.stub(:available_payment_methods => [ create(:bogus_payment_method, :environment => 'test') ])
Spree::CheckoutController.any_instance.stub(:current_order => @order)
Spree::CheckoutController.any_instance.stub(:skip_state_validation? => true)
end
it "prevents double clicking the payment button on checkout", :js => true do
visit spree.checkout_state_path(:payment)
# prevent form submit to verify button is disabled
@@ -49,6 +62,17 @@
page.should have_selector('input.button[disabled]')
end
it "prevents double clicking the confirm button on checkout", :js => true do
visit spree.checkout_state_path(:confirm)
# prevent form submit to verify button is disabled
page.execute_script("$('#checkout_form_confirm').submit(function(){return false;})")
page.should_not have_selector('input.button[disabled]')
click_button "Place Order"
page.should have_selector('input.button[disabled]')
end
# Regression test for #1596
context "full checkout" do
before do

0 comments on commit 84f91aa

Please sign in to comment.