diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index d16e428922..e9173d59a1 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -201,7 +201,7 @@ module Spree end def update_order - order.update! + order.reload.update! end # Necessary because some payment gateways will refuse payments with diff --git a/spec/features/admin/payments_spec.rb b/spec/features/admin/payments_spec.rb index d6c5f38d66..23baabd4ed 100644 --- a/spec/features/admin/payments_spec.rb +++ b/spec/features/admin/payments_spec.rb @@ -35,4 +35,33 @@ feature ' expect(page).to have_content I18n.t(:new_payment) end end + + context "creating an order's first payment via admin", js: true do + before do + order.update_columns( + state: "payment", + payment_state: nil, + shipment_state: nil, + completed_at: nil + ) + end + + it "creates the payment, completes the order, and updates payment and shipping states" do + login_as_admin_and_visit spree.new_admin_order_payment_path order + + expect(page).to have_content "New Payment" + + within "#new_payment" do + find('input[type="radio"]').click + end + + click_button "Update" + expect(page).to have_content "Payments" + + order.reload + expect(order.state).to eq "complete" + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" + end + end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 14e6d151d0..d0f4c03241 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -255,6 +255,10 @@ feature "As a consumer I want to check out my cart", js: true do place_order expect(page).to have_content "Your order has been processed successfully" end.to enqueue_job ConfirmOrderJob + + order = Spree::Order.complete.last + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" end end end @@ -389,7 +393,7 @@ feature "As a consumer I want to check out my cart", js: true do end.to enqueue_job ConfirmOrderJob # And the order's special instructions should be set - order = Spree::Order.complete.first + order = Spree::Order.complete.last expect(order.special_instructions).to eq "SpEcIaL NoTeS" # Shipment and payments states should be set @@ -421,6 +425,10 @@ feature "As a consumer I want to check out my cart", js: true do it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do place_order expect(page).to have_content "Your order has been processed successfully" + + order = Spree::Order.complete.last + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" end it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do @@ -443,9 +451,11 @@ feature "As a consumer I want to check out my cart", js: true do expect(page).to have_content "Your order has been processed successfully" # There are two orders - our order and our new cart - o = Spree::Order.complete.first - expect(o.shipment_adjustments.first.amount).to eq(4.56) - expect(o.payments.first.amount).to eq(10 + 1.23 + 4.56) # items + fees + shipping + order = Spree::Order.complete.last + expect(order.shipment_adjustments.first.amount).to eq(4.56) + expect(order.payments.first.amount).to eq(10 + 1.23 + 4.56) # items + fees + shipping + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" end end @@ -464,9 +474,11 @@ feature "As a consumer I want to check out my cart", js: true do expect(page).to have_content "Your order has been processed successfully" # There are two orders - our order and our new cart - o = Spree::Order.complete.first - expect(o.all_adjustments.payment_fee.first.amount).to eq 5.67 - expect(o.payments.first.amount).to eq(10 + 1.23 + 5.67) # items + fees + transaction + order = Spree::Order.complete.last + expect(order.all_adjustments.payment_fee.first.amount).to eq 5.67 + expect(order.payments.first.amount).to eq(10 + 1.23 + 5.67) # items + fees + transaction + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" end end @@ -485,8 +497,10 @@ feature "As a consumer I want to check out my cart", js: true do expect(page).to have_content "Your order has been processed successfully" # Order should have a payment with the correct amount - o = Spree::Order.complete.first - expect(o.payments.first.amount).to eq(11.23) + order = Spree::Order.complete.last + expect(order.payments.first.amount).to eq(11.23) + expect(order.payment_state).to eq "paid" + expect(order.shipment_state).to eq "ready" end it "shows the payment processing failed message when submitted with an invalid credit card" do