From ee304873bf0a33a8f80a9759b4fc4078a9a9dc54 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 11:07:43 +0200 Subject: [PATCH 01/24] Update ransack to last released v4 version. This adds support for the unreleased Rails 7.1 version. Co-authored-by: Andrea Longhi --- core/lib/spree/core.rb | 2 ++ core/lib/spree/ransack_4_1_patch.rb | 16 ++++++++++++++++ core/solidus_core.gemspec | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 core/lib/spree/ransack_4_1_patch.rb diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb index 54d4f60987f..f19d057cf54 100644 --- a/core/lib/spree/core.rb +++ b/core/lib/spree/core.rb @@ -21,6 +21,8 @@ require 'ransack' require 'state_machines-activerecord' +require_relative './ransack_4_1_patch' + # This is required because ActiveModel::Validations#invalid? conflicts with the # invalid state of a Payment. In the future this should be removed. StateMachines::Machine.ignore_method_conflicts = true diff --git a/core/lib/spree/ransack_4_1_patch.rb b/core/lib/spree/ransack_4_1_patch.rb new file mode 100644 index 00000000000..f531de330d8 --- /dev/null +++ b/core/lib/spree/ransack_4_1_patch.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "ransack/version" + +return unless Ransack::VERSION.start_with?("4.1.") + +module RansackNodeConditionPatch + private + + # Waiting for https://github.com/activerecord-hackery/ransack/pull/1468 + def casted_array?(predicate) + predicate.is_a?(Arel::Nodes::Casted) && predicate.value.is_a?(Array) + end + + Ransack::Nodes::Condition.prepend(self) +end diff --git a/core/solidus_core.gemspec b/core/solidus_core.gemspec index 58011abdaf6..ee4bd9a629b 100644 --- a/core/solidus_core.gemspec +++ b/core/solidus_core.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_dependency 'monetize', '~> 1.8' s.add_dependency 'kt-paperclip', ['>= 6.3', '< 8'] s.add_dependency 'psych', ['>= 4.0.1', '< 5.0'] - s.add_dependency 'ransack', '~> 2.0' + s.add_dependency 'ransack', '~> 4.0' s.add_dependency 'sprockets-rails' s.add_dependency 'state_machines-activerecord', '~> 0.6' s.add_dependency 'omnes', '~> 0.2.2' From 0a276d2a3f830588d0c510eecfea3621442fecfd Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 11:10:01 +0200 Subject: [PATCH 02/24] Specifiy coder for serialize attributes. This is mandatory for Rails 7.1. Ref: - https://api.rubyonrails.org/v7.1.0/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html - https://github.com/rails/rails/pull/47463 Co-Authored-By: Alberto Vena --- core/app/models/spree/preference.rb | 2 +- core/app/models/spree/return_item.rb | 2 +- core/lib/spree/preferences/persistable.rb | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/preference.rb b/core/app/models/spree/preference.rb index ec03f9ef9c5..52c927d4153 100644 --- a/core/app/models/spree/preference.rb +++ b/core/app/models/spree/preference.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Spree::Preference < Spree::Base - serialize :value + serialize :value, coder: YAML validates :key, presence: true, uniqueness: { allow_blank: true, case_sensitive: true } end diff --git a/core/app/models/spree/return_item.rb b/core/app/models/spree/return_item.rb index 144bca5dccb..5aee0ee53ad 100644 --- a/core/app/models/spree/return_item.rb +++ b/core/app/models/spree/return_item.rb @@ -67,7 +67,7 @@ class ReturnItem < Spree::Base scope :exchange_processed, -> { where.not(exchange_inventory_unit: nil) } scope :exchange_required, -> { exchange_requested.where(exchange_inventory_unit: nil) } - serialize :acceptance_status_errors + serialize :acceptance_status_errors, coder: YAML delegate :eligible_for_return?, :requires_manual_intervention?, to: :validator delegate :variant, to: :inventory_unit diff --git a/core/lib/spree/preferences/persistable.rb b/core/lib/spree/preferences/persistable.rb index 12eff53f93e..252f6e296ed 100644 --- a/core/lib/spree/preferences/persistable.rb +++ b/core/lib/spree/preferences/persistable.rb @@ -7,7 +7,13 @@ module Persistable included do include Spree::Preferences::Preferable - serialize :preferences, Hash + + if method(:serialize).parameters.include?([:key, :type]) # Rails 7.1+ + serialize :preferences, type: Hash, coder: YAML + else + serialize :preferences, Hash, coder: YAML + end + after_initialize :initialize_preference_defaults end From 7906cf5d6ff725640eb1e1bf2035f9d359a0a029 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 12:37:25 +0200 Subject: [PATCH 03/24] Remove unused action on the before_action callback ``` The update action could not be found for the :load_order callback on Spree::Admin::OrdersController, but it is listed in the controller's :only option. Raising for missing callback actions is a new default in Rails 7.1, if you'd like to turn this off you can delete the option from the environment configurations or set `config.action_pack.raise_on_missing_callback_actions` to `false`. ``` --- backend/app/controllers/spree/admin/orders_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/controllers/spree/admin/orders_controller.rb b/backend/app/controllers/spree/admin/orders_controller.rb index 1e11f3161cd..3d989459af5 100644 --- a/backend/app/controllers/spree/admin/orders_controller.rb +++ b/backend/app/controllers/spree/admin/orders_controller.rb @@ -4,8 +4,8 @@ module Spree module Admin class OrdersController < Spree::Admin::BaseController before_action :initialize_order_events - before_action :load_order, only: [:edit, :update, :complete, :advance, :cancel, :resume, :approve, :resend, :unfinalize_adjustments, :finalize_adjustments, :cart, :confirm] - around_action :lock_order, only: [:update, :advance, :complete, :confirm, :cancel, :resume, :approve, :resend] + before_action :load_order, only: [:edit, :complete, :advance, :cancel, :resume, :approve, :resend, :unfinalize_adjustments, :finalize_adjustments, :cart, :confirm] + around_action :lock_order, only: [:advance, :complete, :confirm, :cancel, :resume, :approve, :resend] rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error respond_to :html From aab04a30ac14187b6451efbe0ab9d03c44ee25e5 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 12:46:06 +0200 Subject: [PATCH 04/24] Use 'main' instead of 'master' --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4ef162cc6af..886d1c798fa 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source 'https://rubygems.org' gemspec require: false # rubocop:disable Bundler/DuplicatedGem -if ENV['RAILS_VERSION'] == 'master' +if ENV['RAILS_VERSION'] == 'main' gem 'rails', github: 'rails', require: false else gem 'rails', ENV['RAILS_VERSION'] || '~> 7.0.2', require: false From db5fd5fb3c789ec6458cd9de6678521d59d39b54 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 12:52:51 +0200 Subject: [PATCH 05/24] Add Rails 7.1 supported database_cleaner gem --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 886d1c798fa..88cd67d1495 100644 --- a/Gemfile +++ b/Gemfile @@ -25,7 +25,7 @@ gem 'mysql2', '~> 0.5.0', require: false if dbs.match?(/all|mysql/) gem 'pg', '~> 1.0', require: false if dbs.match?(/all|postgres/) gem 'fast_sqlite', require: false if dbs.match?(/all|sqlite/) -gem 'database_cleaner', '~> 1.3', require: false +gem 'database_cleaner', '~> 2.0', require: false gem 'rspec-activemodel-mocks', '~> 1.1', require: false gem 'rspec-rails', '~> 4.0.1', require: false gem 'rspec-retry', '~> 0.6.2', require: false From 8f1ec11673a5d42b58872c8e054f840b4d44937f Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Fri, 1 Sep 2023 10:33:06 +0200 Subject: [PATCH 06/24] Fix `alias_method` used on an aliased attribute Fixing `alias_method': undefined method `amount' for class `Spree::ShippingRate' (NameError) See https://github.com/rails/rails/issues/49250. --- core/app/models/spree/shipping_rate.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/app/models/spree/shipping_rate.rb b/core/app/models/spree/shipping_rate.rb index 2553fd78e8f..fa16cc87b8e 100644 --- a/core/app/models/spree/shipping_rate.rb +++ b/core/app/models/spree/shipping_rate.rb @@ -18,8 +18,7 @@ class ShippingRate < Spree::Base delegate :name, :tax_category, :tax_category_id, to: :shipping_method delegate :code, to: :shipping_method, prefix: true alias_attribute :amount, :cost - - alias_method :total_before_tax, :amount + alias_attribute :total_before_tax, :cost extend DisplayMoney money_methods :amount From a4aea387ed6e6b2779048a54c8acc0eda95399c6 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sun, 8 Oct 2023 15:05:29 +0200 Subject: [PATCH 07/24] Allow Rails 7.1 and up --- core/solidus_core.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/solidus_core.gemspec b/core/solidus_core.gemspec index ee4bd9a629b..b56b540b466 100644 --- a/core/solidus_core.gemspec +++ b/core/solidus_core.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| actionmailer actionpack actionview activejob activemodel activerecord activestorage activesupport railties ].each do |rails_dep| - s.add_dependency rails_dep, ['>= 7.0', '< 7.1'] + s.add_dependency rails_dep, ['>= 7.0', '< 7.2'] end s.add_dependency 'activemerchant', '~> 1.66' From bf87f5a9f32b69c9542a857ee759ab79e554ad74 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Thu, 12 Oct 2023 10:41:02 +0200 Subject: [PATCH 08/24] Use correct renamed behavior module for testing. --- admin/spec/spec_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/spec/spec_helper.rb b/admin/spec/spec_helper.rb index 37181b90db7..1c8e396cc99 100644 --- a/admin/spec/spec_helper.rb +++ b/admin/spec/spec_helper.rb @@ -83,7 +83,7 @@ require "rails/version" require "rails/generators" require "rails/generators/app_base" -require "rails/generators/testing/behaviour" +require "rails/generators/testing/behavior" # AXE - ACCESSIBILITY require 'axe-rspec' @@ -119,7 +119,7 @@ config.include ViewComponent::SystemTestHelpers, type: :component config.include SolidusAdmin::ComponentHelpers, type: :component - config.include Rails::Generators::Testing::Behaviour, type: :generator + config.include Rails::Generators::Testing::Behavior, type: :generator config.include FileUtils, type: :generator config.before type: :generator do self.generator_class = described_class From e683524fbe5a949ea337b8615ae170b45b3f663d Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Thu, 12 Oct 2023 10:57:39 +0200 Subject: [PATCH 09/24] Use up-to-date rspec-rails gem --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 88cd67d1495..48fdf3acfc5 100644 --- a/Gemfile +++ b/Gemfile @@ -27,7 +27,7 @@ gem 'fast_sqlite', require: false if dbs.match?(/all|sqlite/) gem 'database_cleaner', '~> 2.0', require: false gem 'rspec-activemodel-mocks', '~> 1.1', require: false -gem 'rspec-rails', '~> 4.0.1', require: false +gem 'rspec-rails', '~> 6.0.3', require: false gem 'rspec-retry', '~> 0.6.2', require: false gem 'simplecov', require: false gem 'simplecov-cobertura', require: false From eeaf72cf6997968000a14815f613d7dc67e5314f Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Thu, 12 Oct 2023 11:04:00 +0200 Subject: [PATCH 10/24] Add Rails 7.1 to Circle CI Matrix --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 34d5bd9e0c1..027c2197949 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -358,10 +358,10 @@ workflows: # https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html. - test_solidus: name: &name "test-rails-<>-ruby-<>-<>-<<#matrix.paperclip>>paperclip<><<^matrix.paperclip>>activestorage<>" - matrix: { parameters: { rails: ['7.0'], ruby: ['3.0'], database: ['mysql'], paperclip: [true] } } + matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.0'], database: ['mysql'], paperclip: [true] } } - test_solidus: name: *name - matrix: { parameters: { rails: ['7.0'], ruby: ['3.1'], database: ['postgres'], paperclip: [false] } } + matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.1'], database: ['postgres'], paperclip: [false] } } - test_solidus: name: *name - matrix: { parameters: { rails: ['7.0'], ruby: ['3.2'], database: ['sqlite'], paperclip: [false] } } + matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.2'], database: ['sqlite'], paperclip: [false] } } From 6e6d66e170d47fe9ead2ef54b543999c435b7614 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Thu, 12 Oct 2023 11:38:08 +0200 Subject: [PATCH 11/24] Bump axe-core specs to fix false negative in admin --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 48fdf3acfc5..e88ad974dd8 100644 --- a/Gemfile +++ b/Gemfile @@ -55,8 +55,8 @@ end group :admin do gem 'solidus_admin', path: 'admin', require: false gem 'tailwindcss-rails', '~> 2.0', require: false - gem 'axe-core-rspec', '~> 4.7', require: false - gem 'axe-core-capybara', '~> 4.7', require: false + gem 'axe-core-rspec', '~> 4.8', require: false + gem 'axe-core-capybara', '~> 4.8', require: false end group :lint do From a240dabe3211404ddd0d4646593b0a6e74b4b9f7 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Wed, 6 Dec 2023 12:18:55 +0100 Subject: [PATCH 12/24] Default to Rails 7.1 in development --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e88ad974dd8..61ba1d2d3e3 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gemspec require: false if ENV['RAILS_VERSION'] == 'main' gem 'rails', github: 'rails', require: false else - gem 'rails', ENV['RAILS_VERSION'] || '~> 7.0.2', require: false + gem 'rails', ENV['RAILS_VERSION'] || '~> 7.1.0', require: false end # rubocop:enable Bundler/DuplicatedGem From e78a836a795a7e22cce086e9c59925b92a88f164 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Wed, 6 Dec 2023 12:32:24 +0100 Subject: [PATCH 13/24] Remove deprecated usage of alias_attributes This commit removes the following deprecations: DEPRECATION WARNING: Spree::Order model aliases `bill_address`, but `bill_address` is not an attribute. Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. Use `alias_method :billing_address, :bill_address` or define the method manually. DEPRECATION WARNING: Spree::Order model aliases `ship_address`, but `ship_address` is not an attribute. Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. Use `alias_method :shipping_address, :ship_address` or define the method manually. DEPRECATION WARNING: Spree::CreditCard model aliases `cc_type` and has a method called `cc_type=` defined. Starting in Rails 7.2 `brand=` will not be calling `cc_type=` anymore. You may want to additionally define `brand=` to preserve the current behavior. --- core/app/models/spree/credit_card.rb | 9 ++++++--- core/app/models/spree/order.rb | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb index 5756ed41086..8b5c9460055 100644 --- a/core/app/models/spree/credit_card.rb +++ b/core/app/models/spree/credit_card.rb @@ -21,9 +21,6 @@ class CreditCard < Spree::PaymentSource scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') } - # needed for some of the ActiveMerchant gateways (eg. SagePay) - alias_attribute :brand, :cc_type - # Taken from ActiveMerchant # https://github.com/activemerchant/active_merchant/blob/2f2acd4696e8de76057b5ed670b9aa022abc1187/lib/active_merchant/billing/credit_card_methods.rb#L5 CARD_TYPES = { @@ -95,6 +92,12 @@ def cc_type=(type) end end + # needed for some of the ActiveMerchant gateways (eg. SagePay) + alias_attribute :brand, :cc_type + + # Rails 7.1+ won't use the custom setter with alias_attribute + alias_method :brand=, :cc_type= + # Sets the last digits field based on the assigned credit card number. def set_last_digits self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 11f92c965cc..8d09c1f3476 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -72,11 +72,15 @@ class CannotRebuildShipments < StandardError; end # Customer info belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true + belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address', optional: true - alias_attribute :billing_address, :bill_address + alias_method :billing_address, :bill_address + alias_method :billing_address=, :bill_address= belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address', optional: true - alias_attribute :shipping_address, :ship_address + alias_method :shipping_address, :ship_address + alias_method :shipping_address=, :ship_address= + alias_attribute :ship_total, :shipment_total belongs_to :store, class_name: 'Spree::Store', optional: true From 0a97cc2306d9e4d91fefc4fa0d6d4a100b6de5d4 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Wed, 6 Dec 2023 12:48:13 +0100 Subject: [PATCH 14/24] Fix Set-Cookie header domain in tests for Rails 7.1 Apparently now Rails returns the host without the initial . --- core/spec/lib/spree/core/controller_helpers/auth_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb index 476dcebd48e..d0acf6b3ed8 100644 --- a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb +++ b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb @@ -53,7 +53,7 @@ def controller.index path: '/api' }) get :index - expect(response.headers["Set-Cookie"]).to match(/domain=\.test\.host; path=\/api/) + expect(response.headers["Set-Cookie"]).to match(/domain=(\.)?test\.host; path=\/api/) end it 'never overwrites httponly' do From fb15c4ce72dbc1b9f104d13392350e3151623960 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Wed, 13 Dec 2023 18:08:26 +0100 Subject: [PATCH 15/24] Fix warining about SchemaMigration no longer inheriting from ActiveRecord::Base DEPRECATION WARNING: SchemaMigration no longer inherits from ActiveRecord::Base. If you want to use the default connection, remove this argument. If you want to use a specific connection, instantiate MigrationContext with the connection's schema migration, for example `MigrationContext.new(path, Dog.connection.schema_migration)`. (called from new at /Users/andrea/nebulab/solidus/core/lib/spree/testing_support/dummy_app/rake_tasks.rb:41) --- core/lib/spree/testing_support/dummy_app/rake_tasks.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/lib/spree/testing_support/dummy_app/rake_tasks.rb b/core/lib/spree/testing_support/dummy_app/rake_tasks.rb index c96945e8ada..942be162967 100644 --- a/core/lib/spree/testing_support/dummy_app/rake_tasks.rb +++ b/core/lib/spree/testing_support/dummy_app/rake_tasks.rb @@ -38,10 +38,7 @@ def initialize(gem_root:, lib_name:) # railties:install:migrations and then db:migrate. # Migrations should be run one directory at a time ActiveRecord::Migrator.migrations_paths.each do |path| - ActiveRecord::MigrationContext.new( - [path], - ActiveRecord::SchemaMigration - ).migrate + ActiveRecord::MigrationContext.new([path]).migrate end ActiveRecord::Base.clear_cache! From de9d3adba171a9817e83b22e7d1d5305c462cb53 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Thu, 14 Dec 2023 15:28:29 +0100 Subject: [PATCH 16/24] Replace explicit shipping_address and billing_address attributes Due to deprecations, with a previous commit we replaced `alias_attribute` calls for these two attributes with `alias_method`, but the latter doesn't fully cover the previous behavior. When `shipping_address` or `billing_address` are passed as attributes, the error `ActiveModel::UnknownAttributeError` is now raised. For this reason, we're starting to replace them with the right association name. We may want to revisit the possibility to still use `billing_address` and `shipping_address` as providing these aliases doesn't seem to be fully viable anymore. --- sample/db/samples/orders.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sample/db/samples/orders.rb b/sample/db/samples/orders.rb index 25810d27bfd..798ff073e06 100644 --- a/sample/db/samples/orders.rb +++ b/sample/db/samples/orders.rb @@ -7,14 +7,15 @@ store = Spree::Store.first! orders = [] + orders << Spree::Order.create!( number: "R123456789", email: "spree@example.com", item_total: 150.95, adjustment_total: 150.95, total: 301.90, - shipping_address: Spree::Address.first, - billing_address: Spree::Address.last + ship_address: Spree::Address.first, + bill_address: Spree::Address.last ) orders << Spree::Order.create!( @@ -23,8 +24,8 @@ item_total: 15.95, adjustment_total: 15.95, total: 31.90, - shipping_address: Spree::Address.first, - billing_address: Spree::Address.last + ship_address: Spree::Address.first, + bill_address: Spree::Address.last ) orders[0].line_items.create!( From 9b194e2ec5cf3939faa5dd945b12c9be7e68549b Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Thu, 14 Dec 2023 18:26:23 +0100 Subject: [PATCH 17/24] Convert helper output_buffer to string Starting from Rails 7.1, `ActionView::TestCase#output_buffer` uses `ActionView::OutputBuffer` rather than `ActiveSupport::SafeBuffer`. Due to the slightly different behavior, before comparing it to a string we we need first to convert it. See https://github.com/rails/rails/pull/45679/commits/532e39ae019322e5c2ac9736c894eec876c2a3e0 --- core/spec/helpers/base_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb index 04013a1da4d..08d27b3d135 100644 --- a/core/spec/helpers/base_helper_spec.rb +++ b/core/spec/helpers/base_helper_spec.rb @@ -86,7 +86,7 @@ expect(html.css(".notice").text).to eq("ok") expect(html.css(".foo").text).to be_empty expect(html.css(".bar").text).to be_empty - expect(helper.output_buffer).to eq("
ok
") + expect(helper.output_buffer.to_s).to eq("
ok
") end end From 532dec4f9de8f83c6ffe32d0d4e4d3a1581a7c6f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 20 Dec 2023 11:45:50 +0100 Subject: [PATCH 18/24] Fix the encrypted preference spec by allowing other calls to ENV --- core/spec/models/spree/preferences/preferable_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/spec/models/spree/preferences/preferable_spec.rb b/core/spec/models/spree/preferences/preferable_spec.rb index 1064ae92462..f5f4ecc1811 100644 --- a/core/spec/models/spree/preferences/preferable_spec.rb +++ b/core/spec/models/spree/preferences/preferable_spec.rb @@ -294,7 +294,9 @@ def self.allowed_admin_form_preference_types end it "with string, encryption key provided as env variable" do - expect(ENV).to receive(:[]).with("SOLIDUS_PREFERENCES_MASTER_KEY").and_return("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!") + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:[]).with("SOLIDUS_PREFERENCES_MASTER_KEY").and_return("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!") + expect(Spree::Encryptor).to receive(:new).with("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!").and_call_original config_class_a.preference :secret, :encrypted_string From 5ef180376886da704267ca2e4eedb5bf27150feb Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 20 Dec 2023 12:18:54 +0100 Subject: [PATCH 19/24] Setup the active storage configuration In Rails 7.1 AS will check the global configuration when the macro is used. --- core/lib/spree/testing_support/dummy_app.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index 2e089d239f4..6a1883dd7c9 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -87,17 +87,15 @@ class Application < ::Rails::Application config.active_record.dump_schema_after_migration = false # Configure active storage to use storage within tmp folder - unless (ENV['DISABLE_ACTIVE_STORAGE'] == 'true') - initializer 'solidus.active_storage' do - config.active_storage.service_configurations = { - test: { - service: 'Disk', - root: Rails.root.join('tmp', 'storage') - } + initializer 'solidus.active_storage' do + config.active_storage.service_configurations = { + test: { + service: 'Disk', + root: Rails.root.join('tmp', 'storage') } - config.active_storage.service = :test - config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', :vips).to_sym - end + } + config.active_storage.service = :test + config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', :vips).to_sym end # Avoid issues if an old spec/dummy still exists From 85b35ad338f34e090ce0555e394c0b3ec94e8532 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Wed, 6 Dec 2023 12:19:46 +0100 Subject: [PATCH 20/24] Fix preview paths to work with Rails 7.1 Adding the previews path after setting the autoload ensures the file is not autoloaded by Zeitwerk. Co-Authored-By: andrea longhi --- core/lib/spree/core/engine.rb | 12 +++++++----- core/lib/spree/testing_support/dummy_app.rb | 6 +++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index 5008bc1fa01..58525660adf 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -67,12 +67,14 @@ class Engine < ::Rails::Engine end # Load in mailer previews for apps to use in development. - initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_configs" do |app| - original_preview_path = app.config.action_mailer.preview_path - solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews' + initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_autoload_paths" do + solidus_preview_path = Spree::Core::Engine.root.join("lib/spree/mailer_previews") - app.config.action_mailer.preview_path = "{#{original_preview_path},#{solidus_preview_path}}" - ActionMailer::Base.preview_path = app.config.action_mailer.preview_path + if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+ + ActionMailer::Base.preview_paths << solidus_preview_path.to_s + else + ActionMailer::Base.preview_path = "{#{ActionMailer::Base.preview_path},#{solidus_preview_path}}" + end end initializer "spree.deprecator" do |app| diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index 6a1883dd7c9..119843b0a03 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -82,7 +82,11 @@ class Application < ::Rails::Application config.secret_key_base = 'SECRET_TOKEN' # Set the preview path within the dummy app: - config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__) + if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+ + config.action_mailer.preview_paths << File.expand_path('dummy_app/mailer_previews', __dir__) + else + config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__) + end config.active_record.dump_schema_after_migration = false From f6047e771f5f59fbfc59771e5af795156ec4cb02 Mon Sep 17 00:00:00 2001 From: Peter Berkenbosch Date: Sat, 26 Aug 2023 12:33:34 +0200 Subject: [PATCH 21/24] Don't define the `with_values` scope for Rails 7.1+ https://github.com/rails/rails/commit/098b0eb5dbcf1a942c4e727dcdc150151bea51ab --- core/app/models/spree/address.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/app/models/spree/address.rb b/core/app/models/spree/address.rb index 8b68c2475a3..4866d0d9787 100644 --- a/core/app/models/spree/address.rb +++ b/core/app/models/spree/address.rb @@ -28,8 +28,10 @@ class Address < Spree::Base self.allowed_ransackable_attributes = %w[name] - scope :with_values, ->(attributes) do - where(value_attributes(attributes)) + unless ActiveRecord::Relation.method_defined? :with_values # Rails 7.1+ + scope :with_values, ->(attributes) do + where(value_attributes(attributes)) + end end # @return [Address] an address with default attributes From 95a0b09f1b6ccdb35bd2cd1b3570e8886839ad64 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 21 Dec 2023 10:45:32 +0100 Subject: [PATCH 22/24] Avoid using deprecated constants when logging VC rendering --- admin/config/initializers/view_component.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/config/initializers/view_component.rb b/admin/config/initializers/view_component.rb index 7b90ff368e2..5222819a7db 100644 --- a/admin/config/initializers/view_component.rb +++ b/admin/config/initializers/view_component.rb @@ -6,8 +6,8 @@ Rails.application.config.view_component.instrumentation_enabled = true Rails.application.config.view_component.use_deprecated_instrumentation_name = false - bold = ActiveSupport::LogSubscriber::BOLD - clear = ActiveSupport::LogSubscriber::CLEAR + bold = "\e[1m" + clear = "\e[0m" ActiveSupport::Notifications.subscribe("render.view_component") do |*args| next unless args.last[:name].starts_with?("SolidusAdmin::") From 2739f7b76424b6355c041936895e4ca9bdf5354b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 21 Dec 2023 10:45:57 +0100 Subject: [PATCH 23/24] Add a note about the value of `action_dispatch.show_exceptions` --- core/lib/generators/spree/dummy/templates/rails/test.rb | 2 +- core/lib/spree/testing_support/dummy_app.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/generators/spree/dummy/templates/rails/test.rb b/core/lib/generators/spree/dummy/templates/rails/test.rb index de4ef453afd..c890b9919a2 100644 --- a/core/lib/generators/spree/dummy/templates/rails/test.rb +++ b/core/lib/generators/spree/dummy/templates/rails/test.rb @@ -18,7 +18,7 @@ config.eager_load = false # Raise exceptions instead of rendering exception templates - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = false # Should be :none for Rails 7.1+ # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index 119843b0a03..45f3735bae9 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -63,7 +63,7 @@ class Application < ::Rails::Application # Make debugging easier: config.consider_all_requests_local = true - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = false # Should be :none for Rails 7.1+ config.active_support.deprecation = :stderr config.log_level = :debug From 66b325fb62a2031e8403c0d2dbfee416cb2c7bda Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 21 Dec 2023 10:48:09 +0100 Subject: [PATCH 24/24] Run the solidus installer on Rails 7.1 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 027c2197949..8c81b8a3e90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -165,7 +165,7 @@ commands: ruby -v >> /tmp/.ruby-versions gem --version >> /tmp/.gems-versions bundle --version >> /tmp/.gems-versions - gem search -eq rails -v "~> 7" -v"< 7.1" >> /tmp/.gems-versions # get the latest rails from rubygems + gem search -eq rails -v "~> 7" -v "< 7.2" >> /tmp/.gems-versions # get the latest rails from rubygems gem search -eq solidus >> /tmp/.gems-versions # get the latest solidus from rubygems cat /tmp/.ruby-versions