From: Jean-Philippe Lang Date: Sun, 13 Oct 2013 07:58:33 +0000 (+0000) Subject: Fixed that the mail method should return a Mail::Message (#15113). X-Git-Tag: 2.4.0~54 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=176ce785740c5b65cc0b674789c669a76fdd8124;p=redmine.git Fixed that the mail method should return a Mail::Message (#15113). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12210 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c6822362e..c6becfdd4 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -368,7 +368,7 @@ class Mailer < ActionMailer::Base ActionMailer::Base.delivery_method = saved_method end - def mail(headers={}) + def mail(headers={}, &block) headers.merge! 'X-Mailer' => 'Redmine', 'X-Redmine-Host' => Setting.host_name, 'X-Redmine-Site' => Setting.app_title, @@ -403,12 +403,17 @@ class Mailer < ActionMailer::Base headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') end - super headers do |format| - format.text - format.html unless Setting.plain_text_mail? + m = if block_given? + super headers, &block + else + super headers do |format| + format.text + format.html unless Setting.plain_text_mail? + end end - set_language_if_valid @initial_language + + m end def initialize(*args) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index a2f371632..138611bc1 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -725,6 +725,10 @@ class MailerTest < ActiveSupport::TestCase end end + def test_mail_should_return_a_mail_message + assert_kind_of ::Mail::Message, Mailer.test_email(User.find(1)) + end + private def last_email