From fcf9cf7bb17e5760f9cd4c93e481dcf41bac8b86 2014-12-08 17:31:48 From: Jean-Philippe Lang Date: 2014-12-08 17:31:48 Subject: [PATCH] Misc tests. git-svn-id: http://svn.redmine.org/redmine/trunk@13734 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index b502a86..fa996ad 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -49,7 +49,7 @@ class MailHandler < ActionMailer::Base # Receives an email and rescues any exception def self.safe_receive(*args) receive(*args) - rescue => e + rescue Exception => e logger.error "An unexpected error occurred when receiving email: #{e.message}" if logger return false end diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index d18da5f..afa698a 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -936,6 +936,12 @@ class MailHandlerTest < ActiveSupport::TestCase }, options) end + def test_safe_receive_should_rescue_exceptions_and_return_false + MailHandler.stubs(:receive).raises(Exception.new "Something went wrong") + + assert_equal false, MailHandler.safe_receive + end + private def submit_email(filename, options={}) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index e9ffbae..68e3c34 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -758,6 +758,19 @@ class MailerTest < ActiveSupport::TestCase assert_kind_of ::Mail::Message, Mailer.test_email(User.find(1)) end + def test_with_synched_deliveries_should_yield_with_synced_deliveries + ActionMailer::Base.delivery_method = :async_smtp + ActionMailer::Base.async_smtp_settings = {:foo => 'bar'} + + Mailer.with_synched_deliveries do + assert_equal :smtp, ActionMailer::Base.delivery_method + assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings) + end + assert_equal :async_smtp, ActionMailer::Base.delivery_method + ensure + ActionMailer::Base.delivery_method = :test + end + private def last_email