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

Fix setting the wallet's default payment source to the same value #1888

Merged
merged 3 commits into from
May 9, 2017
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
5 changes: 5 additions & 0 deletions core/app/models/spree/wallet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def default_wallet_payment_source=(wallet_payment_source)
raise Unauthorized, "wallet_payment_source #{wallet_payment_source.id} does not belong to wallet of user #{user.id}"
end

# Do not update the payment source if the passed source is already default
if default_wallet_payment_source == wallet_payment_source
return
end

wallet_payment_source.transaction do
# Unset old default
default_wallet_payment_source.try!(:update!, default: false)
Expand Down
12 changes: 12 additions & 0 deletions core/spec/models/spree/wallet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@
end
end

context "with the same payment source already set to default" do
let!(:wallet_credit_card) { subject.add(credit_card) }

before { subject.default_wallet_payment_source = wallet_credit_card }

it "does not change the default payment source" do
expect { subject.default_wallet_payment_source = wallet_credit_card }.not_to(
change(subject, :default_wallet_payment_source)
)
end
end

context 'with a wallet payment source that does not belong to the wallet' do
let(:other_wallet_credit_card) { other_wallet.add(credit_card) }
let(:other_wallet) { Spree::Wallet.new(other_user) }
Expand Down