diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-10-06 13:08:52 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2018-10-06 13:08:52 +0000 |
commit | 015ca366341ba2fa9f1d7903907ddab19a87865f (patch) | |
tree | fce88f7a0fb880d3584352e255dfd420c3e798d6 /test/unit | |
parent | b41096d9d00b0eb4c9004936b4ed5f127ec3f2c4 (diff) | |
download | redmine-015ca366341ba2fa9f1d7903907ddab19a87865f.tar.gz redmine-015ca366341ba2fa9f1d7903907ddab19a87865f.zip |
Send individual emails for each mail recipient (#26791).
We are creating multipe mails per class notification event, one per
recipient, wrapped in a Mailer::MultiMessage object to send them all at
once.
We keep the existing interface of all class methods intended to be used
by external code the same as they were before, with one exception:
We provide additional recipient addresses in options[:recipients] for
Mailer.security_notification. Since the first-class recipients have to
be users to render individual mails for them, additional recipient
addresses have to be provided with some other channel.
By providing additional recipients in options[:recipients], we can solve
the use-case for address change notifications for users, which probably
is the only real use-case for having to use a plain email address
instead of a User as a notification recipient.
Patch by Holger Just and Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@17583 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/changeset_test.rb | 2 | ||||
-rw-r--r-- | test/unit/comment_test.rb | 2 | ||||
-rw-r--r-- | test/unit/document_test.rb | 2 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 9 | ||||
-rw-r--r-- | test/unit/journal_observer_test.rb | 10 | ||||
-rw-r--r-- | test/unit/journal_test.rb | 2 | ||||
-rw-r--r-- | test/unit/mail_handler_test.rb | 11 | ||||
-rw-r--r-- | test/unit/mailer_test.rb | 14 | ||||
-rw-r--r-- | test/unit/news_test.rb | 2 | ||||
-rw-r--r-- | test/unit/repository_test.rb | 17 | ||||
-rw-r--r-- | test/unit/wiki_content_test.rb | 12 |
11 files changed, 47 insertions, 36 deletions
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb index 8586d8fc7..a1c3cf8dc 100644 --- a/test/unit/changeset_test.rb +++ b/test/unit/changeset_test.rb @@ -46,7 +46,7 @@ class ChangesetTest < ActiveSupport::TestCase fixed = Issue.find(1) assert fixed.closed? assert_equal 90, fixed.done_ratio - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_ref_keywords diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 4597fd9e7..fe9776fc3 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -36,7 +36,7 @@ class CommentTest < ActiveSupport::TestCase Watcher.create!(:watchable => @news, :user => @jsmith) with_settings :notified_events => %w(news_comment_added) do - assert_difference 'ActionMailer::Base.deliveries.size' do + assert_difference 'ActionMailer::Base.deliveries.size', 2 do Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment") end end diff --git a/test/unit/document_test.rb b/test/unit/document_test.rb index 9adcd4724..e4243dd60 100644 --- a/test/unit/document_test.rb +++ b/test/unit/document_test.rb @@ -41,7 +41,7 @@ class DocumentTest < ActiveSupport::TestCase doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation')) assert doc.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_with_default_category diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index a6ace2fa0..432dd8745 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2529,7 +2529,7 @@ class IssueTest < ActiveSupport::TestCase :subject => 'test_create', :estimated_hours => '1:30') with_settings :notified_events => %w(issue_added) do assert issue.save - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end end @@ -2541,7 +2541,7 @@ class IssueTest < ActiveSupport::TestCase :subject => 'test_create', :estimated_hours => '1:30') with_settings :notified_events => %w(issue_added issue_updated) do assert issue.save - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end end @@ -2568,7 +2568,8 @@ class IssueTest < ActiveSupport::TestCase issue.init_journal User.find(1) issue.assigned_to = nil issue.save! - assert_include user.mail, ActionMailer::Base.deliveries.last.bcc + + assert_include [user.mail], ActionMailer::Base.deliveries.map(&:bcc) end end @@ -2581,7 +2582,7 @@ class IssueTest < ActiveSupport::TestCase issue.subject = 'Subjet update' with_settings :notified_events => %w(issue_updated) do assert issue.save - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size ActionMailer::Base.deliveries.clear stale.init_journal(User.find(1)) diff --git a/test/unit/journal_observer_test.rb b/test/unit/journal_observer_test.rb index e9eac32e5..17695538a 100644 --- a/test/unit/journal_observer_test.rb +++ b/test/unit/journal_observer_test.rb @@ -36,7 +36,7 @@ class JournalObserverTest < ActiveSupport::TestCase with_settings :notified_events => %w(issue_updated) do assert journal.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_should_not_send_email_notification_with_notify_set_to_false @@ -71,7 +71,7 @@ class JournalObserverTest < ActiveSupport::TestCase with_settings :notified_events => %w(issue_note_added) do assert journal.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_should_not_send_email_notification_without_issue_note_added @@ -95,7 +95,7 @@ class JournalObserverTest < ActiveSupport::TestCase with_settings :notified_events => %w(issue_status_updated) do assert issue.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_should_not_send_email_notification_without_issue_status_updated @@ -132,7 +132,7 @@ class JournalObserverTest < ActiveSupport::TestCase with_settings :notified_events => %w(issue_assigned_to_updated) do assert issue.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_should_not_send_email_notification_without_issue_assignee_updated @@ -157,7 +157,7 @@ class JournalObserverTest < ActiveSupport::TestCase with_settings :notified_events => %w(issue_priority_updated) do assert issue.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_create_should_not_send_email_notification_without_issue_priority_updated diff --git a/test/unit/journal_test.rb b/test/unit/journal_test.rb index cca405a2e..9bbedd1d5 100644 --- a/test/unit/journal_test.rb +++ b/test/unit/journal_test.rb @@ -50,7 +50,7 @@ class JournalTest < ActiveSupport::TestCase journal = issue.init_journal(user, issue) assert journal.save - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_should_not_save_journal_with_blank_notes_and_no_details diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 401198fed..8aa2cdbe8 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -440,10 +440,11 @@ class MailHandlerTest < ActiveSupport::TestCase ) end - # only 1 email for the new issue notification - assert_equal 1, ActionMailer::Base.deliveries.size - email = ActionMailer::Base.deliveries.first - assert_include 'Ticket by unknown user', email.subject + # only 2 emails for the new issue notification + assert_equal 2, ActionMailer::Base.deliveries.size + ActionMailer::Base.deliveries.each do |email| + assert_include 'Ticket by unknown user', email.subject + end end def test_created_user_should_have_mail_notification_to_none_with_no_notification_option @@ -877,7 +878,7 @@ class MailHandlerTest < ActiveSupport::TestCase def test_update_issue_should_send_email_notification journal = submit_email('ticket_reply.eml') assert journal.is_a?(Journal) - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 3, ActionMailer::Base.deliveries.size end def test_update_issue_should_not_set_defaults diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 049db8198..0908e9e63 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -412,11 +412,15 @@ class MailerTest < ActiveSupport::TestCase journal.save! Role.find(2).add_permission! :view_private_notes - Mailer.deliver_issue_edit(journal) - assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort + assert_difference 'ActionMailer::Base.deliveries.size', 2 do + Mailer.deliver_issue_edit(journal) + end + assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last(2).flat_map(&:bcc).sort Role.find(2).remove_permission! :view_private_notes - Mailer.deliver_issue_edit(journal) + assert_difference 'ActionMailer::Base.deliveries.size', 1 do + Mailer.deliver_issue_edit(journal) + end assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort end @@ -534,7 +538,7 @@ class MailerTest < ActiveSupport::TestCase def test_wiki_content_added content = WikiContent.find(1) with_each_language_as_default do - assert_difference 'ActionMailer::Base.deliveries.size' do + assert_difference 'ActionMailer::Base.deliveries.size', 2 do assert Mailer.wiki_content_added(content).deliver assert_select_email do assert_select 'a[href=?]', @@ -548,7 +552,7 @@ class MailerTest < ActiveSupport::TestCase def test_wiki_content_updated content = WikiContent.find(1) with_each_language_as_default do - assert_difference 'ActionMailer::Base.deliveries.size' do + assert_difference 'ActionMailer::Base.deliveries.size', 2 do assert Mailer.wiki_content_updated(content).deliver assert_select_email do assert_select 'a[href=?]', diff --git a/test/unit/news_test.rb b/test/unit/news_test.rb index 7899ec2c2..03a868a91 100644 --- a/test/unit/news_test.rb +++ b/test/unit/news_test.rb @@ -34,7 +34,7 @@ class NewsTest < ActiveSupport::TestCase with_settings :notified_events => %w(news_added) do assert news.save end - assert_equal 1, ActionMailer::Base.deliveries.size + assert_equal 2, ActionMailer::Base.deliveries.size end def test_should_include_news_for_projects_with_news_enabled diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 59f011f9f..9552d0948 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -262,14 +262,15 @@ class RepositoryTest < ActiveSupport::TestCase assert_equal User.find_by_login('dlopper'), journal.user assert_equal 'Applied in changeset r2.', journal.notes - # 2 email notifications - assert_equal 2, ActionMailer::Base.deliveries.size - mail = ActionMailer::Base.deliveries.first - assert_not_nil mail - assert mail.subject.starts_with?( - "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") - assert_mail_body_match( - "Status changed from #{old_status} to #{fixed_issue.status}", mail) + # 5 email notifications, 2 for #1, 3 for #2 + assert_equal 5, ActionMailer::Base.deliveries.size + ActionMailer::Base.deliveries.first(2).each do |mail| + assert_not_nil mail + assert mail.subject.starts_with?( + "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") + assert_mail_body_match( + "Status changed from #{old_status} to #{fixed_issue.status}", mail) + end # ignoring commits referencing an issue of another project assert_equal [], Issue.find(4).changesets diff --git a/test/unit/wiki_content_test.rb b/test/unit/wiki_content_test.rb index d3cb74427..1b6dcf095 100644 --- a/test/unit/wiki_content_test.rb +++ b/test/unit/wiki_content_test.rb @@ -53,8 +53,10 @@ class WikiContentTest < ActiveSupport::TestCase assert page.save end - assert_equal 1, ActionMailer::Base.deliveries.size - assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last) + assert_equal 2, ActionMailer::Base.deliveries.size + ActionMailer::Base.deliveries.each do |mail| + assert_include 'wiki page has been added', mail_body(mail) + end end def test_update_should_be_versioned @@ -100,8 +102,10 @@ class WikiContentTest < ActiveSupport::TestCase assert content.save end - assert_equal 1, ActionMailer::Base.deliveries.size - assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last) + assert_equal 2, ActionMailer::Base.deliveries.size + ActionMailer::Base.deliveries.each do |mail| + assert_include 'wiki page has been updated', mail_body(mail) + end end def test_fetch_history |