Browse files

Fix GH #4551. Set delivery method settings to Mail.defaults.

  • Loading branch information...
1 parent b4b2f5d commit d30c92aaf6a14330fab377400868ed85b43c5d16 @kennyj committed Feb 2, 2012
Showing with 32 additions and 0 deletions.
  1. +12 −0 actionmailer/lib/action_mailer/railtie.rb
  2. +20 −0 railties/test/application/configuration_test.rb
View
12 actionmailer/lib/action_mailer/railtie.rb
@@ -1,3 +1,4 @@
+require 'mail'
require "action_mailer"
require "rails"
require "abstract_controller/railties/routes_helpers"
@@ -40,5 +41,16 @@ class Railtie < Rails::Railtie
config.compile_methods! if config.respond_to?(:compile_methods!)
end
end
+
+ config.after_initialize do |app|
+ options = app.config.action_mailer
+
+ # set default delivery method settings to Mail
+ method = options.delivery_method
+ if settings = options.send(:"#{method}_settings")
+ Mail.defaults { delivery_method(method, settings) }
+ end
+ end
+
end
end
View
20 railties/test/application/configuration_test.rb
@@ -359,6 +359,25 @@ def index
assert_equal [::MyMailObserver, ::MyOtherMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers")
end
+ test "default delivery_method settings for Mail" do
+ add_to_config <<-RUBY
+ config.action_mailer.delivery_method = :smtp
+ config.action_mailer.smtp_settings = { :address => "foo.bar", :port => 1025 }
+ RUBY
+
+ require "#{app_path}/config/environment"
+ require "mail"
+
+ _ = ActionMailer::Base
+
+ expected = {
+ :address => "foo.bar", :port => 1025,
+ :domain=>"localhost.localdomain", :user_name=>nil, :password=>nil, :authentication=>nil,
+ :enable_starttls_auto=>true, :openssl_verify_mode=>nil, :ssl=>nil, :tls=>nil
+ }
+ assert_equal expected, Mail.delivery_method.settings
+ end
+
test "valid timezone is setup correctly" do
add_to_config <<-RUBY
config.root = "#{app_path}"
@@ -539,5 +558,6 @@ def index
make_basic_app
assert app.config.colorize_logging
end
+
end
end

0 comments on commit d30c92a

Please sign in to comment.