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 assigning nil to default_wallet_payment_source= #1896

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
2 changes: 1 addition & 1 deletion core/app/models/spree/wallet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def default_wallet_payment_source=(wallet_payment_source)
return
end

wallet_payment_source.transaction do
Spree::WalletPaymentSource.transaction do
# Unset old default
default_wallet_payment_source.try!(:update!, default: false)
# Set new default
Expand Down
47 changes: 30 additions & 17 deletions core/spec/models/spree/wallet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,45 @@
to(wallet_credit_card)
)
end

context "assigning nil" do
it "remains unset" do
expect(subject.default_wallet_payment_source).to be_nil
subject.default_wallet_payment_source = nil
expect(subject.default_wallet_payment_source).to be_nil
end
end
end

context "with other payment source already default" do
context "with a default" do
let!(:wallet_credit_card) { subject.add(credit_card) }
let!(:wallet_store_credit) { subject.add(store_credit) }

before { subject.default_wallet_payment_source = wallet_credit_card }

it "sets the new payment source as the default" do
expect { subject.default_wallet_payment_source = wallet_store_credit }.to(
change(subject, :default_wallet_payment_source).
from(wallet_credit_card).
to(wallet_store_credit)
)
end
end
context "assigning a new default" do
let!(:wallet_store_credit) { subject.add(store_credit) }

context "with the same payment source already set to default" do
let!(:wallet_credit_card) { subject.add(credit_card) }
it "sets the new payment source as the default" do
expect {
subject.default_wallet_payment_source = wallet_store_credit
}.to change{ subject.default_wallet_payment_source }.from(wallet_credit_card).to(wallet_store_credit)
end
end

before { subject.default_wallet_payment_source = wallet_credit_card }
context "assigning same default" do
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

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)
)
context "assigning nil" do
it "clears the default payment source" do
expect {
subject.default_wallet_payment_source = nil
}.to change{ subject.default_wallet_payment_source }.to nil
end
end
end

Expand Down