diff --git a/core/app/models/spree/wallet.rb b/core/app/models/spree/wallet.rb index 5f9b9dccff9..5449342a552 100644 --- a/core/app/models/spree/wallet.rb +++ b/core/app/models/spree/wallet.rb @@ -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 diff --git a/core/spec/models/spree/wallet_spec.rb b/core/spec/models/spree/wallet_spec.rb index 935f5206418..d5ba4a19aeb 100644 --- a/core/spec/models/spree/wallet_spec.rb +++ b/core/spec/models/spree/wallet_spec.rb @@ -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