From 7af8d7caf06416a1d9b94f061a6d0b28fc6bc2d9 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 5 May 2012 13:07:12 +0000 Subject: [PATCH] replace Mailer deliver syntax to Rails3 style git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9638 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/account_controller.rb | 6 +- app/controllers/admin_controller.rb | 2 +- app/controllers/documents_controller.rb | 4 +- app/controllers/files_controller.rb | 2 +- app/controllers/users_controller.rb | 6 +- app/models/comment_observer.rb | 2 +- app/models/document_observer.rb | 2 +- app/models/issue_observer.rb | 2 +- app/models/journal_observer.rb | 2 +- app/models/mail_handler.rb | 2 +- app/models/message_observer.rb | 2 +- app/models/news_observer.rb | 2 +- app/models/wiki_content_observer.rb | 4 +- lib/tasks/email.rake | 2 +- test/unit/lib/redmine/hook_test.rb | 4 +- test/unit/mailer_test.rb | 74 ++++++++++++------------- 16 files changed, 60 insertions(+), 58 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index d44741678..fa530087e 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -68,7 +68,7 @@ class AccountController < ApplicationController # create a new token for password recovery token = Token.new(:user => user, :action => "recovery") if token.save - Mailer.deliver_lost_password(token) + Mailer.lost_password(token).deliver flash[:notice] = l(:notice_account_lost_email_sent) redirect_to :action => 'login' return @@ -235,7 +235,7 @@ class AccountController < ApplicationController def register_by_email_activation(user, &block) token = Token.new(:user => user, :action => "register") if user.save and token.save - Mailer.deliver_register(token) + Mailer.register(token).deliver flash[:notice] = l(:notice_account_register_done) redirect_to :action => 'login' else @@ -265,7 +265,7 @@ class AccountController < ApplicationController def register_manually_by_administrator(user, &block) if user.save # Sends an email to the administrators - Mailer.deliver_account_activation_request(user) + Mailer.account_activation_request(user).deliver account_pending else yield if block_given? diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 6e961dad9..e8cccca85 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -63,7 +63,7 @@ class AdminController < ApplicationController # Force ActionMailer to raise delivery errors so we can catch it ActionMailer::Base.raise_delivery_errors = true begin - @test = Mailer.deliver_test_email(User.current) + @test = Mailer.test_email(User.current).deliver flash[:notice] = l(:notice_email_sent, User.current.mail) rescue Exception => e flash[:error] = l(:notice_email_error, e.message) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 96be5631a..b3c82eeb0 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -86,7 +86,9 @@ class DocumentsController < ApplicationController attachments = Attachment.attach_files(@document, params[:attachments]) render_attachment_warning_if_needed(@document) - Mailer.deliver_attachments_added(attachments[:files]) if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') + if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added') + Mailer.attachments_added(attachments[:files]).deliver + end redirect_to :action => 'show', :id => @document end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index d21aa5e14..f96cd4a9f 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -46,7 +46,7 @@ class FilesController < ApplicationController render_attachment_warning_if_needed(container) if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') - Mailer.deliver_attachments_added(attachments[:files]) + Mailer.attachments_added(attachments[:files]).deliver end redirect_to project_files_path(@project) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 44aa41037..3b42e7e54 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -99,7 +99,7 @@ class UsersController < ApplicationController @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information] + Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] respond_to do |format| format.html { @@ -146,9 +146,9 @@ class UsersController < ApplicationController @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) if was_activated - Mailer.deliver_account_activated(@user) + Mailer.account_activated(@user).deliver elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? - Mailer.deliver_account_information(@user, params[:user][:password]) + Mailer.account_information(@user, params[:user][:password]).deliver end respond_to do |format| diff --git a/app/models/comment_observer.rb b/app/models/comment_observer.rb index 07823e44c..e85f3b6c9 100644 --- a/app/models/comment_observer.rb +++ b/app/models/comment_observer.rb @@ -18,7 +18,7 @@ class CommentObserver < ActiveRecord::Observer def after_create(comment) if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') - Mailer.deliver_news_comment_added(comment) + Mailer.news_comment_added(comment).deliver end end end diff --git a/app/models/document_observer.rb b/app/models/document_observer.rb index a5db33e5e..cd0db3d26 100644 --- a/app/models/document_observer.rb +++ b/app/models/document_observer.rb @@ -17,6 +17,6 @@ class DocumentObserver < ActiveRecord::Observer def after_create(document) - Mailer.deliver_document_added(document) if Setting.notified_events.include?('document_added') + Mailer.document_added(document).deliver if Setting.notified_events.include?('document_added') end end diff --git a/app/models/issue_observer.rb b/app/models/issue_observer.rb index 8c42e692e..86f5e0c8e 100644 --- a/app/models/issue_observer.rb +++ b/app/models/issue_observer.rb @@ -17,6 +17,6 @@ class IssueObserver < ActiveRecord::Observer def after_create(issue) - Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') + Mailer.issue_add(issue).deliver if Setting.notified_events.include?('issue_added') end end diff --git a/app/models/journal_observer.rb b/app/models/journal_observer.rb index 8bd0d3315..f94e5f7c3 100644 --- a/app/models/journal_observer.rb +++ b/app/models/journal_observer.rb @@ -23,7 +23,7 @@ class JournalObserver < ActiveRecord::Observer (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) ) - Mailer.deliver_issue_edit(journal) + Mailer.issue_edit(journal).deliver end end end diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index a63ee1dac..9e7e3aade 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -94,7 +94,7 @@ class MailHandler < ActionMailer::Base if logger && logger.info logger.info "MailHandler: [#{@user.login}] account created" end - Mailer.deliver_account_information(@user, @user.password) + Mailer.account_information(@user, @user.password).deliver else if logger && logger.error logger.error "MailHandler: could not create account for [#{sender_email}]" diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb index 6a0f05931..62c564361 100644 --- a/app/models/message_observer.rb +++ b/app/models/message_observer.rb @@ -17,6 +17,6 @@ class MessageObserver < ActiveRecord::Observer def after_create(message) - Mailer.deliver_message_posted(message) if Setting.notified_events.include?('message_posted') + Mailer.message_posted(message).deliver if Setting.notified_events.include?('message_posted') end end diff --git a/app/models/news_observer.rb b/app/models/news_observer.rb index 0fdfe0bac..3dd2da2bb 100644 --- a/app/models/news_observer.rb +++ b/app/models/news_observer.rb @@ -17,6 +17,6 @@ class NewsObserver < ActiveRecord::Observer def after_create(news) - Mailer.deliver_news_added(news) if Setting.notified_events.include?('news_added') + Mailer.news_added(news).deliver if Setting.notified_events.include?('news_added') end end diff --git a/app/models/wiki_content_observer.rb b/app/models/wiki_content_observer.rb index 9f3742291..f423044cd 100644 --- a/app/models/wiki_content_observer.rb +++ b/app/models/wiki_content_observer.rb @@ -17,12 +17,12 @@ class WikiContentObserver < ActiveRecord::Observer def after_create(wiki_content) - Mailer.deliver_wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added') + Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added') end def after_update(wiki_content) if wiki_content.text_changed? - Mailer.deliver_wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated') + Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated') end end end diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index 5e68080f9..2a8542ebe 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -177,7 +177,7 @@ END_DESC ActionMailer::Base.raise_delivery_errors = true begin Mailer.with_synched_deliveries do - Mailer.deliver_test_email(user) + Mailer.test_email(user).deliver end puts l(:notice_email_sent, user.mail) rescue Exception => e diff --git a/test/unit/lib/redmine/hook_test.rb b/test/unit/lib/redmine/hook_test.rb index 6a8e69a30..225d49bda 100644 --- a/test/unit/lib/redmine/hook_test.rb +++ b/test/unit/lib/redmine/hook_test.rb @@ -148,14 +148,14 @@ class Redmine::Hook::ManagerTest < ActionView::TestCase issue = Issue.find(1) ActionMailer::Base.deliveries.clear - Mailer.deliver_issue_add(issue) + Mailer.issue_add(issue).deliver mail = ActionMailer::Base.deliveries.last @hook_module.add_listener(TestLinkToHook) hook_helper.call_hook(:view_layouts_base_html_head) ActionMailer::Base.deliveries.clear - Mailer.deliver_issue_add(issue) + Mailer.issue_add(issue).deliver mail2 = ActionMailer::Base.deliveries.last assert_equal mail_body(mail), mail_body(mail2) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index d9daec7a7..483886e58 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -42,7 +42,7 @@ class MailerTest < ActiveSupport::TestCase Setting.protocol = 'https' journal = Journal.find(3) - assert Mailer.deliver_issue_edit(journal) + assert Mailer.issue_edit(journal).deliver mail = last_email assert_not_nil mail @@ -81,7 +81,7 @@ class MailerTest < ActiveSupport::TestCase Setting.protocol = 'http' journal = Journal.find(3) - assert Mailer.deliver_issue_edit(journal) + assert Mailer.issue_edit(journal).deliver mail = last_email assert_not_nil mail @@ -121,7 +121,7 @@ class MailerTest < ActiveSupport::TestCase Redmine::Utils.relative_url_root = nil journal = Journal.find(3) - assert Mailer.deliver_issue_edit(journal) + assert Mailer.issue_edit(journal).deliver mail = last_email assert_not_nil mail @@ -158,7 +158,7 @@ class MailerTest < ActiveSupport::TestCase def test_email_headers issue = Issue.find(1) - Mailer.deliver_issue_add(issue) + Mailer.issue_add(issue).deliver mail = last_email assert_not_nil mail assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s @@ -167,7 +167,7 @@ class MailerTest < ActiveSupport::TestCase def test_email_headers_should_include_sender issue = Issue.find(1) - Mailer.deliver_issue_add(issue) + Mailer.issue_add(issue).deliver mail = last_email assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s end @@ -175,7 +175,7 @@ class MailerTest < ActiveSupport::TestCase def test_plain_text_mail Setting.plain_text_mail = 1 journal = Journal.find(2) - Mailer.deliver_issue_edit(journal) + Mailer.issue_edit(journal).deliver mail = last_email assert_equal "text/plain; charset=UTF-8", mail.content_type assert_equal 0, mail.parts.size @@ -185,7 +185,7 @@ class MailerTest < ActiveSupport::TestCase def test_html_mail Setting.plain_text_mail = 0 journal = Journal.find(2) - Mailer.deliver_issue_edit(journal) + Mailer.issue_edit(journal).deliver mail = last_email assert_equal 2, mail.parts.size assert mail.encoded.include?('href') @@ -193,7 +193,7 @@ class MailerTest < ActiveSupport::TestCase def test_from_header with_settings :mail_from => 'redmine@example.net' do - Mailer.deliver_test_email(User.find(1)) + Mailer.test_email(User.find(1)).deliver end mail = last_email assert_equal 'redmine@example.net', mail.from_addrs.first @@ -201,7 +201,7 @@ class MailerTest < ActiveSupport::TestCase def test_from_header_with_phrase with_settings :mail_from => 'Redmine app ' do - Mailer.deliver_test_email(User.find(1)) + Mailer.test_email(User.find(1)).deliver end mail = last_email assert_equal 'redmine@example.net', mail.from_addrs.first @@ -217,7 +217,7 @@ class MailerTest < ActiveSupport::TestCase user.pref[:no_self_notified] = false user.pref.save User.current = user - Mailer.deliver_news_added(news.reload) + Mailer.news_added(news.reload).deliver assert_equal 1, last_email.bcc.size # nobody to notify @@ -225,13 +225,13 @@ class MailerTest < ActiveSupport::TestCase user.pref.save User.current = user ActionMailer::Base.deliveries.clear - Mailer.deliver_news_added(news.reload) + Mailer.news_added(news.reload).deliver assert ActionMailer::Base.deliveries.empty? end def test_issue_add_message_id issue = Issue.find(1) - Mailer.deliver_issue_add(issue) + Mailer.issue_add(issue).deliver mail = last_email assert_equal Mailer.message_id_for(issue), mail.message_id assert_nil mail.references @@ -239,7 +239,7 @@ class MailerTest < ActiveSupport::TestCase def test_issue_edit_message_id journal = Journal.find(1) - Mailer.deliver_issue_edit(journal) + Mailer.issue_edit(journal).deliver mail = last_email assert_equal Mailer.message_id_for(journal), mail.message_id assert_include Mailer.message_id_for(journal.issue), mail.references @@ -252,7 +252,7 @@ class MailerTest < ActiveSupport::TestCase def test_message_posted_message_id message = Message.find(1) - Mailer.deliver_message_posted(message) + Mailer.message_posted(message).deliver mail = last_email assert_equal Mailer.message_id_for(message), mail.message_id assert_nil mail.references @@ -266,7 +266,7 @@ class MailerTest < ActiveSupport::TestCase def test_reply_posted_message_id message = Message.find(3) - Mailer.deliver_message_posted(message) + Mailer.message_posted(message).deliver mail = last_email assert_equal Mailer.message_id_for(message), mail.message_id assert_include Mailer.message_id_for(message.parent), mail.references @@ -286,13 +286,13 @@ class MailerTest < ActiveSupport::TestCase end should "notify project members" do - assert Mailer.deliver_issue_add(@issue) + assert Mailer.issue_add(@issue).deliver assert last_email.bcc.include?('dlopper@somenet.foo') end should "not notify project members that are not allow to view the issue" do Role.find(2).remove_permission!(:view_issues) - assert Mailer.deliver_issue_add(@issue) + assert Mailer.issue_add(@issue).deliver assert !last_email.bcc.include?('dlopper@somenet.foo') end @@ -305,7 +305,7 @@ class MailerTest < ActiveSupport::TestCase user.save Watcher.create!(:watchable => @issue, :user => user) - assert Mailer.deliver_issue_add(@issue) + assert Mailer.issue_add(@issue).deliver assert last_email.bcc.include?(user.mail) end @@ -313,7 +313,7 @@ class MailerTest < ActiveSupport::TestCase user = User.find(9) Watcher.create!(:watchable => @issue, :user => user) Role.non_member.remove_permission!(:view_issues) - assert Mailer.deliver_issue_add(@issue) + assert Mailer.issue_add(@issue).deliver assert !last_email.bcc.include?(user.mail) end end @@ -323,7 +323,7 @@ class MailerTest < ActiveSupport::TestCase issue = Issue.find(1) valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_issue_add(issue) + assert Mailer.issue_add(issue).deliver end end @@ -331,7 +331,7 @@ class MailerTest < ActiveSupport::TestCase journal = Journal.find(1) valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_issue_edit(journal) + assert Mailer.issue_edit(journal).deliver end end @@ -339,7 +339,7 @@ class MailerTest < ActiveSupport::TestCase document = Document.find(1) valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_document_added(document) + assert Mailer.document_added(document).deliver end end @@ -347,13 +347,13 @@ class MailerTest < ActiveSupport::TestCase attachements = [ Attachment.find_by_container_type('Document') ] valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_attachments_added(attachements) + assert Mailer.attachments_added(attachements).deliver end end def test_version_file_added attachements = [ Attachment.find_by_container_type('Version') ] - assert Mailer.deliver_attachments_added(attachements) + assert Mailer.attachments_added(attachements).deliver assert_not_nil last_email.bcc assert last_email.bcc.any? assert_select_email do @@ -363,7 +363,7 @@ class MailerTest < ActiveSupport::TestCase def test_project_file_added attachements = [ Attachment.find_by_container_type('Project') ] - assert Mailer.deliver_attachments_added(attachements) + assert Mailer.attachments_added(attachements).deliver assert_not_nil last_email.bcc assert last_email.bcc.any? assert_select_email do @@ -375,7 +375,7 @@ class MailerTest < ActiveSupport::TestCase news = News.find(:first) valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_news_added(news) + assert Mailer.news_added(news).deliver end end @@ -383,7 +383,7 @@ class MailerTest < ActiveSupport::TestCase comment = Comment.find(2) valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_news_comment_added(comment) + assert Mailer.news_comment_added(comment).deliver end end @@ -393,7 +393,7 @@ class MailerTest < ActiveSupport::TestCase recipients = recipients.compact.uniq valid_languages.each do |lang| Setting.default_language = lang.to_s - assert Mailer.deliver_message_posted(message) + assert Mailer.message_posted(message).deliver end end @@ -402,7 +402,7 @@ class MailerTest < ActiveSupport::TestCase valid_languages.each do |lang| Setting.default_language = lang.to_s assert_difference 'ActionMailer::Base.deliveries.size' do - assert Mailer.deliver_wiki_content_added(content) + assert Mailer.wiki_content_added(content).deliver end end end @@ -412,7 +412,7 @@ class MailerTest < ActiveSupport::TestCase valid_languages.each do |lang| Setting.default_language = lang.to_s assert_difference 'ActionMailer::Base.deliveries.size' do - assert Mailer.deliver_wiki_content_updated(content) + assert Mailer.wiki_content_updated(content).deliver end end end @@ -422,7 +422,7 @@ class MailerTest < ActiveSupport::TestCase valid_languages.each do |lang| user.update_attribute :language, lang.to_s user.reload - assert Mailer.deliver_account_information(user, 'pAsswORd') + assert Mailer.account_information(user, 'pAsswORd').deliver end end @@ -431,7 +431,7 @@ class MailerTest < ActiveSupport::TestCase valid_languages.each do |lang| token.user.update_attribute :language, lang.to_s token.reload - assert Mailer.deliver_lost_password(token) + assert Mailer.lost_password(token).deliver end end @@ -444,7 +444,7 @@ class MailerTest < ActiveSupport::TestCase token.user.update_attribute :language, lang.to_s token.reload ActionMailer::Base.deliveries.clear - assert Mailer.deliver_register(token) + assert Mailer.register(token).deliver mail = last_email assert_select_email do assert_select "a[href=?]", @@ -458,7 +458,7 @@ class MailerTest < ActiveSupport::TestCase user = User.find(1) valid_languages.each do |lang| user.update_attribute :language, lang.to_s - assert Mailer.deliver_test_email(user) + assert Mailer.test_email(user).deliver end end @@ -504,7 +504,7 @@ class MailerTest < ActiveSupport::TestCase # Send an email to a french user user = User.find(1) user.language = 'fr' - Mailer.deliver_account_activated(user) + Mailer.account_activated(user).deliver mail = last_email assert_mail_body_match 'Votre compte', mail @@ -513,7 +513,7 @@ class MailerTest < ActiveSupport::TestCase def test_with_deliveries_off Mailer.with_deliveries false do - Mailer.deliver_test_email(User.find(1)) + Mailer.test_email(User.find(1)).deliver end assert ActionMailer::Base.deliveries.empty? # should restore perform_deliveries @@ -522,7 +522,7 @@ class MailerTest < ActiveSupport::TestCase def test_layout_should_include_the_emails_header with_settings :emails_header => "*Header content*" do - assert Mailer.deliver_test_email(User.find(1)) + assert Mailer.test_email(User.find(1)).deliver assert_select_email do assert_select ".header" do assert_select "strong", :text => "Header content" -- 2.39.5