Redmine 4.1.1
This commit is contained in:
parent
33e7b881a5
commit
3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2019 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -26,6 +26,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
:member_roles, :roles, :documents, :attachments, :news,
|
||||
:tokens, :journals, :journal_details, :changesets,
|
||||
:trackers, :projects_trackers,
|
||||
:custom_fields, :custom_fields_trackers,
|
||||
:issue_statuses, :enumerations, :messages, :boards, :repositories,
|
||||
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
|
||||
:versions,
|
||||
|
@ -44,7 +45,6 @@ class MailerTest < ActiveSupport::TestCase
|
|||
assert Mailer.deliver_issue_edit(journal)
|
||||
end
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
|
||||
assert_select_email do
|
||||
# link to the main ticket on issue id
|
||||
|
@ -62,7 +62,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
:text => '#1'
|
||||
# link to a changeset
|
||||
assert_select 'a[href=?][title=?]',
|
||||
'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
|
||||
'https://mydomain.foo/projects/ecookbook/repository/10/revisions/2',
|
||||
'This commit fixes #1, #2 and references #1 & #3',
|
||||
:text => 'r2'
|
||||
# link to a description diff
|
||||
|
@ -88,7 +88,6 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
|
||||
assert_select_email do
|
||||
# link to the main ticket
|
||||
|
@ -102,7 +101,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
:text => '#1'
|
||||
# link to a changeset
|
||||
assert_select 'a[href=?][title=?]',
|
||||
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
||||
'http://mydomain.foo/rdm/projects/ecookbook/repository/10/revisions/2',
|
||||
'This commit fixes #1, #2 and references #1 & #3',
|
||||
:text => 'r2'
|
||||
# link to a description diff
|
||||
|
@ -122,18 +121,16 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_generated_links_with_port_and_prefix
|
||||
with_settings :host_name => '10.0.0.1:81/redmine', :protocol => 'http' do
|
||||
Mailer.test_email(User.find(1)).deliver
|
||||
Mailer.test_email(User.find(1)).deliver_now
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_include 'http://10.0.0.1:81/redmine', mail_body(mail)
|
||||
end
|
||||
end
|
||||
|
||||
def test_generated_links_with_port
|
||||
with_settings :host_name => '10.0.0.1:81', :protocol => 'http' do
|
||||
Mailer.test_email(User.find(1)).deliver
|
||||
Mailer.test_email(User.find(1)).deliver_now
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_include 'http://10.0.0.1:81', mail_body(mail)
|
||||
end
|
||||
end
|
||||
|
@ -141,6 +138,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
def test_issue_edit_should_generate_url_with_hostname_for_relations
|
||||
journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now)
|
||||
journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2)
|
||||
journal.save
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
assert_not_nil last_email
|
||||
assert_select_email do
|
||||
|
@ -158,7 +156,6 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
|
||||
assert_select_email do
|
||||
# link to the main ticket
|
||||
|
@ -172,7 +169,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
:text => '#1'
|
||||
# link to a changeset
|
||||
assert_select 'a[href=?][title=?]',
|
||||
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
||||
'http://mydomain.foo/rdm/projects/ecookbook/repository/10/revisions/2',
|
||||
'This commit fixes #1, #2 and references #1 & #3',
|
||||
:text => 'r2'
|
||||
# link to a description diff
|
||||
|
@ -193,14 +190,25 @@ class MailerTest < ActiveSupport::TestCase
|
|||
Redmine::Utils.relative_url_root = relative_url_root
|
||||
end
|
||||
|
||||
def test_link_to_user_in_email
|
||||
issue = Issue.generate!(:description => '@jsmith')
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert_select_email do
|
||||
assert_select "a[href=?]", "http://localhost:3000/users/2", :text => 'John Smith'
|
||||
end
|
||||
end
|
||||
|
||||
def test_email_headers
|
||||
issue = Issue.find(1)
|
||||
Mailer.deliver_issue_add(issue)
|
||||
with_settings :mail_from => 'Redmine <redmine@example.net>' do
|
||||
issue = Issue.find(1)
|
||||
Mailer.deliver_issue_add(issue)
|
||||
end
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_equal 'All', mail.header['X-Auto-Response-Suppress'].to_s
|
||||
assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
|
||||
# List-Id should not include the display name "Redmine"
|
||||
assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
|
||||
assert_equal 'Bug', mail.header['X-Redmine-Issue-Tracker'].to_s
|
||||
end
|
||||
|
||||
def test_email_headers_should_include_sender
|
||||
|
@ -231,7 +239,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_from_header
|
||||
with_settings :mail_from => 'redmine@example.net' do
|
||||
Mailer.test_email(User.find(1)).deliver
|
||||
Mailer.deliver_test_email(User.find(1))
|
||||
end
|
||||
mail = last_email
|
||||
assert_equal 'redmine@example.net', mail.from_addrs.first
|
||||
|
@ -239,13 +247,45 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_from_header_with_phrase
|
||||
with_settings :mail_from => 'Redmine app <redmine@example.net>' do
|
||||
Mailer.test_email(User.find(1)).deliver
|
||||
Mailer.deliver_test_email(User.find(1))
|
||||
end
|
||||
mail = last_email
|
||||
assert_equal 'redmine@example.net', mail.from_addrs.first
|
||||
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
||||
end
|
||||
|
||||
def test_from_header_with_rfc_non_compliant_phrase
|
||||
# Send out the email instead of raising an exception
|
||||
# no matter if the emission email address is not RFC compliant
|
||||
assert_nothing_raised do
|
||||
with_settings :mail_from => '[Redmine app] <redmine@example.net>' do
|
||||
Mailer.deliver_test_email(User.find(1))
|
||||
end
|
||||
end
|
||||
mail = last_email
|
||||
assert_match /<redmine@example\.net>/, mail.from_addrs.first
|
||||
assert_equal '[Redmine app] <redmine@example.net>', mail.header['From'].to_s
|
||||
end
|
||||
|
||||
def test_from_header_with_author_name
|
||||
# Use the author's name or Setting.app_title as a display name
|
||||
# when Setting.mail_from does not include a display name
|
||||
with_settings :mail_from => 'redmine@example.net', :app_title => 'Foo' do
|
||||
# Use @author.name as a display name
|
||||
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
|
||||
:subject => 'Issue created by Dave Lopper', :author_id => 3)
|
||||
mail = last_email
|
||||
assert_equal 'redmine@example.net', mail.from_addrs.first
|
||||
assert_equal 'Dave Lopper <redmine@example.net>', mail.header['From'].to_s
|
||||
|
||||
# Use app_title if @author is nil or AnonymousUser
|
||||
Mailer.deliver_test_email(User.find(1))
|
||||
mail = last_email
|
||||
assert_equal 'redmine@example.net', mail.from_addrs.first
|
||||
assert_equal "Foo <redmine@example.net>", mail.header['From'].to_s
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_not_send_email_without_recipient
|
||||
news = News.first
|
||||
user = news.author
|
||||
|
@ -255,7 +295,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
user.pref.no_self_notified = false
|
||||
user.pref.save
|
||||
User.current = user
|
||||
Mailer.news_added(news.reload).deliver
|
||||
Mailer.deliver_news_added(news.reload)
|
||||
assert_equal 1, last_email.bcc.size
|
||||
|
||||
# nobody to notify
|
||||
|
@ -263,7 +303,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
user.pref.save
|
||||
User.current = user
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Mailer.news_added(news.reload).deliver
|
||||
Mailer.deliver_news_added(news.reload)
|
||||
assert ActionMailer::Base.deliveries.empty?
|
||||
end
|
||||
|
||||
|
@ -271,8 +311,9 @@ class MailerTest < ActiveSupport::TestCase
|
|||
issue = Issue.find(2)
|
||||
Mailer.deliver_issue_add(issue)
|
||||
mail = last_email
|
||||
assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id
|
||||
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
||||
uid = destination_user(mail).id
|
||||
assert_include "redmine.issue-2.20060719190421.#{uid}@example.net", mail.message_id
|
||||
assert_include "redmine.issue-2.20060719190421.#{uid}@example.net", mail.references
|
||||
end
|
||||
|
||||
def test_issue_edit_message_id
|
||||
|
@ -281,8 +322,9 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
mail = last_email
|
||||
assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
||||
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
||||
uid = destination_user(mail).id
|
||||
assert_match /^redmine\.journal-3\.\d+\.#{uid}@example\.net/, mail.message_id
|
||||
assert_include "redmine.issue-2.20060719190421.#{uid}@example.net", mail.references
|
||||
assert_select_email do
|
||||
# link to the update
|
||||
assert_select "a[href=?]",
|
||||
|
@ -292,10 +334,11 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_message_posted_message_id
|
||||
message = Message.find(1)
|
||||
Mailer.message_posted(message).deliver
|
||||
Mailer.deliver_message_posted(message)
|
||||
mail = last_email
|
||||
assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
||||
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
||||
uid = destination_user(mail).id
|
||||
assert_include "redmine.message-1.20070512151532.#{uid}@example.net", mail.message_id
|
||||
assert_include "redmine.message-1.20070512151532.#{uid}@example.net", mail.references
|
||||
assert_select_email do
|
||||
# link to the message
|
||||
assert_select "a[href=?]",
|
||||
|
@ -306,10 +349,11 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_reply_posted_message_id
|
||||
message = Message.find(3)
|
||||
Mailer.message_posted(message).deliver
|
||||
Mailer.deliver_message_posted(message)
|
||||
mail = last_email
|
||||
assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
||||
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
||||
uid = destination_user(mail).id
|
||||
assert_include "redmine.message-3.20070512151802.#{uid}@example.net", mail.message_id
|
||||
assert_include "redmine.message-1.20070512151532.#{uid}@example.net", mail.references
|
||||
assert_select_email do
|
||||
# link to the reply
|
||||
assert_select "a[href=?]",
|
||||
|
@ -318,25 +362,38 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_timestamp_in_message_id_should_be_utc
|
||||
zone_was = Time.zone
|
||||
issue = Issue.find(3)
|
||||
user = User.find(1)
|
||||
%w(UTC Paris Tokyo).each do |zone|
|
||||
Time.zone = zone
|
||||
assert_match /^redmine\.issue-3\.20060719190727\.1@example\.net/, Mailer.token_for(issue, user)
|
||||
end
|
||||
ensure
|
||||
Time.zone = zone_was
|
||||
end
|
||||
|
||||
test "#issue_add should notify project members" do
|
||||
issue = Issue.find(1)
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert last_email.bcc.include?('dlopper@somenet.foo')
|
||||
assert_include 'dlopper@somenet.foo', recipients
|
||||
end
|
||||
|
||||
def test_issue_add_should_send_mail_to_all_user_email_address
|
||||
EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo')
|
||||
issue = Issue.find(1)
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert last_email.bcc.include?('dlopper@somenet.foo')
|
||||
assert last_email.bcc.include?('otheremail@somenet.foo')
|
||||
|
||||
assert mail = ActionMailer::Base.deliveries.find {|m| m.bcc.include?('dlopper@somenet.foo')}
|
||||
assert mail.bcc.include?('otheremail@somenet.foo')
|
||||
end
|
||||
|
||||
test "#issue_add should not notify project members that are not allow to view the issue" do
|
||||
issue = Issue.find(1)
|
||||
Role.find(2).remove_permission!(:view_issues)
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert !last_email.bcc.include?('dlopper@somenet.foo')
|
||||
assert_not_include 'dlopper@somenet.foo', recipients
|
||||
end
|
||||
|
||||
test "#issue_add should notify issue watchers" do
|
||||
|
@ -350,7 +407,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Watcher.create!(:watchable => issue, :user => user)
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert last_email.bcc.include?(user.mail)
|
||||
assert_include user.mail, recipients
|
||||
end
|
||||
|
||||
test "#issue_add should not notify watchers not allowed to view the issue" do
|
||||
|
@ -359,7 +416,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
Watcher.create!(:watchable => issue, :user => user)
|
||||
Role.non_member.remove_permission!(:view_issues)
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert !last_email.bcc.include?(user.mail)
|
||||
assert_not_include user.mail, recipients
|
||||
end
|
||||
|
||||
def test_issue_add_should_include_enabled_fields
|
||||
|
@ -374,27 +431,62 @@ class MailerTest < ActiveSupport::TestCase
|
|||
def test_issue_add_should_not_include_disabled_fields
|
||||
issue = Issue.find(2)
|
||||
tracker = issue.tracker
|
||||
tracker.core_fields -= ['fixed_version_id']
|
||||
tracker.core_fields -= ['fixed_version_id', 'start_date']
|
||||
tracker.save!
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
assert_mail_body_no_match 'Target version', last_email
|
||||
assert_mail_body_no_match 'Start date', last_email
|
||||
assert_select_email do
|
||||
assert_select 'li', :text => /Target version/, :count => 0
|
||||
assert_select 'li', :text => /Start date/, :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
# test mailer methods for each language
|
||||
def test_issue_add
|
||||
issue = Issue.find(1)
|
||||
with_each_language_as_default do
|
||||
assert Mailer.deliver_issue_add(issue)
|
||||
def test_issue_add_subject_should_include_status_if_setting_is_enabled
|
||||
with_settings :show_status_changes_in_mail_subject => 1 do
|
||||
issue = Issue.find(2)
|
||||
Mailer.deliver_issue_add(issue)
|
||||
|
||||
mail = last_email
|
||||
assert_equal "[eCookbook - Feature request #2] (Assigned) Add ingredients categories", mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
def test_issue_edit
|
||||
journal = Journal.find(1)
|
||||
with_each_language_as_default do
|
||||
assert Mailer.deliver_issue_edit(journal)
|
||||
def test_issue_add_subject_should_not_include_status_if_setting_is_disabled
|
||||
with_settings :show_status_changes_in_mail_subject => 0 do
|
||||
issue = Issue.find(2)
|
||||
Mailer.deliver_issue_add(issue)
|
||||
|
||||
mail = last_email
|
||||
assert_equal "[eCookbook - Feature request #2] Add ingredients categories", mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
def test_issue_edit_subject_should_include_status_changes_if_setting_is_enabled
|
||||
with_settings :show_status_changes_in_mail_subject => 1 do
|
||||
issue = Issue.find(2)
|
||||
issue.init_journal(User.current)
|
||||
issue.update(:status_id => 4)
|
||||
journal = issue.journals.last
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
|
||||
assert journal.new_value_for('status_id')
|
||||
mail = last_email
|
||||
assert_equal "[eCookbook - Feature request #2] (Feedback) Add ingredients categories", mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
def test_issue_edit_subject_should_not_include_status_changes_if_setting_is_disabled
|
||||
with_settings :show_status_changes_in_mail_subject => 0 do
|
||||
issue = Issue.find(2)
|
||||
issue.init_journal(User.current)
|
||||
issue.update(:status_id => 4)
|
||||
journal = issue.journals.last
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
|
||||
assert journal.new_value_for('status_id')
|
||||
mail = last_email
|
||||
assert_equal "[eCookbook - Feature request #2] Add ingredients categories", mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -404,12 +496,17 @@ 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), recipients
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
Role.find(2).remove_permission! :view_private_notes
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
end
|
||||
assert_equal %w(jsmith@somenet.foo), recipients
|
||||
end
|
||||
|
||||
def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
|
||||
|
@ -420,11 +517,12 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Role.non_member.add_permission! :view_private_notes
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
||||
assert_include 'someone@foo.bar', recipients
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
Role.non_member.remove_permission! :view_private_notes
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
||||
assert_not_include 'someone@foo.bar', recipients
|
||||
end
|
||||
|
||||
def test_issue_edit_should_mark_private_notes
|
||||
|
@ -449,29 +547,36 @@ class MailerTest < ActiveSupport::TestCase
|
|||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
Mailer.deliver_issue_edit(journal)
|
||||
last_email.bcc.each do |email|
|
||||
recipients.each do |email|
|
||||
user = User.find_by_mail(email)
|
||||
assert private_issue.visible?(user), "Issue was not visible to #{user}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_document_added
|
||||
document = Document.find(1)
|
||||
with_each_language_as_default do
|
||||
assert Mailer.document_added(document).deliver
|
||||
end
|
||||
end
|
||||
def test_issue_should_send_email_notification_with_suppress_empty_fields
|
||||
ActionMailer::Base.deliveries.clear
|
||||
with_settings :notified_events => %w(issue_added) do
|
||||
cf = IssueCustomField.generate!
|
||||
issue = Issue.generate!
|
||||
Mailer.deliver_issue_add(issue)
|
||||
|
||||
def test_attachments_added
|
||||
attachements = [ Attachment.find_by_container_type('Document') ]
|
||||
with_each_language_as_default do
|
||||
assert Mailer.attachments_added(attachements).deliver
|
||||
assert_not_equal 0, ActionMailer::Base.deliveries.size
|
||||
|
||||
mail = last_email
|
||||
assert_mail_body_match /^\* Author: /, mail
|
||||
assert_mail_body_match /^\* Status: /, mail
|
||||
assert_mail_body_match /^\* Priority: /, mail
|
||||
|
||||
assert_mail_body_no_match /^\* Assignee: /, mail
|
||||
assert_mail_body_no_match /^\* Category: /, mail
|
||||
assert_mail_body_no_match /^\* Target version: /, mail
|
||||
assert_mail_body_no_match /^\* #{cf.name}: /, mail
|
||||
end
|
||||
end
|
||||
|
||||
def test_version_file_added
|
||||
attachements = [ Attachment.find_by_container_type('Version') ]
|
||||
assert Mailer.attachments_added(attachements).deliver
|
||||
assert Mailer.deliver_attachments_added(attachements)
|
||||
assert_not_nil last_email.bcc
|
||||
assert last_email.bcc.any?
|
||||
assert_select_email do
|
||||
|
@ -481,7 +586,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_project_file_added
|
||||
attachements = [ Attachment.find_by_container_type('Project') ]
|
||||
assert Mailer.attachments_added(attachements).deliver
|
||||
assert Mailer.deliver_attachments_added(attachements)
|
||||
assert_not_nil last_email.bcc
|
||||
assert last_email.bcc.any?
|
||||
assert_select_email do
|
||||
|
@ -489,116 +594,69 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_news_added
|
||||
news = News.first
|
||||
with_each_language_as_default do
|
||||
assert Mailer.news_added(news).deliver
|
||||
end
|
||||
end
|
||||
|
||||
def test_news_added_should_notify_project_news_watchers
|
||||
user1 = User.generate!
|
||||
user2 = User.generate!
|
||||
news = News.find(1)
|
||||
news.project.enabled_module('news').add_watcher(user1)
|
||||
|
||||
Mailer.news_added(news).deliver
|
||||
assert_include user1.mail, last_email.bcc
|
||||
assert_not_include user2.mail, last_email.bcc
|
||||
end
|
||||
|
||||
def test_news_comment_added
|
||||
comment = Comment.find(2)
|
||||
with_each_language_as_default do
|
||||
assert Mailer.news_comment_added(comment).deliver
|
||||
end
|
||||
end
|
||||
|
||||
def test_message_posted
|
||||
message = Message.first
|
||||
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
|
||||
recipients = recipients.compact.uniq
|
||||
with_each_language_as_default do
|
||||
assert Mailer.message_posted(message).deliver
|
||||
end
|
||||
Mailer.deliver_news_added(news)
|
||||
assert_include user1.mail, recipients
|
||||
assert_not_include user2.mail, recipients
|
||||
end
|
||||
|
||||
def test_wiki_content_added
|
||||
content = WikiContent.find(1)
|
||||
with_each_language_as_default do
|
||||
assert_difference 'ActionMailer::Base.deliveries.size' do
|
||||
assert Mailer.wiki_content_added(content).deliver
|
||||
assert_select_email do
|
||||
assert_select 'a[href=?]',
|
||||
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
||||
:text => 'CookBook documentation'
|
||||
end
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', 2 do
|
||||
assert Mailer.deliver_wiki_content_added(content)
|
||||
assert_select_email do
|
||||
assert_select 'a[href=?]',
|
||||
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
||||
:text => 'CookBook documentation'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_wiki_content_updated
|
||||
content = WikiContent.find(1)
|
||||
with_each_language_as_default do
|
||||
assert_difference 'ActionMailer::Base.deliveries.size' do
|
||||
assert Mailer.wiki_content_updated(content).deliver
|
||||
assert_select_email do
|
||||
assert_select 'a[href=?]',
|
||||
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
||||
:text => 'CookBook documentation'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_account_information
|
||||
user = User.find(2)
|
||||
valid_languages.each do |lang|
|
||||
user.update_attribute :language, lang.to_s
|
||||
user.reload
|
||||
assert Mailer.account_information(user, 'pAsswORd').deliver
|
||||
end
|
||||
end
|
||||
|
||||
def test_lost_password
|
||||
token = Token.find(2)
|
||||
valid_languages.each do |lang|
|
||||
token.user.update_attribute :language, lang.to_s
|
||||
token.reload
|
||||
assert Mailer.lost_password(token).deliver
|
||||
assert Mailer.deliver_wiki_content_updated(content)
|
||||
assert_select_email do
|
||||
assert_select 'a[href=?]',
|
||||
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
||||
:text => 'CookBook documentation'
|
||||
end
|
||||
end
|
||||
|
||||
def test_register
|
||||
token = Token.find(1)
|
||||
valid_languages.each do |lang|
|
||||
token.user.update_attribute :language, lang.to_s
|
||||
token.reload
|
||||
ActionMailer::Base.deliveries.clear
|
||||
assert Mailer.register(token).deliver
|
||||
mail = last_email
|
||||
assert_select_email do
|
||||
assert_select "a[href=?]",
|
||||
"http://localhost:3000/account/activate?token=#{token.value}",
|
||||
:text => "http://localhost:3000/account/activate?token=#{token.value}"
|
||||
end
|
||||
assert Mailer.deliver_register(token.user, token)
|
||||
assert_select_email do
|
||||
assert_select "a[href=?]",
|
||||
"http://localhost:3000/account/activate?token=#{token.value}",
|
||||
:text => "http://localhost:3000/account/activate?token=#{token.value}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_test
|
||||
def test_test_email_later
|
||||
user = User.find(1)
|
||||
valid_languages.each do |lang|
|
||||
user.update_attribute :language, lang.to_s
|
||||
assert Mailer.test_email(user).deliver
|
||||
end
|
||||
assert Mailer.test_email(user).deliver_later
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
end
|
||||
|
||||
def test_reminders
|
||||
users(:users_003).pref.update_attribute :time_zone, 'UTC' # dlopper
|
||||
Mailer.reminders(:days => 42)
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
mail = last_email
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
|
||||
assert_mail_body_match 'View all issues (2 open)', mail
|
||||
assert_select_email do
|
||||
assert_select 'a[href=?]',
|
||||
'http://localhost:3000/issues?assigned_to_id=me&set_filter=1&sort=due_date%3Aasc',
|
||||
:text => 'View all issues'
|
||||
assert_select '/p:nth-last-of-type(1)', :text => 'View all issues (2 open)'
|
||||
end
|
||||
assert_equal '1 issue(s) due in the next 42 days', mail.subject
|
||||
end
|
||||
|
||||
|
@ -606,11 +664,12 @@ class MailerTest < ActiveSupport::TestCase
|
|||
with_settings :default_language => 'fr' do
|
||||
user = User.find(3)
|
||||
user.update_attribute :language, ''
|
||||
user.pref.update_attribute :time_zone, 'UTC'
|
||||
Mailer.reminders(:days => 42)
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
mail = last_email
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (En retard de 5 jours)', mail
|
||||
assert_equal "1 demande(s) arrivent à échéance (42)", mail.subject
|
||||
end
|
||||
end
|
||||
|
@ -632,22 +691,29 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_reminders_for_users
|
||||
users(:users_003).pref.update_attribute :time_zone, 'UTC' # dlopper
|
||||
Mailer.reminders(:days => 42, :users => ['5'])
|
||||
assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
|
||||
Mailer.reminders(:days => 42, :users => ['3'])
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
|
||||
mail = last_email
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
||||
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe (5 days late)', mail
|
||||
end
|
||||
|
||||
def test_reminder_should_include_issues_assigned_to_groups
|
||||
with_settings :default_language => 'en', :issue_group_assignment => '1' do
|
||||
group = Group.generate!
|
||||
Member.create!(:project_id => 1, :principal => group, :role_ids => [1])
|
||||
group.users << User.find(2)
|
||||
group.users << User.find(3)
|
||||
[users(:users_002), users(:users_003)].each do |user| # jsmith, dlopper
|
||||
group.users << user
|
||||
user.pref.update_attribute :time_zone, 'UTC'
|
||||
end
|
||||
|
||||
Issue.update_all(:assigned_to_id => nil)
|
||||
due_date = 10.days.from_now
|
||||
Issue.update(1, :due_date => due_date, :assigned_to_id => 3)
|
||||
Issue.update(2, :due_date => due_date, :assigned_to_id => group.id)
|
||||
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
|
||||
:subject => 'Assigned to group', :assigned_to => group,
|
||||
:due_date => 5.days.from_now,
|
||||
|
@ -656,9 +722,11 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Mailer.reminders(:days => 7)
|
||||
assert_equal 2, ActionMailer::Base.deliveries.size
|
||||
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
|
||||
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), recipients
|
||||
ActionMailer::Base.deliveries.each do |mail|
|
||||
assert_mail_body_match 'Assigned to group', mail
|
||||
assert_mail_body_match '1 issue(s) that are assigned to you are due in the next 7 days::', mail
|
||||
assert_mail_body_match 'Assigned to group (Due in 5 days)', mail
|
||||
assert_mail_body_match "View all issues (#{mail.bcc.include?('dlopper@somenet.foo') ? 3 : 2} open)", mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -672,9 +740,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Mailer.reminders(:days => 42, :version => 'acme')
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
|
||||
mail = last_email
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert_include 'dlopper@somenet.foo', recipients
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -691,19 +757,42 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
Mailer.reminders(:days => 42)
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
assert_include 'dlopper@somenet.foo', recipients
|
||||
mail = last_email
|
||||
assert mail.bcc.include?('dlopper@somenet.foo')
|
||||
assert_mail_body_no_match 'Issue dlopper should not see', mail
|
||||
end
|
||||
end
|
||||
|
||||
def test_reminders_should_sort_issues_by_due_date
|
||||
user = User.find(2)
|
||||
user.pref.update_attribute :time_zone, 'UTC'
|
||||
Issue.generate!(:assigned_to => user, :due_date => 2.days.from_now, :subject => 'quux')
|
||||
Issue.generate!(:assigned_to => user, :due_date => 0.days.from_now, :subject => 'baz')
|
||||
Issue.generate!(:assigned_to => user, :due_date => 1.days.from_now, :subject => 'qux')
|
||||
Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'foo')
|
||||
Issue.generate!(:assigned_to => user, :due_date => -1.days.from_now, :subject => 'bar')
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
Mailer.reminders(:days => 7, :users => [user.id])
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
assert_select_email do
|
||||
assert_select 'li', 5
|
||||
assert_select 'li:nth-child(1)', /foo \(1 day late\)/
|
||||
assert_select 'li:nth-child(2)', /bar \(1 day late\)/
|
||||
assert_select 'li:nth-child(3)', /baz \(Due in 0 days\)/
|
||||
assert_select 'li:nth-child(4)', /qux \(Due in 1 day\)/
|
||||
assert_select 'li:nth-child(5)', /quux \(Due in 2 days\)/
|
||||
end
|
||||
end
|
||||
|
||||
def test_security_notification
|
||||
set_language_if_valid User.find(1).language
|
||||
with_settings :emails_footer => "footer without link" do
|
||||
User.current.remote_ip = '192.168.1.1'
|
||||
assert Mailer.security_notification(User.find(1), message: :notice_account_password_updated).deliver
|
||||
sender = User.find(2)
|
||||
sender.remote_ip = '192.168.1.1'
|
||||
assert Mailer.deliver_security_notification(User.find(1), sender, message: :notice_account_password_updated)
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_mail_body_match sender.login, mail
|
||||
assert_mail_body_match '192.168.1.1', mail
|
||||
assert_mail_body_match I18n.t(:notice_account_password_updated), mail
|
||||
assert_select_email do
|
||||
|
@ -713,30 +802,25 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_security_notification_with_overridden_originator_and_remote_ip
|
||||
def test_security_notification_with_overridden_remote_ip
|
||||
set_language_if_valid User.find(1).language
|
||||
with_settings :emails_footer => "footer without link" do
|
||||
User.current.remote_ip = '192.168.1.1'
|
||||
assert Mailer.security_notification(User.find(1), message: :notice_account_password_updated, originator: User.find(2), remote_ip: '10.0.0.42').deliver
|
||||
sender = User.find(2)
|
||||
sender.remote_ip = '192.168.1.1'
|
||||
assert Mailer.deliver_security_notification(User.find(1), sender, message: :notice_account_password_updated, remote_ip: '10.0.0.42')
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_mail_body_match User.find(2).login, mail
|
||||
assert_mail_body_match '10.0.0.42', mail
|
||||
assert_mail_body_match I18n.t(:notice_account_password_updated), mail
|
||||
assert_select_email do
|
||||
assert_select "h1", false
|
||||
assert_select "a", false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_security_notification_should_include_title
|
||||
set_language_if_valid User.find(2).language
|
||||
with_settings :emails_footer => "footer without link" do
|
||||
assert Mailer.security_notification(User.find(2),
|
||||
message: :notice_account_password_updated,
|
||||
title: :label_my_account
|
||||
).deliver
|
||||
assert Mailer.deliver_security_notification(
|
||||
User.find(2), User.find(2),
|
||||
message: :notice_account_password_updated,
|
||||
title: :label_my_account
|
||||
)
|
||||
assert_select_email do
|
||||
assert_select "a", false
|
||||
assert_select "h1", :text => I18n.t(:label_my_account)
|
||||
|
@ -747,11 +831,12 @@ class MailerTest < ActiveSupport::TestCase
|
|||
def test_security_notification_should_include_link
|
||||
set_language_if_valid User.find(3).language
|
||||
with_settings :emails_footer => "footer without link" do
|
||||
assert Mailer.security_notification(User.find(3),
|
||||
message: :notice_account_password_updated,
|
||||
title: :label_my_account,
|
||||
url: {controller: 'my', action: 'account'}
|
||||
).deliver
|
||||
assert Mailer.deliver_security_notification(
|
||||
User.find(3), User.find(3),
|
||||
message: :notice_account_password_updated,
|
||||
title: :label_my_account,
|
||||
url: {controller: 'my', action: 'account'}
|
||||
)
|
||||
assert_select_email do
|
||||
assert_select "h1", false
|
||||
assert_select 'a[href=?]', 'http://localhost:3000/my/account', :text => I18n.t(:label_my_account)
|
||||
|
@ -764,8 +849,9 @@ class MailerTest < ActiveSupport::TestCase
|
|||
set_language_if_valid 'it'
|
||||
# Send an email to a french user
|
||||
user = User.find(1)
|
||||
user.language = 'fr'
|
||||
Mailer.account_activated(user).deliver
|
||||
user.update_attribute :language, 'fr'
|
||||
|
||||
Mailer.deliver_account_activated(user)
|
||||
mail = last_email
|
||||
assert_mail_body_match 'Votre compte', mail
|
||||
|
||||
|
@ -774,7 +860,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_with_deliveries_off
|
||||
Mailer.with_deliveries false do
|
||||
Mailer.test_email(User.find(1)).deliver
|
||||
Mailer.test_email(User.find(1)).deliver_now
|
||||
end
|
||||
assert ActionMailer::Base.deliveries.empty?
|
||||
# should restore perform_deliveries
|
||||
|
@ -783,14 +869,15 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_token_for_should_strip_trailing_gt_from_address_with_full_name
|
||||
with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do
|
||||
assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!)
|
||||
assert_match /\Aredmine.issue-\d+\.\d+\.3@redmine.org\z/,
|
||||
Mailer.token_for(Issue.generate!, User.find(3))
|
||||
end
|
||||
end
|
||||
|
||||
def test_layout_should_include_the_emails_header
|
||||
with_settings :emails_header => "*Header content*" do
|
||||
with_settings :plain_text_mail => 0 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
assert_select_email do
|
||||
assert_select ".header" do
|
||||
assert_select "strong", :text => "Header content"
|
||||
|
@ -798,9 +885,8 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
with_settings :plain_text_mail => 1 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_include "*Header content*", mail.body.decoded
|
||||
end
|
||||
end
|
||||
|
@ -808,7 +894,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_layout_should_not_include_empty_emails_header
|
||||
with_settings :emails_header => "", :plain_text_mail => 0 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
assert_select_email do
|
||||
assert_select ".header", false
|
||||
end
|
||||
|
@ -818,7 +904,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
def test_layout_should_include_the_emails_footer
|
||||
with_settings :emails_footer => "*Footer content*" do
|
||||
with_settings :plain_text_mail => 0 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
assert_select_email do
|
||||
assert_select ".footer" do
|
||||
assert_select "strong", :text => "Footer content"
|
||||
|
@ -826,9 +912,8 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
with_settings :plain_text_mail => 1 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_include "\n-- \n", mail.body.decoded
|
||||
assert_include "*Footer content*", mail.body.decoded
|
||||
end
|
||||
|
@ -838,22 +923,21 @@ class MailerTest < ActiveSupport::TestCase
|
|||
def test_layout_should_not_include_empty_emails_footer
|
||||
with_settings :emails_footer => "" do
|
||||
with_settings :plain_text_mail => 0 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
assert_select_email do
|
||||
assert_select ".footer", false
|
||||
end
|
||||
end
|
||||
with_settings :plain_text_mail => 1 do
|
||||
assert Mailer.test_email(User.find(1)).deliver
|
||||
assert Mailer.test_email(User.find(1)).deliver_now
|
||||
mail = last_email
|
||||
assert_not_nil mail
|
||||
assert_not_include "\n-- \n", mail.body.decoded
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_escape_html_templates_only
|
||||
Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
|
||||
Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>', :notify => true)
|
||||
mail = last_email
|
||||
assert_equal 2, mail.parts.size
|
||||
assert_include '<tag>', text_part.body.encoded
|
||||
|
@ -862,10 +946,10 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
|
||||
mail = Mailer.test_email(User.find(1))
|
||||
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
||||
mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
|
||||
|
||||
ActionMailer::Base.raise_delivery_errors = true
|
||||
assert_raise Exception, "delivery error" do
|
||||
assert_raise StandardError, "delivery error" do
|
||||
mail.deliver
|
||||
end
|
||||
ensure
|
||||
|
@ -874,7 +958,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
|
||||
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
|
||||
mail = Mailer.test_email(User.find(1))
|
||||
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
||||
mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
|
||||
|
||||
Rails.logger.expects(:error).with("Email delivery error: delivery error")
|
||||
ActionMailer::Base.raise_delivery_errors = false
|
||||
|
@ -884,44 +968,44 @@ class MailerTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_with_synched_deliveries_should_yield_with_synced_deliveries
|
||||
ActionMailer::Base.delivery_method = :async_smtp
|
||||
ActionMailer::Base.async_smtp_settings = {:foo => 'bar'}
|
||||
ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new
|
||||
|
||||
Mailer.with_synched_deliveries do
|
||||
assert_equal :smtp, ActionMailer::Base.delivery_method
|
||||
assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings)
|
||||
assert_kind_of ActiveJob::QueueAdapters::InlineAdapter, ActionMailer::DeliveryJob.queue_adapter
|
||||
end
|
||||
assert_equal :async_smtp, ActionMailer::Base.delivery_method
|
||||
assert_kind_of ActiveJob::QueueAdapters::AsyncAdapter, ActionMailer::DeliveryJob.queue_adapter
|
||||
ensure
|
||||
ActionMailer::Base.delivery_method = :test
|
||||
ActionMailer::DeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
|
||||
end
|
||||
|
||||
def test_email_addresses_should_keep_addresses
|
||||
assert_equal ["foo@example.net"],
|
||||
Mailer.email_addresses("foo@example.net")
|
||||
|
||||
Mailer.email_addresses("foo@example.net")
|
||||
assert_equal ["foo@example.net", "bar@example.net"],
|
||||
Mailer.email_addresses(["foo@example.net", "bar@example.net"])
|
||||
Mailer.email_addresses(["foo@example.net", "bar@example.net"])
|
||||
end
|
||||
|
||||
def test_email_addresses_should_replace_users_with_their_email_addresses
|
||||
assert_equal ["admin@somenet.foo"],
|
||||
Mailer.email_addresses(User.find(1))
|
||||
|
||||
Mailer.email_addresses(User.find(1))
|
||||
assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"],
|
||||
Mailer.email_addresses(User.where(:id => [1,2])).sort
|
||||
Mailer.email_addresses(User.where(:id => [1,2])).sort
|
||||
end
|
||||
|
||||
def test_email_addresses_should_include_notified_emails_addresses_only
|
||||
EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false)
|
||||
EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo")
|
||||
|
||||
assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"],
|
||||
Mailer.email_addresses(User.find(2)).sort
|
||||
Mailer.email_addresses(User.find(2)).sort
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns an array of email addresses to which emails were sent
|
||||
def recipients
|
||||
ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
|
||||
end
|
||||
|
||||
def last_email
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_not_nil mail
|
||||
|
@ -936,11 +1020,7 @@ class MailerTest < ActiveSupport::TestCase
|
|||
last_email.parts.detect {|part| part.content_type.include?('text/html')}
|
||||
end
|
||||
|
||||
def with_each_language_as_default(&block)
|
||||
valid_languages.each do |lang|
|
||||
with_settings :default_language => lang.to_s do
|
||||
yield lang
|
||||
end
|
||||
end
|
||||
def destination_user(mail)
|
||||
EmailAddress.where(:address => [mail.to, mail.cc, mail.bcc].flatten).map(&:user).first
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue