From 44d20af07877113a4a6a93dbb433cbdff3dd3858 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 28 Jul 2023 13:35:05 +0200 Subject: [PATCH 1/4] Use the new ActiveSupport deprecation syntax See https://github.com/rails/rails/blob/814f8ee068814e3d4832a607f49f155e02a609c0/activesupport/lib/active_support/deprecation.rb#L6-L34 Add Spree.deprecator to the list of app deprecators as suggested by Rails, this will allow applying the global deprecation configurations to our engine deprecations as well. Eg: config.active_support.deprecation = :raise This will set the deprecation behavior to raise an exception on any of the deprecators under `Rails.application.deprecators`. --- core/lib/spree/core/engine.rb | 6 ++++++ core/lib/spree/deprecation.rb | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb index 807f05cfe83..5008bc1fa01 100644 --- a/core/lib/spree/core/engine.rb +++ b/core/lib/spree/core/engine.rb @@ -75,6 +75,12 @@ class Engine < ::Rails::Engine ActionMailer::Base.preview_path = app.config.action_mailer.preview_path end + initializer "spree.deprecator" do |app| + if app.respond_to?(:deprecators) + app.deprecators[:spree] = Spree.deprecator + end + end + config.after_initialize do Spree::Config.check_load_defaults_called('Spree::Config') Spree::Config.static_model_preferences.validate! diff --git a/core/lib/spree/deprecation.rb b/core/lib/spree/deprecation.rb index 26a6baac69f..f1bcdec712d 100644 --- a/core/lib/spree/deprecation.rb +++ b/core/lib/spree/deprecation.rb @@ -3,7 +3,11 @@ require 'active_support/deprecation' module Spree - Deprecation = ActiveSupport::Deprecation.new('5.0', 'Solidus') + def self.deprecator + @deprecator ||= ActiveSupport::Deprecation.new('5.0', 'Solidus') + end + + Deprecation = Spree.deprecator # This DeprecatedInstanceVariableProxy transforms instance variable to # deprecated instance variable. From e822f3fc70121f49f2cdc2c709c15fdf62b97be4 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 28 Jul 2023 13:42:49 +0200 Subject: [PATCH 2/4] Convert all Spree::Deprecation in Spree.deprecator --- .../spree/admin/stock_items_controller.rb | 2 +- backend/app/helpers/spree/admin/navigation_helper.rb | 4 ++-- .../spree/admin/shared/_product_sub_menu.html.erb | 2 +- .../spree/admin/shared/_promotion_sub_menu.html.erb | 2 +- .../spree/admin/shared/_settings_sub_menu.html.erb | 2 +- .../deprecated_tab_constants.rb | 2 +- backend/lib/spree/backend_configuration/menu_item.rb | 12 ++++++------ backend/spec/helpers/admin/navigation_helper_spec.rb | 2 +- .../spree/backend_configuration/menu_item_spec.rb | 6 +++--- backend/spec/lib/spree/backend_configuration_spec.rb | 2 +- core/app/models/spree/adjustment.rb | 2 +- core/app/models/spree/order.rb | 4 ++-- core/app/models/spree/order_updater.rb | 2 +- .../generators/spree/dummy/templates/rails/test.rb | 2 +- core/lib/spree/deprecation.rb | 4 ++-- core/lib/spree/preferences/configuration.rb | 2 +- core/lib/spree/testing_support/dummy_app.rb | 2 +- core/lib/spree/testing_support/factory_bot.rb | 2 +- .../spree/testing_support/silence_deprecations.rb | 2 +- core/spec/models/spree/order_spec.rb | 2 +- .../models/spree/preferences/configuration_spec.rb | 6 +++--- 21 files changed, 33 insertions(+), 33 deletions(-) diff --git a/backend/app/controllers/spree/admin/stock_items_controller.rb b/backend/app/controllers/spree/admin/stock_items_controller.rb index f2387bdae2e..7669a41f19c 100644 --- a/backend/app/controllers/spree/admin/stock_items_controller.rb +++ b/backend/app/controllers/spree/admin/stock_items_controller.rb @@ -45,7 +45,7 @@ def load_stock_management_data view_context, :@stock_locations, :stock_item_stock_locations, - Spree::Deprecation, + Spree.deprecator, "Please, do not use @stock_item_stock_locations anymore in the views, use @stock_locations", ) @variant_display_attributes = self.class.variant_display_attributes diff --git a/backend/app/helpers/spree/admin/navigation_helper.rb b/backend/app/helpers/spree/admin/navigation_helper.rb index 769e3a0f473..60f566cadf4 100644 --- a/backend/app/helpers/spree/admin/navigation_helper.rb +++ b/backend/app/helpers/spree/admin/navigation_helper.rb @@ -50,12 +50,12 @@ def tab(*args, &block) css_classes = Array(options[:css_class]) if options.key?(:route) - Spree::Deprecation.warn "Passing a route to #tab is deprecated. Please pass a url instead." + Spree.deprecator.warn "Passing a route to #tab is deprecated. Please pass a url instead." options[:url] ||= spree.send("#{options[:route]}_path") end if args.any? - Spree::Deprecation.warn "Passing resources to #tab is deprecated. Please use the `label:` and `match_path:` options instead." + Spree.deprecator.warn "Passing resources to #tab is deprecated. Please use the `label:` and `match_path:` options instead." options[:label] ||= args.first options[:url] ||= spree.send("admin_#{args.first}_path") options[:selected] = args.include?(controller.controller_name.to_sym) diff --git a/backend/app/views/spree/admin/shared/_product_sub_menu.html.erb b/backend/app/views/spree/admin/shared/_product_sub_menu.html.erb index 21218e96ac9..02f468756d6 100644 --- a/backend/app/views/spree/admin/shared/_product_sub_menu.html.erb +++ b/backend/app/views/spree/admin/shared/_product_sub_menu.html.erb @@ -1,4 +1,4 @@ -<% Spree::Deprecation.warn "Using the #{@virtual_path.inspect} partial is deprecated, please use MenuItem#children instead." %> +<% Spree.deprecator.warn "Using the #{@virtual_path.inspect} partial is deprecated, please use MenuItem#children instead." %>