From 921263bb924210308aec9258a8fa445f147dd3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?= Date: Wed, 12 Jan 2022 19:41:25 -0300 Subject: [PATCH] Only configure smtp_settings if provided on configuration --- actionmailer/lib/action_mailer/railtie.rb | 13 ++++++--- .../test/application/configuration_test.rb | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 70c4937c418..bd87fe1057f 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -23,7 +23,6 @@ module ActionMailer options.stylesheets_dir ||= paths["public/stylesheets"].first options.show_previews = Rails.env.development? if options.show_previews.nil? options.cache_store ||= Rails.cache - options.smtp_settings ||= {} if options.show_previews options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil @@ -46,9 +45,15 @@ module ActionMailer self.delivery_job = delivery_job.constantize end - if smtp_timeout = options.delete(:smtp_timeout) - options.smtp_settings[:open_timeout] ||= smtp_timeout - options.smtp_settings[:read_timeout] ||= smtp_timeout + if options.smtp_settings + self.smtp_settings = options.smtp_settings + end + + smtp_timeout = options.delete(:smtp_timeout) + + if self.smtp_settings && smtp_timeout + self.smtp_settings[:open_timeout] ||= smtp_timeout + self.smtp_settings[:read_timeout] ||= smtp_timeout end options.each { |k, v| send("#{k}=", v) } diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index a1c28059626..0e86f547b34 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -2799,7 +2799,36 @@ module ApplicationTests smtp_settings = { domain: "example.com" } assert_equal smtp_settings, ActionMailer::Base.smtp_settings + end + + test "Rails.application.config.action_mailer.smtp_settings = nil fallback to ActionMailer::Base.smtp_settings" do + remove_from_config '.*config\.load_defaults.*\n' + add_to_config <<-RUBY + ActionMailer::Base.smtp_settings = { domain: "example.com" } + config.load_defaults "7.0" + RUBY + + app "development" + + smtp_settings = { domain: "example.com", open_timeout: 5, read_timeout: 5 } + assert_equal smtp_settings, ActionMailer::Base.smtp_settings + assert_nil Rails.configuration.action_mailer.smtp_settings + end + + test "Rails.application.config.action_mailer.smtp_settings = nil and ActionMailer::Base.smtp_settings = nil do not configure smtp_timeout" do + ActionMailer::Base.smtp_settings = nil + + remove_from_config '.*config\.load_defaults.*\n' + add_to_config <<-RUBY + config.action_mailer.smtp_settings = nil + config.load_defaults "7.0" + RUBY + + app "development" + + assert_nil Rails.configuration.action_mailer.smtp_settings + assert_nil ActionMailer::Base.smtp_settings end test "ActiveSupport.utc_to_local_returns_utc_offset_times is true in 6.1 defaults" do