kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
529 lines
20 KiB
529 lines
20 KiB
12 years ago
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
12 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
12 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
12 years ago
|
|
||
11 years ago
|
describe UserMailer, type: :mailer do
|
||
9 years ago
|
include ::Rails::Dom::Testing::Assertions::SelectorAssertions
|
||
12 years ago
|
|
||
11 years ago
|
before do
|
||
12 years ago
|
Setting.mail_from = 'john@doe.com'
|
||
|
Setting.host_name = 'mydomain.foo'
|
||
|
Setting.protocol = 'http'
|
||
|
Setting.plain_text_mail = '0'
|
||
|
Setting.default_language = 'en'
|
||
|
|
||
12 years ago
|
User.delete_all
|
||
11 years ago
|
WorkPackage.delete_all
|
||
12 years ago
|
Project.delete_all
|
||
10 years ago
|
::Type.delete_all
|
||
11 years ago
|
|
||
|
User.current = User.anonymous
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
11 years ago
|
it 'should test mail sends a simple greeting' do
|
||
10 years ago
|
user = FactoryGirl.create(:user, mail: 'foo@bar.de')
|
||
12 years ago
|
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
|
|
||
12 years ago
|
mail = UserMailer.test_mail(user)
|
||
9 years ago
|
assert mail.deliver_now
|
||
12 years ago
|
|
||
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
12 years ago
|
|
||
|
assert_equal 'OpenProject Test', mail.subject
|
||
12 years ago
|
assert_equal ['foo@bar.de'], mail.to
|
||
12 years ago
|
assert_equal ['john@doe.com'], mail.from
|
||
|
assert_match /OpenProject URL/, mail.body.encoded
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should generated links in emails' do
|
||
12 years ago
|
Setting.default_language = 'en'
|
||
|
Setting.host_name = 'mydomain.foo'
|
||
|
Setting.protocol = 'https'
|
||
12 years ago
|
User.current = FactoryGirl.create(:admin)
|
||
12 years ago
|
|
||
12 years ago
|
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
|
||
12 years ago
|
|
||
9 years ago
|
assert UserMailer.work_package_updated(user, journal).deliver_now
|
||
12 years ago
|
assert last_email
|
||
12 years ago
|
|
||
|
assert_select_email do
|
||
|
# link to the main ticket
|
||
|
assert_select 'a[href=?]',
|
||
11 years ago
|
"https://mydomain.foo/work_packages/#{issue.id}",
|
||
10 years ago
|
text: "My Type ##{issue.id}: My awesome Ticket"
|
||
12 years ago
|
# link to a description diff
|
||
10 years ago
|
assert_select 'li', text: /Description changed/
|
||
12 years ago
|
assert_select 'li>a[href=?]',
|
||
|
"https://mydomain.foo/journals/#{journal.id}/diff/description",
|
||
10 years ago
|
text: 'Details'
|
||
12 years ago
|
# link to a referenced ticket
|
||
12 years ago
|
assert_select 'a[href=?][title=?]',
|
||
12 years ago
|
"https://mydomain.foo/work_packages/#{related_issue.id}",
|
||
12 years ago
|
"My related Ticket (#{related_issue.status})",
|
||
10 years ago
|
text: "##{related_issue.id}"
|
||
12 years ago
|
# link to a changeset
|
||
10 years ago
|
if changeset
|
||
|
assert_select 'a[href=?][title=?]',
|
||
10 years ago
|
url_for(controller: 'repositories',
|
||
|
action: 'revision',
|
||
|
project_id: project,
|
||
|
rev: changeset.revision),
|
||
10 years ago
|
'This commit fixes #1, #2 and references #1 and #3',
|
||
10 years ago
|
text: "r#{changeset.revision}"
|
||
10 years ago
|
end
|
||
12 years ago
|
# link to an attachment
|
||
|
assert_select 'a[href=?]',
|
||
12 years ago
|
"https://mydomain.foo/attachments/#{attachment.id}/download",
|
||
10 years ago
|
text: "#{attachment.filename}"
|
||
12 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should generated links with prefix' do
|
||
12 years ago
|
Setting.default_language = 'en'
|
||
|
Setting.host_name = 'mydomain.foo/rdm'
|
||
|
Setting.protocol = 'http'
|
||
12 years ago
|
User.current = FactoryGirl.create(:admin)
|
||
12 years ago
|
|
||
12 years ago
|
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
|
||
12 years ago
|
|
||
9 years ago
|
assert UserMailer.work_package_updated(user, journal).deliver_now
|
||
12 years ago
|
assert last_email
|
||
12 years ago
|
|
||
|
assert_select_email do
|
||
|
# link to the main ticket
|
||
|
assert_select 'a[href=?]',
|
||
11 years ago
|
"http://mydomain.foo/rdm/work_packages/#{issue.id}",
|
||
10 years ago
|
text: "My Type ##{issue.id}: My awesome Ticket"
|
||
12 years ago
|
# link to a description diff
|
||
10 years ago
|
assert_select 'li', text: /Description changed/
|
||
12 years ago
|
assert_select 'li>a[href=?]',
|
||
|
"http://mydomain.foo/rdm/journals/#{journal.id}/diff/description",
|
||
10 years ago
|
text: 'Details'
|
||
12 years ago
|
# link to a referenced ticket
|
||
12 years ago
|
assert_select 'a[href=?][title=?]',
|
||
12 years ago
|
"http://mydomain.foo/rdm/work_packages/#{related_issue.id}",
|
||
12 years ago
|
"My related Ticket (#{related_issue.status})",
|
||
10 years ago
|
text: "##{related_issue.id}"
|
||
12 years ago
|
# link to a changeset
|
||
10 years ago
|
if changeset
|
||
|
assert_select 'a[href=?][title=?]',
|
||
10 years ago
|
url_for(controller: 'repositories',
|
||
|
action: 'revision',
|
||
|
project_id: project,
|
||
|
rev: changeset.revision),
|
||
10 years ago
|
'This commit fixes #1, #2 and references #1 and #3',
|
||
10 years ago
|
text: "r#{changeset.revision}"
|
||
10 years ago
|
end
|
||
12 years ago
|
# link to an attachment
|
||
|
assert_select 'a[href=?]',
|
||
12 years ago
|
"http://mydomain.foo/rdm/attachments/#{attachment.id}/download",
|
||
10 years ago
|
text: "#{attachment.filename}"
|
||
12 years ago
|
end
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should generated links with prefix and no relative url root' do
|
||
|
begin
|
||
|
Setting.default_language = 'en'
|
||
|
relative_url_root = OpenProject::Configuration['rails_relative_url_root']
|
||
|
Setting.host_name = 'mydomain.foo/rdm'
|
||
|
Setting.protocol = 'http'
|
||
|
OpenProject::Configuration['rails_relative_url_root'] = nil
|
||
|
|
||
|
User.current = FactoryGirl.create(:admin)
|
||
|
|
||
|
project, user, related_issue, issue, changeset, attachment, journal = setup_complex_issue_update
|
||
|
|
||
9 years ago
|
assert UserMailer.work_package_updated(user, journal).deliver_now
|
||
11 years ago
|
assert last_email
|
||
|
|
||
|
assert_select_email do
|
||
|
# link to the main ticket
|
||
|
assert_select 'a[href=?]',
|
||
|
"http://mydomain.foo/rdm/work_packages/#{issue.id}",
|
||
|
text: "My Type ##{issue.id}: My awesome Ticket"
|
||
|
# link to a description diff
|
||
|
assert_select 'li', text: /Description changed/
|
||
|
assert_select 'li>a[href=?]',
|
||
|
"http://mydomain.foo/rdm/journals/#{journal.id}/diff/description",
|
||
|
text: 'Details'
|
||
|
# link to a referenced ticket
|
||
10 years ago
|
assert_select 'a[href=?][title=?]',
|
||
11 years ago
|
"http://mydomain.foo/rdm/work_packages/#{related_issue.id}",
|
||
|
"My related Ticket (#{related_issue.status})",
|
||
|
text: "##{related_issue.id}"
|
||
|
# link to a changeset
|
||
|
if changeset
|
||
|
assert_select 'a[href=?][title=?]',
|
||
|
url_for(controller: 'repositories',
|
||
|
action: 'revision',
|
||
|
project_id: project,
|
||
|
rev: changeset.revision),
|
||
|
'This commit fixes #1, #2 and references #1 and #3',
|
||
|
text: "r#{changeset.revision}"
|
||
|
end
|
||
|
# link to an attachment
|
||
|
assert_select 'a[href=?]',
|
||
|
"http://mydomain.foo/rdm/attachments/#{attachment.id}/download",
|
||
|
text: "#{attachment.filename}"
|
||
10 years ago
|
end
|
||
11 years ago
|
ensure
|
||
|
# restore it
|
||
|
OpenProject::Configuration['rails_relative_url_root'] = relative_url_root
|
||
12 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should email headers' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
9 years ago
|
mail = UserMailer.work_package_added(user, issue.journals.first, user)
|
||
9 years ago
|
assert mail.deliver_now
|
||
9 years ago
|
refute_nil mail
|
||
12 years ago
|
assert_equal 'bulk', mail.header['Precedence'].to_s
|
||
|
assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
10 years ago
|
it 'sends plain text mail' do
|
||
12 years ago
|
Setting.plain_text_mail = 1
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
9 years ago
|
UserMailer.work_package_added(user, issue.journals.first, user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
10 years ago
|
assert_match /text\/plain/, mail.content_type
|
||
|
assert_equal 0, mail.parts.size
|
||
12 years ago
|
assert !mail.encoded.include?('href')
|
||
12 years ago
|
end
|
||
|
|
||
10 years ago
|
it 'sends html mail' do
|
||
12 years ago
|
Setting.plain_text_mail = 0
|
||
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
9 years ago
|
UserMailer.work_package_added(user, issue.journals.first, user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
12 years ago
|
assert_match /multipart\/alternative/, mail.content_type
|
||
|
assert_equal 2, mail.parts.size
|
||
|
assert mail.encoded.include?('href')
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should mail from with phrase' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
10 years ago
|
with_settings mail_from: 'Redmine app <redmine@example.net>' do
|
||
9 years ago
|
UserMailer.test_mail(user).deliver_now
|
||
12 years ago
|
end
|
||
|
mail = ActionMailer::Base.deliveries.last
|
||
9 years ago
|
refute_nil mail
|
||
12 years ago
|
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not send email without recipient' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
|
news = FactoryGirl.create(:news)
|
||
12 years ago
|
|
||
12 years ago
|
# notify him
|
||
12 years ago
|
user.pref[:no_self_notified] = false
|
||
|
user.pref.save
|
||
|
User.current = user
|
||
12 years ago
|
ActionMailer::Base.deliveries.clear
|
||
9 years ago
|
UserMailer.news_added(user, news, user).deliver_now
|
||
12 years ago
|
assert_equal 1, last_email.to.size
|
||
12 years ago
|
|
||
12 years ago
|
# nobody to notify
|
||
|
user.pref[:no_self_notified] = true
|
||
|
user.pref.save
|
||
|
User.current = user
|
||
|
ActionMailer::Base.deliveries.clear
|
||
9 years ago
|
UserMailer.news_added(user, news, user).deliver_now
|
||
12 years ago
|
assert ActionMailer::Base.deliveries.empty?
|
||
|
end
|
||
12 years ago
|
|
||
11 years ago
|
it 'should issue add message id' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
9 years ago
|
mail = UserMailer.work_package_added(user, issue.journals.first, user)
|
||
9 years ago
|
mail.deliver_now
|
||
9 years ago
|
refute_nil mail
|
||
11 years ago
|
assert_equal UserMailer.generate_message_id(issue, user), mail.message_id
|
||
12 years ago
|
assert_nil mail.references
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should work package updated message id' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
12 years ago
|
journal = issue.journals.first
|
||
9 years ago
|
UserMailer.work_package_updated(user, journal).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
9 years ago
|
refute_nil mail
|
||
11 years ago
|
assert_equal UserMailer.generate_message_id(journal, user), mail.message_id
|
||
|
assert_match mail.references, UserMailer.generate_message_id(journal.journable, user)
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should message posted message id' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
12 years ago
|
message = FactoryGirl.create(:message)
|
||
9 years ago
|
UserMailer.message_posted(user, message, user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
9 years ago
|
refute_nil mail
|
||
11 years ago
|
assert_equal UserMailer.generate_message_id(message, user), mail.message_id
|
||
12 years ago
|
assert_nil mail.references
|
||
|
assert_select_email do
|
||
|
# link to the message
|
||
10 years ago
|
assert_select 'a[href*=?]', "#{Setting.protocol}://#{Setting.host_name}/topics/#{message.id}", text: message.subject
|
||
12 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should reply posted message id' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
12 years ago
|
parent = FactoryGirl.create(:message)
|
||
10 years ago
|
message = FactoryGirl.create(:message, parent: parent)
|
||
9 years ago
|
UserMailer.message_posted(user, message, user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
9 years ago
|
refute_nil mail
|
||
11 years ago
|
assert_equal UserMailer.generate_message_id(message, user), mail.message_id
|
||
|
assert_match mail.references, UserMailer.generate_message_id(parent, user)
|
||
12 years ago
|
assert_select_email do
|
||
|
# link to the reply
|
||
10 years ago
|
assert_select 'a[href=?]', "#{Setting.protocol}://#{Setting.host_name}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", text: message.subject
|
||
12 years ago
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context('#issue_add') do
|
||
11 years ago
|
it 'should change mail language depending on recipient language' do
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
10 years ago
|
user = FactoryGirl.create(:user, mail: 'foo@bar.de', language: 'de')
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
9 years ago
|
|
||
10 years ago
|
with_settings available_languages: ['en', 'de'] do
|
||
12 years ago
|
I18n.locale = 'en'
|
||
9 years ago
|
assert UserMailer.work_package_added(user, issue.journals.first, user).deliver_now
|
||
12 years ago
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
|
mail = last_email
|
||
|
assert_equal ['foo@bar.de'], mail.to
|
||
|
assert mail.body.encoded.include?('erstellt')
|
||
|
assert !mail.body.encoded.include?('reported')
|
||
|
assert_equal :en, I18n.locale
|
||
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should falls back to default language if user has no language' do
|
||
12 years ago
|
# 1. user's language
|
||
|
# 2. Setting.default_language
|
||
|
# 3. I18n.default_locale
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package)
|
||
10 years ago
|
user = FactoryGirl.create(:user, mail: 'foo@bar.de', language: '') # (auto)
|
||
9 years ago
|
FactoryGirl.create(:user_preference, user: user, others: { no_self_notified: false })
|
||
9 years ago
|
|
||
10 years ago
|
with_settings available_languages: ['en', 'de'],
|
||
|
default_language: 'de' do
|
||
12 years ago
|
I18n.locale = 'de'
|
||
9 years ago
|
assert UserMailer.work_package_added(user, issue.journals.first, user).deliver_now
|
||
12 years ago
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
|
mail = last_email
|
||
|
assert_equal ['foo@bar.de'], mail.to
|
||
|
assert !mail.body.encoded.include?('reported')
|
||
|
assert mail.body.encoded.include?('erstellt')
|
||
12 years ago
|
assert_equal :de, I18n.locale
|
||
12 years ago
|
end
|
||
|
end
|
||
12 years ago
|
end
|
||
12 years ago
|
|
||
11 years ago
|
it 'should news added' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
|
news = FactoryGirl.create(:news)
|
||
9 years ago
|
assert UserMailer.news_added(user, news, user).deliver_now
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should news comment added' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
|
news = FactoryGirl.create(:news)
|
||
10 years ago
|
comment = FactoryGirl.create(:comment, commented: news)
|
||
9 years ago
|
assert UserMailer.news_comment_added(user, comment, user).deliver_now
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should message posted' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
|
message = FactoryGirl.create(:message)
|
||
9 years ago
|
assert UserMailer.message_posted(user, message, user).deliver_now
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should account information' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
9 years ago
|
assert UserMailer.account_information(user, 'pAsswORd').deliver_now
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should lost password' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
10 years ago
|
token = FactoryGirl.create(:token, user: user)
|
||
9 years ago
|
assert UserMailer.password_lost(token).deliver_now
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should register' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
10 years ago
|
token = FactoryGirl.create(:token, user: user)
|
||
12 years ago
|
Setting.host_name = 'redmine.foo'
|
||
|
Setting.protocol = 'https'
|
||
|
|
||
|
mail = UserMailer.user_signed_up(token)
|
||
9 years ago
|
assert mail.deliver_now
|
||
12 years ago
|
assert mail.body.encoded.include?("https://redmine.foo/account/activate?token=#{token.value}")
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should reminders' do
|
||
10 years ago
|
user = FactoryGirl.create(:user, mail: 'foo@bar.de')
|
||
|
issue = FactoryGirl.create(:work_package, due_date: Date.tomorrow, assigned_to: user, subject: 'some issue')
|
||
9 years ago
|
|
||
12 years ago
|
DueIssuesReminder.new(42).remind_users
|
||
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
|
mail = ActionMailer::Base.deliveries.last
|
||
12 years ago
|
assert mail.to.include?('foo@bar.de')
|
||
11 years ago
|
assert mail.body.encoded.include?("#{issue.project.name} - #{issue.type.name} ##{issue.id}: some issue")
|
||
11 years ago
|
assert_equal '1 work package(s) due in the next 42 days', mail.subject
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should reminders for users' do
|
||
10 years ago
|
user1 = FactoryGirl.create(:user, mail: 'foo1@bar.de')
|
||
|
user2 = FactoryGirl.create(:user, mail: 'foo2@bar.de')
|
||
|
issue = FactoryGirl.create(:work_package, due_date: Date.tomorrow, assigned_to: user1, subject: 'some issue')
|
||
12 years ago
|
|
||
|
DueIssuesReminder.new(42, nil, nil, [user2.id]).remind_users
|
||
12 years ago
|
assert_equal 0, ActionMailer::Base.deliveries.size
|
||
|
|
||
12 years ago
|
DueIssuesReminder.new(42, nil, nil, [user1.id]).remind_users
|
||
12 years ago
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
|
|
||
|
mail = ActionMailer::Base.deliveries.last
|
||
12 years ago
|
assert mail.to.include?('foo1@bar.de')
|
||
11 years ago
|
assert mail.body.encoded.include?("#{issue.project.name} - #{issue.type.name} ##{issue.id}: some issue")
|
||
11 years ago
|
assert_equal '1 work package(s) due in the next 42 days', mail.subject
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should mailer should not change locale' do
|
||
10 years ago
|
with_settings available_languages: ['en', 'de'],
|
||
|
default_language: 'en' do
|
||
12 years ago
|
# Set current language to english
|
||
|
I18n.locale = :en
|
||
|
# Send an email to a german user
|
||
10 years ago
|
user = FactoryGirl.create(:user, language: 'de')
|
||
9 years ago
|
UserMailer.account_activated(user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
12 years ago
|
assert mail.body.encoded.include?('aktiviert')
|
||
|
assert_equal :en, I18n.locale
|
||
12 years ago
|
end
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should with deliveries off' do
|
||
12 years ago
|
user = FactoryGirl.create(:user)
|
||
|
UserMailer.with_deliveries(false) do
|
||
9 years ago
|
UserMailer.test_mail(user).deliver_now
|
||
12 years ago
|
end
|
||
|
assert ActionMailer::Base.deliveries.empty?
|
||
|
# should restore perform_deliveries
|
||
|
assert ActionMailer::Base.perform_deliveries
|
||
|
end
|
||
12 years ago
|
|
||
10 years ago
|
context 'layout' do
|
||
11 years ago
|
it 'should include the emails_header depeding on the locale' do
|
||
10 years ago
|
with_settings available_languages: [:en, :de],
|
||
10 years ago
|
emails_header: { 'de' => 'deutscher header',
|
||
|
'en' => 'english header' } do
|
||
10 years ago
|
user = FactoryGirl.create(:user, language: :en)
|
||
9 years ago
|
assert UserMailer.test_mail(user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
|
assert mail.body.encoded.include?('english header')
|
||
|
user.language = :de
|
||
9 years ago
|
assert UserMailer.test_mail(user).deliver_now
|
||
12 years ago
|
mail = ActionMailer::Base.deliveries.last
|
||
|
assert mail.body.encoded.include?('deutscher header')
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
private
|
||
12 years ago
|
|
||
|
def last_email
|
||
|
mail = ActionMailer::Base.deliveries.last
|
||
9 years ago
|
refute_nil mail
|
||
12 years ago
|
mail
|
||
|
end
|
||
12 years ago
|
|
||
|
def setup_complex_issue_update
|
||
|
project = FactoryGirl.create(:valid_project)
|
||
10 years ago
|
user = FactoryGirl.create(:user, member_in_project: project)
|
||
|
type = FactoryGirl.create(:type, name: 'My Type')
|
||
11 years ago
|
project.types << type
|
||
12 years ago
|
project.save
|
||
|
|
||
11 years ago
|
related_issue = FactoryGirl.create(:work_package,
|
||
10 years ago
|
subject: 'My related Ticket',
|
||
|
type: type,
|
||
|
project: project)
|
||
12 years ago
|
|
||
11 years ago
|
issue = FactoryGirl.create(:work_package,
|
||
10 years ago
|
subject: 'My awesome Ticket',
|
||
|
type: type,
|
||
|
project: project,
|
||
|
description: 'nothing here yet')
|
||
12 years ago
|
|
||
|
# now change the issue, to get a nice journal
|
||
10 years ago
|
issue.description = "This is related to issue ##{related_issue.id}\n"
|
||
|
|
||
9 years ago
|
repository = FactoryGirl.create(:repository_subversion,
|
||
10 years ago
|
project: project)
|
||
|
|
||
9 years ago
|
changeset = FactoryGirl.create :changeset,
|
||
10 years ago
|
repository: repository,
|
||
|
comments: 'This commit fixes #1, #2 and references #1 and #3'
|
||
10 years ago
|
|
||
|
issue.description += " A reference to a changeset r#{changeset.revision}\n" if changeset
|
||
|
|
||
12 years ago
|
attachment = FactoryGirl.create(:attachment,
|
||
10 years ago
|
container: issue,
|
||
|
author: issue.author)
|
||
10 years ago
|
|
||
|
issue.description += " A reference to an attachment attachment:#{attachment.filename}"
|
||
|
|
||
12 years ago
|
assert issue.save
|
||
|
issue.reload
|
||
|
journal = issue.journals.last
|
||
|
|
||
|
ActionMailer::Base.deliveries = [] # remove issue-created mails
|
||
|
|
||
|
[project, user, related_issue, issue, changeset, attachment, journal]
|
||
|
end
|
||
11 years ago
|
|
||
|
def url_for(options)
|
||
10 years ago
|
options.merge!(host: Setting.host_name, protocol: Setting.protocol)
|
||
11 years ago
|
Rails.application.routes.url_helpers.url_for options
|
||
|
end
|
||
12 years ago
|
end
|