From ef4f142738167bd4a842a3178b59ffae3730803b Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Feb 2025 18:03:45 +0100 Subject: [PATCH 1/8] Add GitHub Actions Workflow --- .github/workflows/test.yml | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..308f16ef --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,70 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + schedule: + - cron: "0 0 * * 4" # every Thursday + +concurrency: + group: test-${{ github.ref_name }} + cancel-in-progress: ${{ github.ref_name != 'main' }} + +permissions: + contents: read + +jobs: + rspec: + name: Solidus ${{ matrix.solidus-branch }}, Rails ${{ matrix.rails-version }} and Ruby ${{ matrix.ruby-version }} on ${{ matrix.database }} + runs-on: ubuntu-24.04 + strategy: + fail-fast: true + matrix: + rails-version: + - "7.0" + - "7.1" + - "7.2" + ruby-version: + - "3.1" + - "3.4" + solidus-branch: + - "v4.1" + - "v4.2" + - "v4.3" + - "v4.4" + database: + - "postgresql" + - "mysql" + - "sqlite" + exclude: + - rails-version: "7.2" + solidus-branch: "v4.3" + - rails-version: "7.2" + solidus-branch: "v4.2" + - rails-version: "7.2" + solidus-branch: "v4.1" + - rails-version: "7.1" + solidus-branch: "v4.2" + - rails-version: "7.1" + solidus-branch: "v4.1" + - ruby-version: "3.4" + rails-version: "7.0" + env: + TEST_RESULTS_PATH: coverage/coverage.xml + steps: + - uses: actions/checkout@v4 + - name: Run extension tests + uses: solidusio/test-solidus-extension@main + with: + database: ${{ matrix.database }} + rails-version: ${{ matrix.rails-version }} + ruby-version: ${{ matrix.ruby-version }} + solidus-branch: ${{ matrix.solidus-branch }} + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + continue-on-error: true + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ${{ env.TEST_RESULTS_PATH }} From a1f696a6feb63f05106effe616163f7d7dee9e17 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Feb 2025 18:04:07 +0100 Subject: [PATCH 2/8] Remove CircleCI config.yml --- .circleci/config.yml | 67 -------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 8032e579..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,67 +0,0 @@ -version: 2.1 - -orbs: - # Always take the latest version of the orb, this allows us to - # run specs against Solidus supported versions only without the need - # to change this configuration every time a Solidus version is released - # or goes EOL. - solidusio_extensions: solidusio/extensions@volatile - -jobs: - run-specs: - parameters: - solidus: - type: string - default: main - db: - type: string - default: "postgres" - ruby: - type: string - default: "3.2" - executor: - name: solidusio_extensions/<< parameters.db >> - ruby_version: << parameters.ruby >> - steps: - - checkout - - solidusio_extensions/run-tests-solidus-<< parameters.solidus >> - lint-code: - executor: - name: solidusio_extensions/sqlite-memory - ruby_version: 2.5 - steps: - - solidusio_extensions/lint-code - -workflows: - "Run specs on supported Solidus versions": - jobs: - - run-specs: - name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>" - matrix: - parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } - - run-specs: - name: *name - matrix: - parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } - - run-specs: - name: *name - matrix: - parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] } - - "Weekly run specs against main": - triggers: - - schedule: - cron: "0 0 * * 4" # every Thursday - filters: - branches: - only: - - main - jobs: - - run-specs: - name: *name - matrix: - parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } - - run-specs: - name: *name - matrix: - parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } From 1eacffb5e2c2468fdeed8228736769ab8d5e9050 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Feb 2025 18:05:30 +0100 Subject: [PATCH 3/8] Use Rails version from ENV Now possible with the GitHub action --- Gemfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index ba4aac4f..3a66bdf7 100644 --- a/Gemfile +++ b/Gemfile @@ -15,10 +15,8 @@ else gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch end -# Needed to help Bundler figure out how to resolve dependencies, -# otherwise it takes forever to resolve them. -# See https://github.com/bundler/bundler/issues/6677 -gem 'rails', '>0.a' +rails_version = ENV.fetch('RAILS_VERSION', '7.2') +gem 'rails', "~> #{rails_version}" # Provides basic authentication functionality for testing parts of your engine gem 'solidus_auth_devise' From 0faa1ec747b0d95d443171a387fafa478b649925 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Feb 2025 18:06:05 +0100 Subject: [PATCH 4/8] Always use released version of `solidus_frontend` There's not much difference to the main branch anyways. --- Gemfile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 3a66bdf7..d26a2794 100644 --- a/Gemfile +++ b/Gemfile @@ -7,13 +7,7 @@ branch = ENV.fetch('SOLIDUS_BRANCH', 'main') gem 'solidus', github: 'solidusio/solidus', branch: branch # The solidus_frontend gem has been pulled out since v3.2 -if branch >= 'v3.2' - gem 'solidus_frontend' -elsif branch == 'main' - gem 'solidus_frontend', github: 'solidusio/solidus_frontend' -else - gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch -end +gem 'solidus_frontend' rails_version = ENV.fetch('RAILS_VERSION', '7.2') gem 'rails', "~> #{rails_version}" From 0e9500cefa543318ea3a8601b71939e1a6e3ab67 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Wed, 12 Feb 2025 18:06:49 +0100 Subject: [PATCH 5/8] Remove fixes for Rails < 7.0.1 --- Gemfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Gemfile b/Gemfile index d26a2794..90ed88d7 100644 --- a/Gemfile +++ b/Gemfile @@ -26,13 +26,6 @@ end gemspec -if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3') - # Fix for Rails 7+ / Ruby 3+, see https://stackoverflow.com/a/72474475 - gem 'net-imap', require: false - gem 'net-pop', require: false - gem 'net-smtp', require: false -end - # Use a local Gemfile to include development dependencies that might not be # relevant for the project or for other contributors, e.g. pry-byebug. # From 993c37aa0f15679dd84298bafeaac790e5b30ec3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 6 Feb 2025 13:03:07 +0100 Subject: [PATCH 6/8] Do not depend on solidus_auth_devise People might have other authentication solutions, and we can simply not load solidus_auth_devise in specs. --- Gemfile | 3 --- .../spree/user/have_many_subscriptions.rb | 6 +++--- spec/controllers/spree/api/users_controller_spec.rb | 2 +- .../spree/user/have_many_subscriptions_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 90ed88d7..0828e6ef 100644 --- a/Gemfile +++ b/Gemfile @@ -12,9 +12,6 @@ gem 'solidus_frontend' rails_version = ENV.fetch('RAILS_VERSION', '7.2') gem 'rails', "~> #{rails_version}" -# Provides basic authentication functionality for testing parts of your engine -gem 'solidus_auth_devise' - case ENV['DB'] when 'mysql' gem 'mysql2' diff --git a/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb b/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb index 1fb4cdf6..9fee356a 100644 --- a/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb +++ b/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb @@ -16,8 +16,8 @@ def self.prepended(base) end def subscriptions_attributes=(params) - ::Spree::Deprecation.warn( - 'Creating or updating subscriptions through Spree::User nested attributes is deprecated. ' \ + ::Spree.deprecator.warn( + "Creating or updating subscriptions through #{::Spree.user_class} nested attributes is deprecated. " \ 'Please use subscriptions APIs directly.' ) super @@ -27,4 +27,4 @@ def subscriptions_attributes=(params) end end -Spree.user_class.prepend(SolidusSubscriptions::Spree::User::HaveManySubscriptions) +::Spree.user_class.prepend(SolidusSubscriptions::Spree::User::HaveManySubscriptions) diff --git a/spec/controllers/spree/api/users_controller_spec.rb b/spec/controllers/spree/api/users_controller_spec.rb index 0a7d6141..f4bf4844 100644 --- a/spec/controllers/spree/api/users_controller_spec.rb +++ b/spec/controllers/spree/api/users_controller_spec.rb @@ -40,7 +40,7 @@ it 'updates the subscription line items' do allow(::Spree::Deprecation).to receive(:warn).with(a_string_matching( - 'Creating or updating subscriptions through Spree::User nested attributes is deprecated' + "Creating or updating subscriptions through #{Spree.user_class} nested attributes is deprecated" )) update_user line_item = subscription.line_items.reload.first diff --git a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb index 4047b010..ed8aea0f 100644 --- a/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +++ b/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe SolidusSubscriptions::Spree::User::HaveManySubscriptions, type: :model do - subject(:user) { Spree::User.new } + subject(:user) { Spree.user_class.new } it { is_expected.to have_many :subscriptions } it { is_expected.to accept_nested_attributes_for :subscriptions } @@ -16,7 +16,7 @@ expect(::Spree::Deprecation) .to have_received(:warn) - .with(/Creating or updating subscriptions through Spree::User nested attributes is deprecated/) + .with(/Creating or updating subscriptions through #{Spree.user_class} nested attributes is deprecated/) end end end From c0cc20c6b14e5d6bfafe9ca8769e849e6c64940e Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 6 Feb 2025 12:58:34 +0100 Subject: [PATCH 7/8] Install generator: Don't fail if starter frontend not present We're expecting the install generator of this gem to change things in the starter frontend, but the generated Dummy app runs on the legacy frontend. This fails, migrations don't run, and all tests fail. This is not the cleanest solution: Ideally we'd have an install generator for dummy apps that works with the starter frontend template, but we're not there. --- .../solidus_subscriptions/install/install_generator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/generators/solidus_subscriptions/install/install_generator.rb b/lib/generators/solidus_subscriptions/install/install_generator.rb index 2081deab..faa11391 100644 --- a/lib/generators/solidus_subscriptions/install/install_generator.rb +++ b/lib/generators/solidus_subscriptions/install/install_generator.rb @@ -19,6 +19,7 @@ def add_javascripts def copy_starter_frontend_files return if options[:frontend] != 'starter' + return unless File.exist?(Rails.root.join('app/views/cart_line_items/_product_submit.html.erb')) copy_file 'app/views/cart_line_items/_subscription_fields.html.erb' prepend_to_file 'app/views/cart_line_items/_product_submit.html.erb', "<%= render 'cart_line_items/subscription_fields' %>\n" From 7fd0425f11d62baeb4e7a30b232f6617836ab139 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 13 Feb 2025 10:26:58 +0100 Subject: [PATCH 8/8] Conditionally require sqlite3 --- Gemfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0828e6ef..30cfa727 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,11 @@ when 'mysql' when 'postgresql' gem 'pg' else - gem 'sqlite3' + if rails_version <= "7.2" + gem 'sqlite3', "~> 1.7" + else + gem 'sqlite3', "~> 2.0" + end end gemspec