From 42e9eed9ba5fa2a25f9e05ac2c8ad960ae30cc7b Mon Sep 17 00:00:00 2001 From: Dave Gynn Date: Sat, 20 Feb 2016 12:04:45 -0800 Subject: Prevent ActionMailer initializer from triggering load of ActionMailer the after_initialize block has been changed to use the configuration from `config.action_mailer` rather than `ActionMailer::Base` so that action mailer is not loaded before it is necessary. the mailer preview routes setup have been moved out of an `on_load(:action_mailer)` block. --- actionmailer/lib/action_mailer/railtie.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 6a633e4ce8..ae89492b0f 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -45,13 +45,6 @@ module ActionMailer options.each { |k,v| send("#{k}=", v) } - if options.show_previews - app.routes.prepend do - get '/rails/mailers' => "rails/mailers#index", internal: true - get '/rails/mailers/*path' => "rails/mailers#preview", internal: true - end - end - ActionDispatch::IntegrationTest.send :include, ActionMailer::TestCase::ClearTestDeliveries end end @@ -62,9 +55,18 @@ module ActionMailer end end - config.after_initialize do - if ActionMailer::Base.preview_path - ActiveSupport::Dependencies.autoload_paths << ActionMailer::Base.preview_path + config.after_initialize do |app| + options = app.config.action_mailer + + if options.show_previews + app.routes.prepend do + get '/rails/mailers' => "rails/mailers#index", internal: true + get '/rails/mailers/*path' => "rails/mailers#preview", internal: true + end + + if options.preview_path + ActiveSupport::Dependencies.autoload_paths << options.preview_path + end end end end -- cgit v1.2.3