Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/app/models/spree/order_capturing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def capture_payments
end
end
ensure
@order.update!
# FIXME: Adding the inverse_of on the payments relation for orders -should- fix this,
# however it only appears to make it worse (calling with changes three times instead of once.
# Warrants an investigation. Reloading for now.
@order.reload.update!
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions core/spec/models/spree/order_capturing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@
describe '#capture_payments' do
subject { Spree::OrderCapturing.new(order, payment_methods).capture_payments }

# Regression for the order.update! in the ensure block.
# See the comment there.
context "updating the order" do
let(:order) { create :completed_order_with_totals }
let(:payment_methods) { [] }
let!(:payment) { create(:payment, order: order, amount: order.total) }
let(:changes_spy) { spy('changes_spy') }

before do
payment.pend!

allow_any_instance_of(Spree::Order).to receive(:thingamajig) do |order|
changes_spy.change_callback_occured if order.changes.any?
end

@update_hooks = Spree::Order.update_hooks.dup
Spree::Order.register_update_hook :thingamajig
end

after do
Spree::Order.update_hooks = @update_hooks
end

it "keeps the order up to date when updating and only changes it once" do
subject
expect(changes_spy).to have_received(:change_callback_occured).once
end
end

context "payment methods specified" do
let!(:order) { create(:order, ship_address: create(:address)) }

Expand Down