From 4ae9af38557cf9763a2808fb8128ae025772da03 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Mon, 29 Aug 2016 06:51:23 -0600 Subject: [PATCH 1/4] Merge pull request #1406 from jordan-brough/add-order-payment-inverse-of Add `inverse_of` to order.payments --- core/app/models/spree/order.rb | 2 +- core/app/models/spree/order_capturing.rb | 23 +++++++------------ .../spec/models/spree/order_capturing_spec.rb | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 39dcd4bb431..4724915818d 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -48,7 +48,7 @@ class CannotRebuildShipments < StandardError; end belongs_to :store, class_name: 'Spree::Store' has_many :state_changes, as: :stateful has_many :line_items, -> { order(:created_at, :id) }, dependent: :destroy, inverse_of: :order - has_many :payments, dependent: :destroy + has_many :payments, dependent: :destroy, inverse_of: :order has_many :return_authorizations, dependent: :destroy, inverse_of: :order has_many :reimbursements, inverse_of: :order has_many :adjustments, -> { order(:created_at) }, as: :adjustable, inverse_of: :adjustable, dependent: :destroy diff --git a/core/app/models/spree/order_capturing.rb b/core/app/models/spree/order_capturing.rb index bd5c5222a68..3868bb3fc83 100644 --- a/core/app/models/spree/order_capturing.rb +++ b/core/app/models/spree/order_capturing.rb @@ -21,22 +21,15 @@ def capture_payments Spree::OrderMutex.with_lock!(@order) do uncaptured_amount = @order.display_total.cents - begin - sorted_payments(@order).each do |payment| - amount = [uncaptured_amount, payment.money.cents].min - - if amount > 0 - payment.capture!(amount) - uncaptured_amount -= amount - elsif Spree::OrderCapturing.void_unused_payments - payment.void_transaction! - end + sorted_payments(@order).each do |payment| + amount = [uncaptured_amount, payment.money.cents].min + + if amount > 0 + payment.capture!(amount) + uncaptured_amount -= amount + elsif Spree::OrderCapturing.void_unused_payments + payment.void_transaction! end - ensure - # 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 diff --git a/core/spec/models/spree/order_capturing_spec.rb b/core/spec/models/spree/order_capturing_spec.rb index a2980cc2d2f..77b59c5e842 100644 --- a/core/spec/models/spree/order_capturing_spec.rb +++ b/core/spec/models/spree/order_capturing_spec.rb @@ -4,8 +4,8 @@ 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. + # Regression for https://github.com/solidusio/solidus/pull/407 + # See also https://github.com/solidusio/solidus/pull/1406 context "updating the order" do let(:order) { create :completed_order_with_totals } let(:payment_methods) { [] } From e791145f1343ab625023e462c63c4e05a52ef06f Mon Sep 17 00:00:00 2001 From: Gregor MacDougall Date: Wed, 16 Nov 2016 09:48:26 -0500 Subject: [PATCH 2/4] Ensure that order is saved before spec This prevents the change hooks from being triggered twice. --- core/spec/models/spree/order_capturing_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/core/spec/models/spree/order_capturing_spec.rb b/core/spec/models/spree/order_capturing_spec.rb index 77b59c5e842..362f204121c 100644 --- a/core/spec/models/spree/order_capturing_spec.rb +++ b/core/spec/models/spree/order_capturing_spec.rb @@ -14,6 +14,7 @@ before do payment.pend! + order.save! allow_any_instance_of(Spree::Order).to receive(:thingamajig) do |order| changes_spy.change_callback_occured if order.changes.any? From 96569cf313efdb02de1a74639c5349a3891dd388 Mon Sep 17 00:00:00 2001 From: Brian Buchalter Date: Wed, 16 Nov 2016 13:53:32 -0400 Subject: [PATCH 3/4] Only run core,backend,api builds for CircleCI Tommy John is not using these other parts of Solidus, so there is no need to run them in our fork. --- build-ci.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-ci.rb b/build-ci.rb index 800d08ba3fa..4d3092cf134 100755 --- a/build-ci.rb +++ b/build-ci.rb @@ -20,7 +20,7 @@ def initialize(name) @name = name end - ALL = %w[api backend core frontend sample].map(&method(:new)).freeze + ALL = %w[api backend core].map(&method(:new)).freeze # Install subproject # From a5aa679cab70925b6ae0f4bdf89686f5580c6eca Mon Sep 17 00:00:00 2001 From: Brian Buchalter Date: Wed, 16 Nov 2016 13:56:30 -0400 Subject: [PATCH 4/4] Update circle.yml to better reflect TJ environment We use MySQL instead of Postgres and Ruby 2.2.5. --- circle.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index b387c066899..8fc50cd8afc 100644 --- a/circle.yml +++ b/circle.yml @@ -1,11 +1,11 @@ --- machine: environment: - DB: postgresql + DB: mysql services: - - postgresql + - mysql ruby: - version: 2.1.5 + version: 2.2.5 dependencies: override: - bundle check --path=vendor/bundle || bundle install --path=vendor/bundle