From 79d0623aab2069b938fbbc7796b0e46e7eebfbe6 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 May 2023 17:17:37 +0200 Subject: [PATCH 01/10] Allow Solidus v4 --- solidus_stripe.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidus_stripe.gemspec b/solidus_stripe.gemspec index ea434af8..8fdf4323 100644 --- a/solidus_stripe.gemspec +++ b/solidus_stripe.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'solidus_core', ['>= 2.3', '< 4'] + spec.add_dependency 'solidus_core', ['>= 3', '< 5'] spec.add_dependency 'solidus_support', '~> 0.8' spec.add_dependency 'activemerchant', '>= 1.105' spec.add_dependency 'rexml' From 7c27878d7b1bf46261624b3266425b490fea2543 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 May 2023 17:27:27 +0200 Subject: [PATCH 02/10] Use a newer ruby version for linting --- .circleci/config.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 99d13624..5f2417c3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,15 +10,6 @@ orbs: # or goes EOL. solidusio_extensions: solidusio/extensions@volatile -executors: - sqlite: - description: Run specs with an SQLite - docker: - - image: cimg/ruby:2.7-browsers - environment: - RAILS_ENV: test - DB: sqlite - jobs: run-specs-with-postgres: executor: solidusio_extensions/postgres @@ -31,12 +22,14 @@ jobs: - browser-tools/install-chrome - solidusio_extensions/run-tests run-specs-with-sqlite: - executor: sqlite + executor: solidusio_extensions/sqlite steps: - browser-tools/install-chrome - solidusio_extensions/run-tests lint-code: - executor: solidusio_extensions/sqlite-memory + executor: + name: solidusio_extensions/sqlite-memory + ruby_version: "3.0" steps: - solidusio_extensions/lint-code From 5f9f0ac290a80a608853102e524d6c90e9da835c Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 11:47:16 +0200 Subject: [PATCH 03/10] Distribute solidus versions to different runners --- .circleci/config.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f2417c3..8e15596f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,20 +12,36 @@ orbs: jobs: run-specs-with-postgres: - executor: solidusio_extensions/postgres + executor: + name: solidusio_extensions/postgres + ruby_version: "3.0" steps: - browser-tools/install-chrome - - solidusio_extensions/run-tests + - checkout + - solidusio_extensions/dependencies + - solidusio_extensions/run-tests-solidus-main + - solidusio_extensions/store-test-results + run-specs-with-mysql: - executor: solidusio_extensions/mysql + executor: + name: solidusio_extensions/mysql + ruby_version: "3.0" steps: - browser-tools/install-chrome - - solidusio_extensions/run-tests + - checkout + - solidusio_extensions/dependencies + - solidusio_extensions/run-tests-solidus-current + - solidusio_extensions/store-test-results run-specs-with-sqlite: - executor: solidusio_extensions/sqlite + executor: + name: solidusio_extensions/sqlite + ruby_version: "2.7" steps: - browser-tools/install-chrome - - solidusio_extensions/run-tests + - checkout + - solidusio_extensions/dependencies + - solidusio_extensions/run-tests-solidus-older + - solidusio_extensions/store-test-results lint-code: executor: name: solidusio_extensions/sqlite-memory From 11017da9c8124494dcd18bda7ef58cc167a28ff7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 12:20:02 +0200 Subject: [PATCH 04/10] Don't mock AM::Billing::Response as it needs to be serialized --- .../create_intents_payment_service_spec.rb | 2 +- .../spree/payment_method/stripe_credit_card_spec.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/models/solidus_stripe/create_intents_payment_service_spec.rb b/spec/models/solidus_stripe/create_intents_payment_service_spec.rb index 4db47bf4..8c541a75 100644 --- a/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +++ b/spec/models/solidus_stripe/create_intents_payment_service_spec.rb @@ -102,7 +102,7 @@ end before do - response = double(success?: true, authorization: payment.response_code) + response = ActiveMerchant::Billing::Response.new(true, nil, {}, authorization: payment.response_code) allow_any_instance_of(Spree::PaymentMethod::StripeCreditCard).to receive(:void) { response } end diff --git a/spec/models/spree/payment_method/stripe_credit_card_spec.rb b/spec/models/spree/payment_method/stripe_credit_card_spec.rb index af3e1c8f..2bb21a02 100644 --- a/spec/models/spree/payment_method/stripe_credit_card_spec.rb +++ b/spec/models/spree/payment_method/stripe_credit_card_spec.rb @@ -262,10 +262,14 @@ end let!(:success_response) do - double('success_response', success?: true, - authorization: '123', - avs_result: { 'code' => 'avs-code' }, - cvv_result: { 'code' => 'cvv-code', 'message' => "CVV Result" }) + ActiveMerchant::Billing::Response.new( + true, + nil, + {}, + avs_result: { 'code' => 'avs-code' }, + cvv_result: 'cvv-code', + authorization: '123', + ) end after do From 56ce411e4117c04b8c21a456ee6da0cf3e50dd4d Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 12:37:18 +0200 Subject: [PATCH 05/10] Avoid using spree.root_path It's not available on new solidus versions. --- spec/features/stripe_checkout_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/stripe_checkout_spec.rb b/spec/features/stripe_checkout_spec.rb index e35ce99e..10a38855 100644 --- a/spec/features/stripe_checkout_spec.rb +++ b/spec/features/stripe_checkout_spec.rb @@ -23,7 +23,7 @@ FactoryBot.create(:product, name: "DL-44") - visit spree.root_path + visit '/' click_link "DL-44" click_button "Add To Cart" @@ -85,7 +85,7 @@ click_button "Place Order" expect(page).to have_content("Your order has been processed successfully") - visit spree.root_path + visit '/' click_link "DL-44" click_button "Add To Cart" @@ -207,7 +207,7 @@ click_button "Place Order" expect(page).to have_content("Your order has been processed successfully") - visit spree.root_path + visit '/' click_link "DL-44" click_button "Add To Cart" @@ -329,7 +329,7 @@ click_button "Place Order" expect(page).to have_content("Your order has been processed successfully") - visit spree.root_path + visit '/' click_link "DL-44" click_button "Add To Cart" From a52503abb5f7e7b663e03575f9f3628963f56d77 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 12:46:00 +0200 Subject: [PATCH 06/10] Use different ruby versions for different DBs Widen the number of ruby versions we test against. --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e15596f..20c845d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: run-specs-with-postgres: executor: name: solidusio_extensions/postgres - ruby_version: "3.0" + ruby_version: "3.2" steps: - browser-tools/install-chrome - checkout @@ -25,7 +25,7 @@ jobs: run-specs-with-mysql: executor: name: solidusio_extensions/mysql - ruby_version: "3.0" + ruby_version: "3.1" steps: - browser-tools/install-chrome - checkout @@ -35,7 +35,7 @@ jobs: run-specs-with-sqlite: executor: name: solidusio_extensions/sqlite - ruby_version: "2.7" + ruby_version: "3.0" steps: - browser-tools/install-chrome - checkout From 3e82cac94a65a86e70d10b29425ab15deb9ba74f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 13:34:33 +0200 Subject: [PATCH 07/10] Assume we'll run migrations in the CI --- lib/generators/solidus_stripe/install/install_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/solidus_stripe/install/install_generator.rb b/lib/generators/solidus_stripe/install/install_generator.rb index 59643de5..7a8f755d 100644 --- a/lib/generators/solidus_stripe/install/install_generator.rb +++ b/lib/generators/solidus_stripe/install/install_generator.rb @@ -14,7 +14,7 @@ def add_migrations end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength + run_migrations = options[:auto_run_migrations] || ENV['CI'] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength if run_migrations run 'bin/rails db:migrate' else From 5a257699f40f780e9fe4aa667c07ffdd2dfb005f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 13:37:13 +0200 Subject: [PATCH 08/10] Override the frontend app template for newer solidus --- .circleci/config.yml | 4 ++++ spec/solidus_frontend_app_template.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spec/solidus_frontend_app_template.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index 20c845d1..7eef5c85 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,8 @@ jobs: executor: name: solidusio_extensions/postgres ruby_version: "3.2" + environment: + FRONTEND: "/home/circleci/project/spec/solidus_frontend_app_template.rb" steps: - browser-tools/install-chrome - checkout @@ -26,6 +28,8 @@ jobs: executor: name: solidusio_extensions/mysql ruby_version: "3.1" + environment: + FRONTEND: "/home/circleci/project/spec/solidus_frontend_app_template.rb" steps: - browser-tools/install-chrome - checkout diff --git a/spec/solidus_frontend_app_template.rb b/spec/solidus_frontend_app_template.rb new file mode 100644 index 00000000..a3a3b21e --- /dev/null +++ b/spec/solidus_frontend_app_template.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +create_file "public/robots.txt" +bundle_command "add solidus_frontend --github solidusio/solidus_frontend --branch #{ENV['SOLIDUS_BRANCH'] || 'main'}" +generate "solidus_frontend:install --auto-accept" +empty_directory 'lib/generators/solidus_frontend/install' + +create_file 'lib/generators/solidus_frontend/install/install_generator.rb', <<-CODE + puts "SolidusFrontend::Generators::InstallGenerator was disabled." + module SolidusFrontend + module Generators + class InstallGenerator < Rails::Generators::Base + class_option :auto_accept, type: :boolean, default: false + end + end + end +CODE From 4807b97f057fdbb7b0be1335d9795bca3e1ad9ce Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 24 May 2023 14:01:27 +0200 Subject: [PATCH 09/10] Force solidus_auth_devise for solidus main --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7eef5c85..591130fb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,7 @@ jobs: ruby_version: "3.2" environment: FRONTEND: "/home/circleci/project/spec/solidus_frontend_app_template.rb" + AUTHENTICATION: "devise" steps: - browser-tools/install-chrome - checkout From b3150950cfc23f02ea1e89d2b229f55606db2d34 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 26 May 2023 15:27:00 +0200 Subject: [PATCH 10/10] Override the default dummy app generation task Make it compatible with all the supported Solidus versions. --- Rakefile | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 5b9a827b..6f70d535 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,42 @@ ENV['SKIP_SOLIDUS_BOLT'] = 'true' require 'solidus_dev_support/rake_tasks' SolidusDevSupport::RakeTasks.install -task default: 'extension:specs' +# Override the default dummy app generation task to +# make it compatible with all the supported Solidus versions. +Rake::Task['extension:test_app'].clear +task 'extension:test_app' do # rubocop:disable Rails/RakeEnvironment + Spree::DummyGeneratorHelper.inject_extension_requirements = true + + require 'solidus_stripe' + + Rails.env = ENV["RAILS_ENV"] = 'test' + + Spree::DummyGenerator.start ["--lib-name=solidus_stripe"] + + # While the dummy app is generated the current directory + # within ruby is changed to that of the dummy app. + sh({ + 'FRONTEND' => ENV['FRONTEND'] || "#{__dir__}/spec/solidus_frontend_app_template.rb", + }, [ + 'bin/rails', + 'generate', + 'solidus:install', + Dir.pwd, # use the current dir as Rails.root + "--auto-accept", + "--authentication=none", + "--payment-method=none", + "--migrate=false", + "--seed=false", + "--sample=false", + "--user-class=Spree::LegacyUser", + ].shelljoin) + + puts "Setting up dummy database..." + sh "bin/rails db:environment:set RAILS_ENV=test" + sh "bin/rails db:drop db:create db:migrate VERBOSE=false RAILS_ENV=test" + + puts 'Running extension installation generator...' + sh "bin/rails generate solidus_stripe:install --auto-run-migrations" +end + +task default: ['extension:specs']