Skip to content

Commit

Permalink
Merge pull request #5836 from tvdeyen/destroy-wallet-payment-source-o…
Browse files Browse the repository at this point in the history
…n-source-destroy

Destroy wallet payment source on source destroy
  • Loading branch information
tvdeyen authored Aug 29, 2024
2 parents 127d02c + 4ca261c commit 580da1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/app/models/spree/payment_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class PaymentSource < Spree::Base
belongs_to :payment_method, optional: true

has_many :payments, as: :source
has_many :wallet_payment_sources, class_name: 'Spree::WalletPaymentSource', as: :payment_source, inverse_of: :payment_source
has_many :wallet_payment_sources,
class_name: 'Spree::WalletPaymentSource',
as: :payment_source,
inverse_of: :payment_source,
dependent: :destroy

attr_accessor :imported

Expand Down
18 changes: 18 additions & 0 deletions core/spec/support/concerns/payment_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
it { is_expected.to respond_to(:user) }
end

describe "#wallet_payment_sources" do
let(:user) { create(:user) }

let!(:wallet_payment_source) do
# There are nasty validations that do not matter for this test
payment_source.save(validate: false)
Spree::WalletPaymentSource.new(user: user, payment_source: payment_source).tap do |wps|
wps.save(validate: false)
end
end

context "when the payment source gets destroyed" do
it "destroys the wallet payment source" do
expect { payment_source.destroy }.to change { Spree::WalletPaymentSource.count }.by(-1)
end
end
end

describe "#can_capture?" do
it "should be true if payment is pending" do
payment = mock_model(Spree::Payment, pending?: true, created_at: Time.current)
Expand Down

0 comments on commit 580da1d

Please sign in to comment.