-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add make_default method on AddPaymentSourcesToWallet class
Move the logic to make the last payment source as default outside the add_to_wallet method to take advantage if someone wants to change only the make default behavior.
- Loading branch information
1 parent
69e6932
commit 44e5e20
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
core/spec/models/spree/wallet/add_payment_sources_to_wallet_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Spree::Wallet::AddPaymentSourcesToWallet, type: :model do | ||
let(:order) { create(:order_ready_to_complete) } | ||
|
||
describe '#add_to_wallet' do | ||
subject { described_class.new(order) } | ||
|
||
it 'saves the payment source and calls make_default' do | ||
expect(subject).to receive(:make_default) | ||
subject.add_to_wallet | ||
expect(order.user.wallet.wallet_payment_sources.count).to eq(1) | ||
end | ||
end | ||
|
||
describe '#make_default' do | ||
subject(:call) { -> { described_class.new(order).make_default } } | ||
|
||
let(:payment) { create(:payment) } | ||
|
||
before do | ||
order.user.wallet.add(payment.source) | ||
end | ||
|
||
it 'makes the user payment source as default' do | ||
subject.call | ||
expect(order.user.wallet.wallet_payment_sources.any?(&:default)).to be_truthy | ||
end | ||
end | ||
end |