From 0d931fecbb1132abb71a83bb91435812f2012d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim=20and=20Mikel=20Lindsaar?= Date: Sun, 24 Jan 2010 18:11:57 +0100 Subject: Finish cleaning up delivery methods implementation. --- actionmailer/test/delivery_method_test.rb | 73 ------------------------------ actionmailer/test/delivery_methods_test.rb | 72 +++++++++++++++++++++++++++++ actionmailer/test/mail_service_test.rb | 22 ++++----- 3 files changed, 83 insertions(+), 84 deletions(-) delete mode 100644 actionmailer/test/delivery_method_test.rb create mode 100644 actionmailer/test/delivery_methods_test.rb (limited to 'actionmailer/test') diff --git a/actionmailer/test/delivery_method_test.rb b/actionmailer/test/delivery_method_test.rb deleted file mode 100644 index 1e7408d6d6..0000000000 --- a/actionmailer/test/delivery_method_test.rb +++ /dev/null @@ -1,73 +0,0 @@ -require 'abstract_unit' -require 'mail' - -class MyCustomDelivery -end - -class DefaultsDeliveryMethodsTest < ActionMailer::TestCase - def setup - set_delivery_method :smtp - end - - def teardown - restore_delivery_method - end - - def test_should_be_the_default_smtp - assert_equal :smtp, ActionMailer::Base.delivery_method - end - - def test_should_have_default_smtp_delivery_method_settings - settings = { :address => "localhost", - :port => 25, - :domain => 'localhost.localdomain', - :user_name => nil, - :password => nil, - :authentication => nil, - :enable_starttls_auto => true } - assert_equal settings, ActionMailer::Base.smtp_settings - end - - def test_should_have_default_file_delivery_method_settings - settings = {:location => "#{Dir.tmpdir}/mails"} - assert_equal settings, ActionMailer::Base.file_settings - end - - def test_should_have_default_sendmail_delivery_method_settings - settings = {:location => '/usr/sbin/sendmail', - :arguments => '-i -t'} - assert_equal settings, ActionMailer::Base.sendmail_settings - end -end - -class CustomDeliveryMethodsTest < ActionMailer::TestCase - def setup - ActionMailer::Base.add_delivery_method :custom, MyCustomDelivery - end - - def teardown - ActionMailer::Base.delivery_methods.delete(:custom) - ActionMailer::Base.delivery_settings.delete(:custom) - end - - def test_allow_to_add_a_custom_delivery_method - ActionMailer::Base.delivery_method = :custom - assert_equal :custom, ActionMailer::Base.delivery_method - end - - def test_allow_to_customize_custom_settings - ActionMailer::Base.custom_settings = { :foo => :bar } - assert_equal Hash[:foo => :bar], ActionMailer::Base.custom_settings - end - - def test_respond_to_custom_method_settings - assert_respond_to ActionMailer::Base, :custom_settings - assert_respond_to ActionMailer::Base, :custom_settings= - end - - def test_should_not_respond_for_invalid_method_settings - assert_raise NoMethodError do - ActionMailer::Base.another_settings - end - end -end diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb new file mode 100644 index 0000000000..de3d54197d --- /dev/null +++ b/actionmailer/test/delivery_methods_test.rb @@ -0,0 +1,72 @@ +require 'abstract_unit' +require 'mail' + +class MyCustomDelivery +end + +class DefaultsDeliveryMethodsTest < ActionMailer::TestCase + def setup + set_delivery_method :smtp + end + + def teardown + restore_delivery_method + end + + def test_should_be_the_default_smtp + assert_equal :smtp, ActionMailer::Base.delivery_method + end + + def test_should_have_default_smtp_delivery_method_settings + settings = { :address => "localhost", + :port => 25, + :domain => 'localhost.localdomain', + :user_name => nil, + :password => nil, + :authentication => nil, + :enable_starttls_auto => true } + assert_equal settings, ActionMailer::Base.smtp_settings + end + + def test_should_have_default_file_delivery_method_settings + settings = {:location => "#{Dir.tmpdir}/mails"} + assert_equal settings, ActionMailer::Base.file_settings + end + + def test_should_have_default_sendmail_delivery_method_settings + settings = {:location => '/usr/sbin/sendmail', + :arguments => '-i -t'} + assert_equal settings, ActionMailer::Base.sendmail_settings + end +end + +class CustomDeliveryMethodsTest < ActionMailer::TestCase + def setup + ActionMailer::Base.add_delivery_method :custom, MyCustomDelivery + end + + def teardown + ActionMailer::Base.delivery_methods.delete(:custom) + end + + def test_allow_to_add_a_custom_delivery_method + ActionMailer::Base.delivery_method = :custom + assert_equal :custom, ActionMailer::Base.delivery_method + end + + def test_allow_to_customize_custom_settings + ActionMailer::Base.custom_settings = { :foo => :bar } + assert_equal Hash[:foo => :bar], ActionMailer::Base.custom_settings + end + + def test_respond_to_custom_method_settings + assert_respond_to ActionMailer::Base, :custom_settings + assert_respond_to ActionMailer::Base, :custom_settings= + end + + def test_should_not_respond_for_invalid_method_settings + assert_raise NoMethodError do + ActionMailer::Base.another_settings + end + end +end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index b3bf1b9acd..c0a3f655b9 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -511,7 +511,7 @@ class ActionMailerTest < Test::Unit::TestCase end def test_from_without_name_for_smtp - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.from_without_name.deliver mail = MockSMTP.deliveries.first @@ -522,7 +522,7 @@ class ActionMailerTest < Test::Unit::TestCase end def test_from_with_name_for_smtp - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.from_with_name.deliver mail = MockSMTP.deliveries.first @@ -659,7 +659,7 @@ class ActionMailerTest < Test::Unit::TestCase def test_performs_delivery_via_sendmail IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+') - ActionMailer::Base.delivery_method = :sendmail + TestMailer.delivery_method = :sendmail TestMailer.signed_up(@recipient).deliver end @@ -956,7 +956,7 @@ EOF end def test_headers_removed_on_smtp_delivery - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.cc_bcc(@recipient).deliver assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com") assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com") @@ -1053,35 +1053,35 @@ EOF end def test_return_path_with_deliver - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.return_path.deliver assert_match %r{^Return-Path: }, MockSMTP.deliveries[0][0] assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s end def test_starttls_is_enabled_if_supported - ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => true) + TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true) MockSMTP.any_instance.expects(:enable_starttls_auto) - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.signed_up(@recipient).deliver end def test_starttls_is_disabled_if_not_supported - ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => true) + TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false) MockSMTP.any_instance.expects(:enable_starttls_auto).never - ActionMailer::Base.delivery_method = :smtp + TestMailer.delivery_method = :smtp TestMailer.signed_up(@recipient).deliver end def test_starttls_is_not_enabled - TestMailer.delivery_settings[:smtp].merge!(:enable_starttls_auto => false) + TestMailer.smtp_settings.merge!(:enable_starttls_auto => false) MockSMTP.any_instance.expects(:respond_to?).never TestMailer.delivery_method = :smtp TestMailer.signed_up(@recipient).deliver ensure - TestMailer.delivery_settings[:smtp].merge!(:enable_starttls_auto => true) + TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) end end -- cgit v1.2.3