From b3e08b47b961f7561b58e4d81670b4cf9ec065b2 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sat, 8 May 2021 10:57:39 -0700 Subject: [PATCH] set Stripe api key directly instead of using `allow` --- spec/controllers/admin/stripe_accounts_controller_spec.rb | 4 ++-- .../admin/stripe_connect_settings_controller_spec.rb | 4 ++-- spec/controllers/checkout_controller_spec.rb | 2 +- .../orders/payments/payments_controller_refunds_spec.rb | 8 ++++---- spec/controllers/spree/credit_cards_controller_spec.rb | 2 +- spec/features/admin/payment_method_spec.rb | 2 +- spec/features/consumer/account/cards_spec.rb | 4 ++-- spec/helpers/enterprises_helper_spec.rb | 2 +- spec/lib/stripe/account_connector_spec.rb | 2 +- spec/lib/stripe/credit_card_cloner_spec.rb | 2 +- spec/lib/stripe/payment_intent_validator_spec.rb | 2 +- spec/lib/stripe/profile_storer_spec.rb | 2 +- spec/models/spree/gateway/stripe_connect_spec.rb | 2 +- spec/models/spree/gateway/stripe_sca_spec.rb | 2 +- spec/models/stripe_account_spec.rb | 4 ++-- spec/requests/checkout/stripe_connect_spec.rb | 2 +- spec/requests/checkout/stripe_sca_spec.rb | 2 +- spec/support/request/stripe_helper.rb | 4 ++-- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/spec/controllers/admin/stripe_accounts_controller_spec.rb b/spec/controllers/admin/stripe_accounts_controller_spec.rb index bca1d2444e..11478c9b34 100644 --- a/spec/controllers/admin/stripe_accounts_controller_spec.rb +++ b/spec/controllers/admin/stripe_accounts_controller_spec.rb @@ -6,7 +6,7 @@ describe Admin::StripeAccountsController, type: :controller do let(:enterprise) { create(:distributor_enterprise) } before do - allow(Stripe).to receive(:client_id) { "some_id" } + Stripe.client_id = "some_id" end describe "#connect" do @@ -86,7 +86,7 @@ describe Admin::StripeAccountsController, type: :controller do end before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" Spree::Config.set(stripe_connect_enabled: false) end diff --git a/spec/controllers/admin/stripe_connect_settings_controller_spec.rb b/spec/controllers/admin/stripe_connect_settings_controller_spec.rb index fe671dc666..22819c43e7 100644 --- a/spec/controllers/admin/stripe_connect_settings_controller_spec.rb +++ b/spec/controllers/admin/stripe_connect_settings_controller_spec.rb @@ -30,7 +30,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do context "when a Stripe API key is not set" do before do - allow(Stripe).to receive(:api_key) { nil } + Stripe.api_key = nil end it "sets the account status to :empty_api_key_error_html" do @@ -42,7 +42,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do context "when a Stripe API key is set" do before do - allow(Stripe).to receive(:api_key) { "sk_test_xxxx" } + Stripe.api_key = "sk_test_xxxx" end context "and the request to retrieve Stripe account info fails" do diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index f52d901b74..3f12646288 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -153,7 +153,7 @@ describe CheckoutController, type: :controller do } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_payment_intent_get_request stub_successful_capture_request(order: order) diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb index e7ec842625..00c550b787 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_refunds_spec.rb @@ -31,7 +31,7 @@ describe Spree::Admin::PaymentsController, type: :controller do end before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" end context "where the request succeeds" do @@ -90,7 +90,7 @@ describe Spree::Admin::PaymentsController, type: :controller do end before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" end context "where the request succeeds" do @@ -152,7 +152,7 @@ describe Spree::Admin::PaymentsController, type: :controller do let(:stripe_account) { create(:stripe_account, enterprise: shop) } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" allow(StripeAccount).to receive(:find_by) { stripe_account } end @@ -236,7 +236,7 @@ describe Spree::Admin::PaymentsController, type: :controller do end before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_payment_intent_get_request stripe_account_header: false end diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index 867fe89861..d256c95479 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -7,7 +7,7 @@ describe Spree::CreditCardsController, type: :controller do let(:token) { "tok_234bd2c22" } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" allow(controller).to receive(:spree_current_user) { user } end diff --git a/spec/features/admin/payment_method_spec.rb b/spec/features/admin/payment_method_spec.rb index e45cfef67b..38ffa8b960 100644 --- a/spec/features/admin/payment_method_spec.rb +++ b/spec/features/admin/payment_method_spec.rb @@ -47,7 +47,7 @@ feature ' before do Spree::Config.set(stripe_connect_enabled: true) - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_request(:get, "https://api.stripe.com/v1/accounts/acc_connected123").to_return(body: JSON.generate(stripe_account_mock)) stub_request(:get, "https://api.stripe.com/v1/accounts/acc_revoked123").to_return(status: 404) end diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb index d2f6b673dd..606fc08e9f 100644 --- a/spec/features/consumer/account/cards_spec.rb +++ b/spec/features/consumer/account/cards_spec.rb @@ -22,8 +22,8 @@ feature "Credit Cards", js: true do before do login_as user - allow(Stripe).to receive(:api_key) { "sk_test_12345" } - allow(Stripe).to receive(:publishable_key) { "some_token" } + Stripe.api_key = "sk_test_12345" + Stripe.publishable_key = "some_token" Spree::Config.set(stripe_connect_enabled: true) stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ"). diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb index 22e7decd57..b8e6fb19b6 100644 --- a/spec/helpers/enterprises_helper_spec.rb +++ b/spec/helpers/enterprises_helper_spec.rb @@ -266,7 +266,7 @@ describe EnterprisesHelper, type: :helper do before do Spree::Config.set(stripe_connect_enabled: true) - allow(Stripe).to receive(:publishable_key) { "some_key" } + Stripe.publishable_key = "some_key" end it "includes Stripe payment methods with a valid stripe accounts" do diff --git a/spec/lib/stripe/account_connector_spec.rb b/spec/lib/stripe/account_connector_spec.rb index 200485e840..54c5091150 100644 --- a/spec/lib/stripe/account_connector_spec.rb +++ b/spec/lib/stripe/account_connector_spec.rb @@ -15,7 +15,7 @@ module Stripe let(:connector) { AccountConnector.new(user, params) } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" end context "when the connection was cancelled by the user" do diff --git a/spec/lib/stripe/credit_card_cloner_spec.rb b/spec/lib/stripe/credit_card_cloner_spec.rb index 62584f8313..1e80849873 100644 --- a/spec/lib/stripe/credit_card_cloner_spec.rb +++ b/spec/lib/stripe/credit_card_cloner_spec.rb @@ -24,7 +24,7 @@ module Stripe } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_customers_post_request email: credit_card.user.email, response: { customer_id: new_customer_id }, diff --git a/spec/lib/stripe/payment_intent_validator_spec.rb b/spec/lib/stripe/payment_intent_validator_spec.rb index efebbb6577..81a730ab2a 100644 --- a/spec/lib/stripe/payment_intent_validator_spec.rb +++ b/spec/lib/stripe/payment_intent_validator_spec.rb @@ -12,7 +12,7 @@ module Stripe let(:payment_intent_response_mock) { { status: 200, body: payment_intent_response_body } } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") .with(headers: { 'Stripe-Account' => stripe_account_id }) diff --git a/spec/lib/stripe/profile_storer_spec.rb b/spec/lib/stripe/profile_storer_spec.rb index 73c7d71af2..d23ed84e95 100644 --- a/spec/lib/stripe/profile_storer_spec.rb +++ b/spec/lib/stripe/profile_storer_spec.rb @@ -14,7 +14,7 @@ module Stripe let(:customer_response_mock) { { status: 200, body: customer_response_body } } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" stub_request(:post, "https://api.stripe.com/v1/customers") .with(basic_auth: ["sk_test_12345", ""], body: { email: payment.order.email }) diff --git a/spec/models/spree/gateway/stripe_connect_spec.rb b/spec/models/spree/gateway/stripe_connect_spec.rb index c6621b9343..4f5793f551 100644 --- a/spec/models/spree/gateway/stripe_connect_spec.rb +++ b/spec/models/spree/gateway/stripe_connect_spec.rb @@ -15,7 +15,7 @@ describe Spree::Gateway::StripeConnect, type: :model do let(:stripe_account_id) { "acct_123" } before do - allow(Stripe).to receive(:api_key) { "sk_test_123456" } + Stripe.api_key = "sk_test_123456" allow(subject).to receive(:stripe_account_id) { stripe_account_id } allow(subject).to receive(:options_for_purchase_or_auth).and_return(['money', 'cc', 'opts']) allow(subject).to receive(:provider).and_return provider diff --git a/spec/models/spree/gateway/stripe_sca_spec.rb b/spec/models/spree/gateway/stripe_sca_spec.rb index 3eea62c02d..ef4216240d 100644 --- a/spec/models/spree/gateway/stripe_sca_spec.rb +++ b/spec/models/spree/gateway/stripe_sca_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Spree::Gateway::StripeSCA, type: :model do - before { allow(Stripe).to receive(:api_key) { "sk_test_12345" } } + before { Stripe.api_key = "sk_test_12345" } describe "#purchase" do let(:order) { create(:order_with_totals_and_distribution) } diff --git a/spec/models/stripe_account_spec.rb b/spec/models/stripe_account_spec.rb index bade785a46..75595d3142 100644 --- a/spec/models/stripe_account_spec.rb +++ b/spec/models/stripe_account_spec.rb @@ -12,8 +12,8 @@ describe StripeAccount do let!(:stripe_account) { create(:stripe_account, enterprise: enterprise, stripe_user_id: stripe_user_id) } before do - allow(Stripe).to receive(:api_key) { "sk_test_12345" } - allow(Stripe).to receive(:client_id) { client_id } + Stripe.api_key = "sk_test_12345" + Stripe.client_id = client_id end context "when the Stripe API disconnect fails" do diff --git a/spec/requests/checkout/stripe_connect_spec.rb b/spec/requests/checkout/stripe_connect_spec.rb index 9a01b28511..4c7fe894ac 100644 --- a/spec/requests/checkout/stripe_connect_spec.rb +++ b/spec/requests/checkout/stripe_connect_spec.rb @@ -68,7 +68,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re allow(OrderCycleDistributedVariants).to receive(:new) { order_cycle_distributed_variants } allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true } - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order diff --git a/spec/requests/checkout/stripe_sca_spec.rb b/spec/requests/checkout/stripe_sca_spec.rb index 5b1df19196..14a825e459 100644 --- a/spec/requests/checkout/stripe_sca_spec.rb +++ b/spec/requests/checkout/stripe_sca_spec.rb @@ -87,7 +87,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques allow(OrderCycleDistributedVariants).to receive(:new) { order_cycle_distributed_variants } allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true } - allow(Stripe).to receive(:api_key) { "sk_test_12345" } + Stripe.api_key = "sk_test_12345" order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order diff --git a/spec/support/request/stripe_helper.rb b/spec/support/request/stripe_helper.rb index ef552a0586..0c6e7da8e6 100644 --- a/spec/support/request/stripe_helper.rb +++ b/spec/support/request/stripe_helper.rb @@ -30,8 +30,8 @@ module StripeHelper end def setup_stripe - allow(Stripe).to receive(:api_key) { "sk_test_12345" } - allow(Stripe).to receive(:publishable_key) { "pk_test_12345" } + Stripe.api_key = "sk_test_12345" + Stripe.publishable_key = "pk_test_12345" Spree::Config.set(stripe_connect_enabled: true) end end