From 9f676c76e105742ac00e0bc11da3bd17ca862697 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 24 Feb 2021 17:51:48 +0000 Subject: [PATCH] config: fix zeitwerk warning about DynamicSmtpSettingsInterceptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix a warning when running tests: > DEPRECATION WARNING: Initialization autoloaded the constant DynamicSmtpSettingsInterceptor. > > Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. > > Reloading does not reboot the application, and therefore code executed during > initialization does not run again. So, if you reload DynamicSmtpSettingsInterceptor, for example, > the expected changes won't be reflected in that stale Class object. > > This autoloaded constant has been unloaded. > > Please, check the "Autoloading and Reloading Constants" guide for solutions. However if we fix as recommanded, the interceptor will get added each time the classes are reloaded. And as the actual class instance changed after the reloading, they won't be de-duplicated – *and* there's no way to remove the old interceptor without having a reference to the (now-deleted) class. Instead we load the interceptor once, and add a message about the class not being auto-reloaded. --- app/models/dynamic_smtp_settings_interceptor.rb | 6 ++++++ config/initializers/dynamic_smtp_settings_interceptor.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/dynamic_smtp_settings_interceptor.rb b/app/models/dynamic_smtp_settings_interceptor.rb index 885c4b8e9..91d6398f8 100644 --- a/app/models/dynamic_smtp_settings_interceptor.rb +++ b/app/models/dynamic_smtp_settings_interceptor.rb @@ -1,3 +1,9 @@ +# Note: this class is instanciated when being added as an interceptor +# during the app initialization. +# +# If you edit this file in development env, you will need to restart +# the app to see the changes. + class DynamicSmtpSettingsInterceptor def self.delivering_email(message) if ENV['SENDINBLUE_BALANCING'] == 'enabled' diff --git a/config/initializers/dynamic_smtp_settings_interceptor.rb b/config/initializers/dynamic_smtp_settings_interceptor.rb index a3f8e2d13..26a5d4d96 100644 --- a/config/initializers/dynamic_smtp_settings_interceptor.rb +++ b/config/initializers/dynamic_smtp_settings_interceptor.rb @@ -1 +1,3 @@ -ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor" +ActiveSupport.on_load(:action_mailer) do + ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor" +end