Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy wallet payment source on source destroy #5836

Merged
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
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
Loading