From 7c7aca4f0c9f6c3489611c598f8e917d78728c2f Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 2 Feb 2011 16:09:11 -0800 Subject: [PATCH] [#792] Add confirmation emails for successful issue replies --- app/models/mail_handler.rb | 1 + app/models/mailer.rb | 16 ++++++++++++++-- config/locales/en.yml | 2 +- test/unit/mail_handler_test.rb | 25 +++++++++++++------------ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 1fc88c25..6ed1fe97 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -163,6 +163,7 @@ class MailHandler < ActionMailer::Base add_attachments(issue) issue.save! logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info + Mailer.deliver_mail_handler_confirmation(issue.last_journal, user, email.subject) if Setting.mail_handler_confirmation_on_success issue.last_journal end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index b7716ab9..efbe8821 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -287,10 +287,22 @@ class Mailer < ActionMailer::Base def mail_handler_confirmation(object, user, email_subject) recipients user.mail - project = object.try(:project).try(:name) || '' + + case + when object.is_a?(Issue) + project = object.project.name + url = url_for(:controller => 'issues', :action => 'show', :id => object.id) + when object.is_a?(Journal) + project = object.project.name + url = url_for(:controller => 'issues', :action => 'show', :id => object.issue.id) + else + project = '' + url = '' + end + subject "[#{project}] #{l(:label_mail_handler_confirmation, :subject => email_subject)}" body(:object => object, - :url => url_for(:controller => 'issues', :action => 'show', :id => object.id)) + :url => url) render_multipart('mail_handler_confirmation', body) end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7625455e..c4d3d052 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -818,7 +818,7 @@ en: label_path_encoding: Path encoding label_deleted_custom_field: '(deleted custom field)' label_toc: "Contents" - label_mail_handler_confirmation: "Confirmation of email submission: {{subject}}" + label_mail_handler_confirmation: "Confirmation of email submission: %{subject}" button_login: Login button_submit: Submit diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index b51b1ef6..3deabac0 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -1,4 +1,4 @@ -#-- encoding: UTF-8 +#-- encoding: utf-8 -8 #-- copyright # ChiliProject is a project management system. # @@ -304,15 +304,6 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal 'Feature request', journal.issue.tracker.name end - test "reply to issue update (Journal) by message_id" do - journal = submit_email('ticket_reply_by_message_id.eml') - assert journal.is_a?(IssueJournal), "Email was a #{journal.class}" - assert_equal User.find_by_login('jsmith'), journal.user - assert_equal Issue.find(2), journal.journaled - assert_match /This is reply/, journal.notes - assert_equal 'Feature request', journal.issue.tracker.name - end - def test_add_issue_note_with_attribute_changes # This email contains: 'Status: Resolved' journal = submit_email('ticket_reply_with_status.eml') @@ -336,7 +327,7 @@ class MailHandlerTest < ActiveSupport::TestCase ActionMailer::Base.deliveries.clear journal = submit_email('ticket_reply.eml') assert journal.is_a?(Journal) - assert_equal 3, ActionMailer::Base.deliveries.size + assert_equal 1, ActionMailer::Base.deliveries.size end def test_add_issue_note_should_not_set_defaults @@ -474,7 +465,17 @@ class MailHandlerTest < ActiveSupport::TestCase end context "#receive_issue_reply" do - should "deliver an email confirmation when configured" + should "deliver an email confirmation when configured" do + journal = submit_email('ticket_reply.eml') + + assert_equal 1, ActionMailer::Base.deliveries.size + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + assert mail.subject.include?('[eCookbook]'), "Project name missing" + assert mail.subject.include?('Confirmation of email submission: Re: Add ingredients categories'), "Main subject missing" + assert mail.body.include?("/issues/2"), "Link to issue missing" + end + end context "#receive_message_reply" do