Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

[SD-1331] Assign Store to Payment Method factory (#11063)

Łukasz Adamczyka037f916d4ed
diff --git a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
index ca0f3edea5..e29b206991 100644
--- a/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/checkout_spec.rb
@@ -224,7 +224,7 @@ describe 'API V2 Storefront Checkout Spec', type: :request do
let!(:stock_location) { create(:stock_location) }
let!(:shipping_method) { create(:shipping_method, zones: [country_zone]) }
- let!(:payment_method) { create(:credit_card_payment_method) }
+ let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }
let(:execute) { patch '/api/v2/storefront/checkout', params: params, headers: headers }
@@ -545,7 +545,7 @@ describe 'API V2 Storefront Checkout Spec', type: :request do
describe 'checkout#payment_methods' do
let(:execute) { get '/api/v2/storefront/checkout/payment_methods', headers: headers }
- let!(:payment_method) { create(:credit_card_payment_method) }
+ let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }
let(:payment_methods) { order.available_payment_methods }
shared_examples 'returns a list of available payment methods' do
diff --git a/core/lib/spree/testing_support/factories/payment_method_factory.rb b/core/lib/spree/testing_support/factories/payment_method_factory.rb
index 2415d49c13..316c97222e 100644
--- a/core/lib/spree/testing_support/factories/payment_method_factory.rb
+++ b/core/lib/spree/testing_support/factories/payment_method_factory.rb
@@ -1,15 +1,28 @@
FactoryBot.define do
- factory :check_payment_method, class: Spree::PaymentMethod::Check do
+ factory :payment_method, class: Spree::PaymentMethod do
+ name { 'Test' }
+
+ before(:create) do |payment_method|
+ if payment_method.stores.empty?
+ default_store = Spree::Store.default.persisted? ? Spree::Store.default : nil
+ store = default_store || create(:store)
+
+ payment_method.stores << [store]
+ end
+ end
+ end
+
+ factory :check_payment_method, parent: :payment_method, class: Spree::PaymentMethod::Check do
name { 'Check' }
end
- factory :credit_card_payment_method, class: Spree::Gateway::Bogus do
+ factory :credit_card_payment_method, parent: :payment_method, class: Spree::Gateway::Bogus do
name { 'Credit Card' }
end
# authorize.net was moved to spree_gateway.
# Leaving this factory in place with bogus in case anyone is using it.
- factory :simple_credit_card_payment_method, class: Spree::Gateway::BogusSimple do
+ factory :simple_credit_card_payment_method, parent: :payment_method, class: Spree::Gateway::BogusSimple do
name { 'Credit Card' }
end