config: fix zeitwerk warning about DynamicSmtpSettingsInterceptor

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.
This commit is contained in:
Pierre de La Morinerie 2021-02-24 17:51:48 +00:00
parent 28722b002b
commit 9f676c76e1
2 changed files with 9 additions and 1 deletions

View file

@ -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'

View file

@ -1 +1,3 @@
ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor"
ActiveSupport.on_load(:action_mailer) do
ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor"
end