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

Verify ownership of payment_source when creating WalletPaymentSource #3007

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Updated specs to respect payment owners
With the changes made to validate users cannot add payment sources
from other users to their wallet. Some of our specs were using and
adding payment sources created for other users to the wallet of the
user being tested.
  • Loading branch information
ericsaupe committed Jan 10, 2019
commit 28c66c8fcdbf7c8b274c29bd6a2abdc80f17517e
2 changes: 1 addition & 1 deletion backend/spec/features/admin/orders/payments_spec.rb
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@

context "user existing card" do
let!(:cc) do
create(:credit_card, payment_method: payment_method, gateway_customer_profile_id: "BGS-RFRE")
create(:credit_card, payment_method: payment_method, gateway_customer_profile_id: "BGS-RFRE", user: order.user)
end

before do
10 changes: 3 additions & 7 deletions core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
@@ -359,6 +359,7 @@ def assert_state_changed(order, from, to)

before do
user = create(:user, email: 'spree@example.org', bill_address: user_bill_address)
default_credit_card.update(user: user)
wallet_payment_source = user.wallet.add(default_credit_card)
user.wallet.default_wallet_payment_source = wallet_payment_source
order.user = user
@@ -497,12 +498,7 @@ def assert_state_changed(order, from, to)

context "with a payment in the pending state" do
let(:order) { create :order_ready_to_complete }
let(:payment) { create :payment, state: "pending", amount: order.total }

before do
order.payments = [payment]
order.save!
end
let(:payment) { create :payment, order: order, state: "pending", amount: order.total }

it "allows the order to complete" do
expect { order.complete! }.
@@ -542,7 +538,7 @@ def assert_state_changed(order, from, to)
order.user = FactoryBot.create(:user)
order.store = FactoryBot.create(:store)
order.email = 'spree@example.org'
order.payments << FactoryBot.create(:payment)
order.payments << FactoryBot.create(:payment, order: order)

# make sure we will actually capture a payment
allow(order).to receive_messages(payment_required?: true)
2 changes: 1 addition & 1 deletion core/spec/models/spree/wallet_spec.rb
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@
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_credit_card) { other_wallet.add(other_credit_card) }
let(:other_wallet) { Spree::Wallet.new(other_user) }
let(:other_credit_card) { create(:credit_card, user_id: other_user.id) }
let(:other_user) { create(:user) }