Skip to content

Commit

Permalink
Destroy wallet payment source when source gets deleted
Browse files Browse the repository at this point in the history
A wallet payment source without an actual payment source
does not make any sense.
  • Loading branch information
tvdeyen committed Aug 27, 2024
1 parent fae8b0d commit 6391ff2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/app/models/spree/payment_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class PaymentSource < Spree::Base
has_many :wallet_payment_sources,
class_name: 'Spree::WalletPaymentSource',
as: :payment_source,
inverse_of: :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 6391ff2

Please sign in to comment.