From b0735aafe05afb8aaabf50c7ddb50e7307e2dd81 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 4 Mar 2021 16:32:58 +0100 Subject: [PATCH] config: fix DynamicSmtpSettingsInterceptor warning again This warning re-appeared when running mailer tests: ``` DISABLE_SPRING=1 bin/rspec spec/mailers/administration_mailer_spec.rb ``` It is now fixed properly, in a way recommanded by the documentation. --- .../dynamic_smtp_settings_interceptor.rb | 13 ++++++++++++- .../dynamic_smtp_settings_interceptor.rb | 0 2 files changed, 12 insertions(+), 1 deletion(-) rename {app/models => lib/action_mailer}/dynamic_smtp_settings_interceptor.rb (100%) diff --git a/config/initializers/dynamic_smtp_settings_interceptor.rb b/config/initializers/dynamic_smtp_settings_interceptor.rb index 26a5d4d96..b91ee7e19 100644 --- a/config/initializers/dynamic_smtp_settings_interceptor.rb +++ b/config/initializers/dynamic_smtp_settings_interceptor.rb @@ -1,3 +1,14 @@ +# We want to register an interceptor, but we can't make the action idempotent +# (because there's no way to peek at the currently registered interceptors). +# +# To make zeitwerk happy, instead signal that we don't want the +# DynamicSmtpSettingsInterceptor constant to be auto-loaded, by: +# - adding it to a non-autoloaded-path (/lib), +# - requiring it explicitely. +# +# See https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots +require 'action_mailer/dynamic_smtp_settings_interceptor' + ActiveSupport.on_load(:action_mailer) do - ActionMailer::Base.register_interceptor "DynamicSmtpSettingsInterceptor" + ActionMailer::Base.register_interceptor DynamicSmtpSettingsInterceptor end diff --git a/app/models/dynamic_smtp_settings_interceptor.rb b/lib/action_mailer/dynamic_smtp_settings_interceptor.rb similarity index 100% rename from app/models/dynamic_smtp_settings_interceptor.rb rename to lib/action_mailer/dynamic_smtp_settings_interceptor.rb