diff --git a/Gemfile b/Gemfile index 95701f8e06..258cb99cc2 100644 --- a/Gemfile +++ b/Gemfile @@ -4,15 +4,15 @@ source 'https://rubygems.org' ruby "2.5.9" git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" } -gem 'rails', '~> 5.2' +gem 'rails', '~> 6.0.3.6' gem 'activemerchant', '>= 1.78.0' gem 'angular-rails-templates', '>= 0.3.0' gem 'awesome_nested_set' gem 'ransack', '2.4.1' gem 'responders' -gem 'sass', '<= 4.7.1' -gem 'sass-rails', '< 6.0.0' +gem 'sass', '~> 3.4.0' # this restriction originates from foundation-rails's version +gem 'sass-rails', '< 5.1.0' # this restriction originates from the compass-rails's version gem 'i18n' gem 'i18n-js', '~> 3.8.3' @@ -20,8 +20,8 @@ gem 'rails-i18n' gem 'rails_safe_tasks', '~> 1.0' gem "activerecord-import" -gem "db2fog", github: "openfoodfoundation/db2fog", branch: "rails-5" -gem "fog-aws", ">= 0.6.0" +gem "db2fog", github: "openfoodfoundation/db2fog", branch: "rails-6" +gem "fog-aws", "~> 2.0" # db2fog does not support v3 gem "catalog", path: "./engines/catalog" gem 'dfc_provider', path: './engines/dfc_provider' @@ -79,7 +79,7 @@ gem 'paper_trail', '~> 10.3.1' gem 'paperclip', '~> 3.4.1' gem 'rack-rewrite' gem 'rack-ssl', require: 'rack/ssl' -gem 'roadie-rails', '~> 2.2.0' +gem 'roadie-rails' gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis'] gem 'hiredis' @@ -113,6 +113,9 @@ gem 'jquery-migrate-rails' gem 'jquery-rails', '4.4.0' gem 'jquery-ui-rails', '~> 4.2' gem 'select2-rails', '~> 3.4.7' +# Thor v0.20 works with both select2-rails 3.4.7 and railties 6.0.3.6 +# To upgrade to thor v1 we need to upgrade select2-rails to v3.5 which requires some work +gem 'thor', '~> 0.20' gem 'ofn-qz', github: 'openfoodfoundation/ofn-qz', branch: 'ofn-rails-4' diff --git a/Gemfile.lock b/Gemfile.lock index fe41d56b46..9c9c422d4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,13 +6,13 @@ GIT GIT remote: https://github.com/openfoodfoundation/db2fog.git - revision: 8ceef362c64e6573d62d26db5ebb0c0f33cd3d61 - branch: rails-5 + revision: 5b63343847452f52aa42f7fc169d6ab3af57cda3 + branch: rails-6 specs: - db2fog (0.9.1) - activerecord (>= 3.2.0, < 6.0) + db2fog (0.9.2) + activerecord (>= 3.2.0, < 7.0) fog-core (~> 1.0) - rails (>= 3.2.0, < 6.0) + rails (>= 3.2.0, < 7.0) GIT remote: https://github.com/openfoodfoundation/ofn-qz.git @@ -48,47 +48,61 @@ GEM remote: https://rubygems.org/ specs: Ascii85 (1.1.0) - actioncable (5.2.6) - actionpack (= 5.2.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) + actioncable (6.0.3.6) + actionpack (= 6.0.3.6) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.0.3.6) + actionpack (= 6.0.3.6) + activejob (= 6.0.3.6) + activerecord (= 6.0.3.6) + activestorage (= 6.0.3.6) + activesupport (= 6.0.3.6) + mail (>= 2.7.1) + actionmailer (6.0.3.6) + actionpack (= 6.0.3.6) + actionview (= 6.0.3.6) + activejob (= 6.0.3.6) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.6) - actionview (= 5.2.6) - activesupport (= 5.2.6) + actionpack (6.0.3.6) + actionview (= 6.0.3.6) + activesupport (= 6.0.3.6) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) + rails-html-sanitizer (~> 1.0, >= 1.2.0) actionpack-action_caching (1.2.2) actionpack (>= 4.0.0) - actionview (5.2.6) - activesupport (= 5.2.6) + actiontext (6.0.3.6) + actionpack (= 6.0.3.6) + activerecord (= 6.0.3.6) + activestorage (= 6.0.3.6) + activesupport (= 6.0.3.6) + nokogiri (>= 1.8.5) + actionview (6.0.3.6) + activesupport (= 6.0.3.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) active_model_serializers (0.8.4) activemodel (>= 3.0) - activejob (5.2.6) - activesupport (= 5.2.6) + activejob (6.0.3.6) + activesupport (= 6.0.3.6) globalid (>= 0.3.6) activemerchant (1.119.0) activesupport (>= 4.2) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) nokogiri (~> 1.4) - activemodel (5.2.6) - activesupport (= 5.2.6) - activerecord (5.2.6) - activemodel (= 5.2.6) - activesupport (= 5.2.6) - arel (>= 9.0) + activemodel (6.0.3.6) + activesupport (= 6.0.3.6) + activerecord (6.0.3.6) + activemodel (= 6.0.3.6) + activesupport (= 6.0.3.6) activerecord-import (1.1.0) activerecord (>= 3.2) activerecord-postgresql-adapter (0.0.1) @@ -99,15 +113,17 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 2.0.8, < 3) railties (>= 5.2.4.1) - activestorage (5.2.6) - actionpack (= 5.2.6) - activerecord (= 5.2.6) + activestorage (6.0.3.6) + actionpack (= 6.0.3.6) + activejob (= 6.0.3.6) + activerecord (= 6.0.3.6) marcel (~> 1.0.0) - activesupport (5.2.6) + activesupport (6.0.3.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) acts-as-taggable-on (7.0.0) activerecord (>= 5.0, < 6.2) acts_as_list (1.0.4) @@ -124,7 +140,6 @@ GEM railties (>= 3, < 7) angularjs-file-upload-rails (2.4.1) angularjs-rails (1.5.5) - arel (9.0.0) ast (2.4.2) awesome_nested_set (3.4.0) activerecord (>= 4.0.0, < 7.0) @@ -225,18 +240,22 @@ GEM erubi (1.10.0) et-orbi (1.2.4) tzinfo - excon (0.79.0) + excon (0.81.0) execjs (2.7.0) factory_bot (6.2.0) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faraday (1.3.0) + faraday (1.4.1) + faraday-excon (~> 1.1) faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.1) multipart-post (>= 1.2, < 3) - ruby2_keywords + ruby2_keywords (>= 0.0.4) + faraday-excon (1.1.0) faraday-net_http (1.0.1) + faraday-net_http_persistent (1.1.0) ffaker (2.18.0) ffi (1.15.0) figaro (1.2.0) @@ -330,11 +349,11 @@ GEM kgio (2.11.3) knapsack (1.22.0) rake - launchy (2.4.3) - addressable (~> 2.3) + launchy (2.5.0) + addressable (~> 2.7) letter_opener (1.7.0) launchy (~> 2.2) - libv8-node (15.14.0.0) + libv8-node (15.14.0.1) loofah (2.9.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -344,7 +363,7 @@ GEM method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2020.1104) + mime-types-data (3.2021.0225) mimemagic (0.4.3) nokogiri (~> 1) rake @@ -399,12 +418,12 @@ GEM ttfunk pg (1.2.3) power_assert (2.0.0) - pry (0.13.1) + pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.9.0) + pry-byebug (3.8.0) byebug (~> 11.0) - pry (~> 0.13.0) + pry (~> 0.10) public_suffix (4.0.6) raabro (1.4.0) racc (1.5.2) @@ -418,18 +437,20 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.6) - actioncable (= 5.2.6) - actionmailer (= 5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - activemodel (= 5.2.6) - activerecord (= 5.2.6) - activestorage (= 5.2.6) - activesupport (= 5.2.6) + rails (6.0.3.6) + actioncable (= 6.0.3.6) + actionmailbox (= 6.0.3.6) + actionmailer (= 6.0.3.6) + actionpack (= 6.0.3.6) + actiontext (= 6.0.3.6) + actionview (= 6.0.3.6) + activejob (= 6.0.3.6) + activemodel (= 6.0.3.6) + activerecord (= 6.0.3.6) + activestorage (= 6.0.3.6) + activesupport (= 6.0.3.6) bundler (>= 1.3.0) - railties (= 5.2.6) + railties (= 6.0.3.6) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -440,16 +461,16 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails-i18n (5.1.3) + rails-i18n (6.0.0) i18n (>= 0.7, < 2) - railties (>= 5.0, < 6) + railties (>= 6.0.0, < 7) rails_safe_tasks (1.0.0) - railties (5.2.6) - actionpack (= 5.2.6) - activesupport (= 5.2.6) + railties (6.0.3.6) + actionpack (= 6.0.3.6) + activesupport (= 6.0.3.6) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.0.0) raindrops (0.19.1) rake (13.0.3) @@ -457,7 +478,7 @@ GEM activerecord (>= 5.2.4) activesupport (>= 5.2.4) i18n - rb-fsevent (0.10.4) + rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) redcarpet (3.5.1) @@ -531,13 +552,13 @@ GEM rubocop (>= 1.7.0, < 2.0) ruby-progressbar (1.11.0) ruby-rc4 (0.1.5) - ruby2_keywords (0.0.2) + ruby2_keywords (0.0.4) rubyzip (2.3.0) rufus-scheduler (3.7.0) fugit (~> 1.1, >= 1.1.6) sass (3.4.25) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.0.8) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) @@ -566,7 +587,7 @@ GEM simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) - simplecov_json_formatter (0.1.2) + simplecov_json_formatter (0.1.3) spring (2.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) @@ -585,7 +606,7 @@ GEM activerecord (>= 5.1) state_machines-activemodel (>= 0.8.0) stringex (2.8.5) - stripe (5.30.0) + stripe (5.32.1) temple (0.8.2) test-prof (1.0.5) test-unit (3.4.2) @@ -611,7 +632,7 @@ GEM unicorn-worker-killer (0.4.5) get_process_mem (~> 0) unicorn (>= 4, < 7) - uniform_notifier (1.14.1) + uniform_notifier (1.14.2) view_component (2.32.0) activesupport (>= 5.0.0, < 7.0) view_component_storybook (0.8.0) @@ -637,6 +658,7 @@ GEM xml-simple (1.1.8) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.4.2) PLATFORMS ruby @@ -686,7 +708,7 @@ DEPENDENCIES flipper flipper-active_record flipper-ui - fog-aws (>= 0.6.0) + fog-aws (~> 2.0) foundation-icons-sass-rails foundation-rails (= 5.5.2.1) fuubar (~> 2.5.1) @@ -725,7 +747,7 @@ DEPENDENCIES rack-mini-profiler (< 3.0.0) rack-rewrite rack-ssl - rails (~> 5.2) + rails (~> 6.0.3.6) rails-controller-testing rails-i18n rails_safe_tasks (~> 1.0) @@ -733,15 +755,15 @@ DEPENDENCIES redcarpet redis (>= 4.0) responders - roadie-rails (~> 2.2.0) + roadie-rails roo (~> 2.8.3) rspec-rails (>= 3.5.2) rspec-retry rswag rubocop rubocop-rails - sass (<= 4.7.1) - sass-rails (< 6.0.0) + sass (~> 3.4.0) + sass-rails (< 5.1.0) select2-rails (~> 3.4.7) selenium-webdriver shoulda-matchers @@ -755,6 +777,7 @@ DEPENDENCIES stripe test-prof test-unit (~> 3.4) + thor (~> 0.20) timecop uglifier (>= 1.0.3) unicorn-rails diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index e18aaf6ab3..ecbcc83c37 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -152,7 +152,7 @@ %th.final_weight_volume{ 'ng-show' => 'columns.final_weight_volume.visible' } = t("admin.orders.bulk_management.weight_volume") %th.price{ 'ng-show' => 'columns.price.visible' } - = "#{t('admin.price')} (#{currency_symbol})" + = "#{t('admin.price')} (#{Spree::Money.currency_symbol})" %th.actions %th.actions = t("admin.orders.bulk_management.ask") diff --git a/config/application.rb b/config/application.rb index b3718d016d..c4f609a4a4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,25 @@ require_relative 'boot' -require 'rails/all' +require "rails" +[ + "active_record/railtie", + #"active_storage/engine", + "action_controller/railtie", + "action_view/railtie", + "action_mailer/railtie", + "active_job/railtie", + #"action_cable/engine", # Enable this when installing StimulusReflex + #"action_mailbox/engine", + #"action_text/engine", + "rails/test_unit/railtie", + "sprockets/railtie" # Disable this after migrating to Webpacker +].each do |railtie| + begin + require railtie + rescue LoadError + end +end + require_relative "../lib/open_food_network/i18n_config" require_relative '../lib/spree/core/environment' diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 5a101fbe4d..dac38f44c7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -40,7 +40,7 @@ Devise.setup do |config| config.stretches = Rails.env.test? ? 1 : 20 # Setup a pepper to generate the encrypted password. - config.pepper = Rails.configuration.secret_token + config.pepper = Rails.configuration.secret_key_base # ==> Configuration for :confirmable # The time you want to give your user to confirm his account. During this time diff --git a/lib/spree/core.rb b/lib/spree/core.rb index cdf1ff4b2a..6cdbf40416 100644 --- a/lib/spree/core.rb +++ b/lib/spree/core.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'rails/all' require 'active_merchant' require 'acts_as_list' require 'awesome_nested_set' 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/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index b1c561ce16..78f0459110 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' describe Spree::OrdersController, type: :controller do include OpenFoodNetwork::EmailHelper include CheckoutHelper + include StripeStubs let(:distributor) { double(:distributor) } let(:order) { create(:order) } @@ -163,7 +164,7 @@ describe Spree::OrdersController, type: :controller do it "does not complete the payment" do get :show, params: { id: order.number, payment_intent: payment_intent } - expect(response).to be_success + expect(response.status).to eq 200 expect(flash[:error]).to eq("#{I18n.t("payment_could_not_process")}. error message") payment.reload expect(payment.cvv_response_message).to eq("https://stripe.com/redirect") @@ -178,11 +179,11 @@ describe Spree::OrdersController, type: :controller do before do allow(payment).to receive(:response_code).and_return("invalid") allow(OrderPaymentFinder).to receive(:new).with(order).and_return(finder) - allow_any_instance_of(Stripe::PaymentIntentValidator) .to receive(:call) .with(payment_intent, kind_of(String)) .and_return(payment_intent) + stub_payment_intent_get_request(payment_intent_id: "valid") end it "does not complete the payment" do 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 diff --git a/spec/support/request/stripe_stubs.rb b/spec/support/request/stripe_stubs.rb index ff1f616871..637c8b7ab7 100644 --- a/spec/support/request/stripe_stubs.rb +++ b/spec/support/request/stripe_stubs.rb @@ -14,8 +14,8 @@ module StripeStubs .to_return(payment_intent_redirect_response_mock(redirect_url)) end - def stub_payment_intent_get_request(response: {}, stripe_account_header: true) - stub = stub_request(:get, "https://api.stripe.com/v1/payment_intents/pi_123") + def stub_payment_intent_get_request(response: {}, stripe_account_header: true, payment_intent_id: "pi_123") + stub = stub_request(:get, "https://api.stripe.com/v1/payment_intents/#{payment_intent_id}") stub = stub.with(headers: { 'Stripe-Account' => 'abc123' }) if stripe_account_header stub.to_return(payment_intent_authorize_response_mock(response)) end @@ -37,7 +37,6 @@ module StripeStubs def stub_retrieve_payment_method_request(payment_method_id = "pm_1234") stub_request(:get, "https://api.stripe.com/v1/payment_methods/#{payment_method_id}") - .with(headers: { 'Authorization' => 'Bearer sk_test_12345' }) .to_return(retrieve_payment_method_response_mock({})) end @@ -52,7 +51,7 @@ module StripeStubs def stub_list_customers_request(email:, response: {}) stub = stub_request(:get, "https://api.stripe.com/v1/customers?email=#{email}&limit=100") stub = stub.with( - headers: { 'Authorization' => 'Bearer sk_test_12345', 'Stripe-Account' => 'abc123' } + headers: { 'Stripe-Account' => 'abc123' } ) stub.to_return(list_customers_response_mock(response)) end @@ -62,7 +61,7 @@ module StripeStubs :get, "https://api.stripe.com/v1/payment_methods?customer=#{customer}&limit=100&type=card" ) stub = stub.with( - headers: { 'Authorization' => 'Bearer sk_test_12345', 'Stripe-Account' => 'abc123' } + headers: { 'Stripe-Account' => 'abc123' } ) stub.to_return(get_customer_payment_methods_response_mock(response)) end @@ -71,7 +70,7 @@ module StripeStubs stub = stub_request(:post, "https://api.stripe.com/v1/payment_methods/#{payment_method}") stub = stub.with(body: { metadata: { "ofn-clone": true } }) stub = stub.with( - headers: { 'Authorization' => 'Bearer sk_test_12345', 'Stripe-Account' => 'abc123' } + headers: { 'Stripe-Account' => 'abc123' } ) stub.to_return(add_metadata_response_mock(response)) end