diff options
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 6 | ||||
-rw-r--r-- | actionmailer/test/delivery_method_test.rb | 63 | ||||
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 20 | ||||
-rw-r--r-- | actionmailer/test/test_helper_test.rb | 2 |
4 files changed, 64 insertions, 27 deletions
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 50b8a53006..1fc5ab85e0 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -26,6 +26,7 @@ FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') ActionMailer::Base.template_root = FIXTURE_LOAD_PATH class MockSMTP + def self.deliveries @@deliveries end @@ -41,6 +42,7 @@ class MockSMTP def start(*args) yield self end + end class Net::SMTP @@ -57,9 +59,9 @@ rescue LoadError $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." end -def set_delivery_method(delivery_method) +def set_delivery_method(method) @old_delivery_method = ActionMailer::Base.delivery_method - ActionMailer::Base.delivery_method = delivery_method + ActionMailer::Base.delivery_method = method end def restore_delivery_method diff --git a/actionmailer/test/delivery_method_test.rb b/actionmailer/test/delivery_method_test.rb index 8f8c6b0275..fb43086423 100644 --- a/actionmailer/test/delivery_method_test.rb +++ b/actionmailer/test/delivery_method_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'mail' class DefaultDeliveryMethodMailer < ActionMailer::Base end @@ -12,18 +13,22 @@ class FileDeliveryMethodMailer < ActionMailer::Base end class CustomDeliveryMethod - attr_accessor :custom_deliveries - def initialize() - @customer_deliveries = [] + + def initialize(values) + @custom_deliveries = [] end - def self.perform_delivery(mail) + attr_accessor :custom_deliveries + + attr_accessor :settings + + def deliver!(mail) self.custom_deliveries << mail end end class CustomerDeliveryMailer < ActionMailer::Base - self.delivery_method = CustomDeliveryMethod.new + self.delivery_method = CustomDeliveryMethod end class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase @@ -36,7 +41,18 @@ class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_instance_of ActionMailer::DeliveryMethod::Smtp, ActionMailer::Base.delivery_method + 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 end @@ -50,7 +66,18 @@ class DefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_instance_of ActionMailer::DeliveryMethod::Smtp, DefaultDeliveryMethodMailer.delivery_method + assert_equal :smtp, DefaultDeliveryMethodMailer.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, DefaultDeliveryMethodMailer.smtp_settings end end @@ -64,7 +91,13 @@ class NonDefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_instance_of ActionMailer::DeliveryMethod::Sendmail, NonDefaultDeliveryMethodMailer.delivery_method + assert_equal :sendmail, NonDefaultDeliveryMethodMailer.delivery_method + end + + def test_should_have_default_sendmail_delivery_method_settings + settings = {:location => '/usr/sbin/sendmail', + :arguments => '-i -t'} + assert_equal settings, NonDefaultDeliveryMethodMailer.sendmail_settings end end @@ -78,11 +111,12 @@ class FileDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_instance_of ActionMailer::DeliveryMethod::File, FileDeliveryMethodMailer.delivery_method + assert_equal :file, FileDeliveryMethodMailer.delivery_method end - def test_should_default_location_to_the_tmpdir - assert_equal "#{Dir.tmpdir}/mails", ActionMailer::Base.file_settings[:location] + def test_should_have_default_file_delivery_method_settings + settings = {:location => "#{Dir.tmpdir}/mails"} + assert_equal settings, FileDeliveryMethodMailer.file_settings end end @@ -96,6 +130,11 @@ class CustomDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_instance_of CustomDeliveryMethod, CustomerDeliveryMailer.delivery_method + assert_equal CustomDeliveryMethod, CustomerDeliveryMailer.delivery_method + end + + def test_should_have_default_custom_delivery_method_settings + settings = {} + assert_equal settings, CustomerDeliveryMailer.custom_settings end end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index f87d9b2e5b..17e7992e29 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -545,7 +545,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_not_nil mail mail, from, to = mail - assert_equal 'system@loudthinking.com', from.addresses.first + assert_equal 'system@loudthinking.com', from end def test_reply_to @@ -674,16 +674,13 @@ class ActionMailerTest < Test::Unit::TestCase def test_doesnt_raise_errors_when_raise_delivery_errors_is_false ActionMailer::Base.raise_delivery_errors = false - TestMailer.delivery_method.expects(:perform_delivery).raises(Exception) + Mail::Message.any_instance.expects(:deliver!).raises(Exception) assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) } end def test_performs_delivery_via_sendmail - sm = mock() - sm.expects(:print).with(anything) - sm.expects(:flush) - IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t', 'w+').yields(sm) - ActionMailer::Base.delivery_method = :sendmail + IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t test@localhost', 'w+') + TestMailer.delivery_method = :sendmail TestMailer.deliver_signed_up(@recipient) end @@ -1093,7 +1090,7 @@ EOF end def test_starttls_is_enabled_if_supported - ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + ActionMailer::Base.delivery_settings[:smtp].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 @@ -1101,7 +1098,7 @@ EOF end def test_starttls_is_disabled_if_not_supported - ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + ActionMailer::Base.delivery_settings[:smtp].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 @@ -1109,13 +1106,12 @@ EOF end def test_starttls_is_not_enabled - ActionMailer::Base.smtp_settings[:enable_starttls_auto] = false + ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => false) MockSMTP.any_instance.expects(:respond_to?).never - MockSMTP.any_instance.expects(:enable_starttls_auto).never ActionMailer::Base.delivery_method = :smtp TestMailer.deliver_signed_up(@recipient) ensure - ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + ActionMailer::Base.delivery_settings[:smtp].merge!(:enable_starttls_auto => true) end end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 1fed26f78f..48e4433e98 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -12,7 +12,7 @@ end class TestHelperMailerTest < ActionMailer::TestCase def test_setup_sets_right_action_mailer_options - assert_instance_of ActionMailer::DeliveryMethod::Test, ActionMailer::Base.delivery_method + assert_equal :test, ActionMailer::Base.delivery_method assert ActionMailer::Base.perform_deliveries assert_equal [], ActionMailer::Base.deliveries end |