|
@@
-1,890
+1,894
|
|
1
|
# Redmine - project management software
|
|
1
|
# Redmine - project management software
|
|
2
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
|
2
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
|
3
|
#
|
|
3
|
#
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
7
|
# of the License, or (at your option) any later version.
|
|
7
|
# of the License, or (at your option) any later version.
|
|
8
|
#
|
|
8
|
#
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
# GNU General Public License for more details.
|
|
12
|
# GNU General Public License for more details.
|
|
13
|
#
|
|
13
|
#
|
|
14
|
# You should have received a copy of the GNU General Public License
|
|
14
|
# You should have received a copy of the GNU General Public License
|
|
15
|
# along with this program; if not, write to the Free Software
|
|
15
|
# along with this program; if not, write to the Free Software
|
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17
|
|
|
17
|
|
|
18
|
require File.expand_path('../../test_helper', __FILE__)
|
|
18
|
require File.expand_path('../../test_helper', __FILE__)
|
|
19
|
|
|
19
|
|
|
20
|
class MailerTest < ActiveSupport::TestCase
|
|
20
|
class MailerTest < ActiveSupport::TestCase
|
|
21
|
include Redmine::I18n
|
|
21
|
include Redmine::I18n
|
|
22
|
include Rails::Dom::Testing::Assertions
|
|
22
|
include Rails::Dom::Testing::Assertions
|
|
23
|
fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :user_preferences, :members,
|
|
23
|
fixtures :projects, :enabled_modules, :issues, :users, :email_addresses, :user_preferences, :members,
|
|
24
|
:member_roles, :roles, :documents, :attachments, :news,
|
|
24
|
:member_roles, :roles, :documents, :attachments, :news,
|
|
25
|
:tokens, :journals, :journal_details, :changesets,
|
|
25
|
:tokens, :journals, :journal_details, :changesets,
|
|
26
|
:trackers, :projects_trackers,
|
|
26
|
:trackers, :projects_trackers,
|
|
27
|
:issue_statuses, :enumerations, :messages, :boards, :repositories,
|
|
27
|
:issue_statuses, :enumerations, :messages, :boards, :repositories,
|
|
28
|
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
|
|
28
|
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
|
|
29
|
:versions,
|
|
29
|
:versions,
|
|
30
|
:comments
|
|
30
|
:comments
|
|
31
|
|
|
31
|
|
|
32
|
def setup
|
|
32
|
def setup
|
|
33
|
ActionMailer::Base.deliveries.clear
|
|
33
|
ActionMailer::Base.deliveries.clear
|
|
34
|
Setting.plain_text_mail = '0'
|
|
34
|
Setting.plain_text_mail = '0'
|
|
35
|
Setting.default_language = 'en'
|
|
35
|
Setting.default_language = 'en'
|
|
36
|
User.current = nil
|
|
36
|
User.current = nil
|
|
37
|
end
|
|
37
|
end
|
|
38
|
|
|
38
|
|
|
39
|
def test_generated_links_in_emails
|
|
39
|
def test_generated_links_in_emails
|
|
40
|
with_settings :host_name => 'mydomain.foo', :protocol => 'https' do
|
|
40
|
with_settings :host_name => 'mydomain.foo', :protocol => 'https' do
|
|
41
|
journal = Journal.find(3)
|
|
41
|
journal = Journal.find(3)
|
|
42
|
assert Mailer.deliver_issue_edit(journal)
|
|
42
|
assert Mailer.deliver_issue_edit(journal)
|
|
43
|
end
|
|
43
|
end
|
|
44
|
mail = last_email
|
|
44
|
mail = last_email
|
|
45
|
assert_not_nil mail
|
|
45
|
assert_not_nil mail
|
|
46
|
|
|
46
|
|
|
47
|
assert_select_email do
|
|
47
|
assert_select_email do
|
|
|
|
|
48
|
# link to the main ticket on issue id
|
|
|
|
|
49
|
assert_select 'a[href=?]',
|
|
|
|
|
50
|
'https://mydomain.foo/issues/2#change-3',
|
|
|
|
|
51
|
:text => '#2'
|
|
48
|
# link to the main ticket
|
|
52
|
# link to the main ticket
|
|
49
|
assert_select 'a[href=?]',
|
|
53
|
assert_select 'a[href=?]',
|
|
50
|
'https://mydomain.foo/issues/2#change-3',
|
|
54
|
'https://mydomain.foo/issues/2#change-3',
|
|
51
|
:text => 'Feature request #2: Add ingredients categories'
|
|
55
|
:text => 'Feature request #2: Add ingredients categories'
|
|
52
|
# link to a referenced ticket
|
|
56
|
# link to a referenced ticket
|
|
53
|
assert_select 'a[href=?][title=?]',
|
|
57
|
assert_select 'a[href=?][title=?]',
|
|
54
|
'https://mydomain.foo/issues/1',
|
|
58
|
'https://mydomain.foo/issues/1',
|
|
55
|
"Bug: Cannot print recipes (New)",
|
|
59
|
"Bug: Cannot print recipes (New)",
|
|
56
|
:text => '#1'
|
|
60
|
:text => '#1'
|
|
57
|
# link to a changeset
|
|
61
|
# link to a changeset
|
|
58
|
assert_select 'a[href=?][title=?]',
|
|
62
|
assert_select 'a[href=?][title=?]',
|
|
59
|
'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
|
|
63
|
'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
|
|
60
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
64
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
61
|
:text => 'r2'
|
|
65
|
:text => 'r2'
|
|
62
|
# link to a description diff
|
|
66
|
# link to a description diff
|
|
63
|
assert_select 'a[href^=?][title=?]',
|
|
67
|
assert_select 'a[href^=?][title=?]',
|
|
64
|
# should be https://mydomain.foo/journals/diff/3?detail_id=4
|
|
68
|
# should be https://mydomain.foo/journals/diff/3?detail_id=4
|
|
65
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
69
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
66
|
# attribute value
|
|
70
|
# attribute value
|
|
67
|
'https://mydomain.foo/journals/3/diff',
|
|
71
|
'https://mydomain.foo/journals/3/diff',
|
|
68
|
'View differences',
|
|
72
|
'View differences',
|
|
69
|
:text => 'diff'
|
|
73
|
:text => 'diff'
|
|
70
|
# link to an attachment
|
|
74
|
# link to an attachment
|
|
71
|
assert_select 'a[href=?]',
|
|
75
|
assert_select 'a[href=?]',
|
|
72
|
'https://mydomain.foo/attachments/download/4/source.rb',
|
|
76
|
'https://mydomain.foo/attachments/download/4/source.rb',
|
|
73
|
:text => 'source.rb'
|
|
77
|
:text => 'source.rb'
|
|
74
|
end
|
|
78
|
end
|
|
75
|
end
|
|
79
|
end
|
|
76
|
|
|
80
|
|
|
77
|
def test_generated_links_with_prefix
|
|
81
|
def test_generated_links_with_prefix
|
|
78
|
relative_url_root = Redmine::Utils.relative_url_root
|
|
82
|
relative_url_root = Redmine::Utils.relative_url_root
|
|
79
|
with_settings :host_name => 'mydomain.foo/rdm', :protocol => 'http' do
|
|
83
|
with_settings :host_name => 'mydomain.foo/rdm', :protocol => 'http' do
|
|
80
|
journal = Journal.find(3)
|
|
84
|
journal = Journal.find(3)
|
|
81
|
assert Mailer.deliver_issue_edit(journal)
|
|
85
|
assert Mailer.deliver_issue_edit(journal)
|
|
82
|
end
|
|
86
|
end
|
|
83
|
|
|
87
|
|
|
84
|
mail = last_email
|
|
88
|
mail = last_email
|
|
85
|
assert_not_nil mail
|
|
89
|
assert_not_nil mail
|
|
86
|
|
|
90
|
|
|
87
|
assert_select_email do
|
|
91
|
assert_select_email do
|
|
88
|
# link to the main ticket
|
|
92
|
# link to the main ticket
|
|
89
|
assert_select 'a[href=?]',
|
|
93
|
assert_select 'a[href=?]',
|
|
90
|
'http://mydomain.foo/rdm/issues/2#change-3',
|
|
94
|
'http://mydomain.foo/rdm/issues/2#change-3',
|
|
91
|
:text => 'Feature request #2: Add ingredients categories'
|
|
95
|
:text => 'Feature request #2: Add ingredients categories'
|
|
92
|
# link to a referenced ticket
|
|
96
|
# link to a referenced ticket
|
|
93
|
assert_select 'a[href=?][title=?]',
|
|
97
|
assert_select 'a[href=?][title=?]',
|
|
94
|
'http://mydomain.foo/rdm/issues/1',
|
|
98
|
'http://mydomain.foo/rdm/issues/1',
|
|
95
|
"Bug: Cannot print recipes (New)",
|
|
99
|
"Bug: Cannot print recipes (New)",
|
|
96
|
:text => '#1'
|
|
100
|
:text => '#1'
|
|
97
|
# link to a changeset
|
|
101
|
# link to a changeset
|
|
98
|
assert_select 'a[href=?][title=?]',
|
|
102
|
assert_select 'a[href=?][title=?]',
|
|
99
|
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
|
103
|
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
|
100
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
104
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
101
|
:text => 'r2'
|
|
105
|
:text => 'r2'
|
|
102
|
# link to a description diff
|
|
106
|
# link to a description diff
|
|
103
|
assert_select 'a[href^=?][title=?]',
|
|
107
|
assert_select 'a[href^=?][title=?]',
|
|
104
|
# should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
|
|
108
|
# should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
|
|
105
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
109
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
106
|
# attribute value
|
|
110
|
# attribute value
|
|
107
|
'http://mydomain.foo/rdm/journals/3/diff',
|
|
111
|
'http://mydomain.foo/rdm/journals/3/diff',
|
|
108
|
'View differences',
|
|
112
|
'View differences',
|
|
109
|
:text => 'diff'
|
|
113
|
:text => 'diff'
|
|
110
|
# link to an attachment
|
|
114
|
# link to an attachment
|
|
111
|
assert_select 'a[href=?]',
|
|
115
|
assert_select 'a[href=?]',
|
|
112
|
'http://mydomain.foo/rdm/attachments/download/4/source.rb',
|
|
116
|
'http://mydomain.foo/rdm/attachments/download/4/source.rb',
|
|
113
|
:text => 'source.rb'
|
|
117
|
:text => 'source.rb'
|
|
114
|
end
|
|
118
|
end
|
|
115
|
end
|
|
119
|
end
|
|
116
|
|
|
120
|
|
|
117
|
def test_generated_links_with_port_and_prefix
|
|
121
|
def test_generated_links_with_port_and_prefix
|
|
118
|
with_settings :host_name => '10.0.0.1:81/redmine', :protocol => 'http' do
|
|
122
|
with_settings :host_name => '10.0.0.1:81/redmine', :protocol => 'http' do
|
|
119
|
Mailer.test_email(User.find(1)).deliver
|
|
123
|
Mailer.test_email(User.find(1)).deliver
|
|
120
|
mail = last_email
|
|
124
|
mail = last_email
|
|
121
|
assert_not_nil mail
|
|
125
|
assert_not_nil mail
|
|
122
|
assert_include 'http://10.0.0.1:81/redmine', mail_body(mail)
|
|
126
|
assert_include 'http://10.0.0.1:81/redmine', mail_body(mail)
|
|
123
|
end
|
|
127
|
end
|
|
124
|
end
|
|
128
|
end
|
|
125
|
|
|
129
|
|
|
126
|
def test_generated_links_with_port
|
|
130
|
def test_generated_links_with_port
|
|
127
|
with_settings :host_name => '10.0.0.1:81', :protocol => 'http' do
|
|
131
|
with_settings :host_name => '10.0.0.1:81', :protocol => 'http' do
|
|
128
|
Mailer.test_email(User.find(1)).deliver
|
|
132
|
Mailer.test_email(User.find(1)).deliver
|
|
129
|
mail = last_email
|
|
133
|
mail = last_email
|
|
130
|
assert_not_nil mail
|
|
134
|
assert_not_nil mail
|
|
131
|
assert_include 'http://10.0.0.1:81', mail_body(mail)
|
|
135
|
assert_include 'http://10.0.0.1:81', mail_body(mail)
|
|
132
|
end
|
|
136
|
end
|
|
133
|
end
|
|
137
|
end
|
|
134
|
|
|
138
|
|
|
135
|
def test_issue_edit_should_generate_url_with_hostname_for_relations
|
|
139
|
def test_issue_edit_should_generate_url_with_hostname_for_relations
|
|
136
|
journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now)
|
|
140
|
journal = Journal.new(:journalized => Issue.find(1), :user => User.find(1), :created_on => Time.now)
|
|
137
|
journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2)
|
|
141
|
journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2)
|
|
138
|
Mailer.deliver_issue_edit(journal)
|
|
142
|
Mailer.deliver_issue_edit(journal)
|
|
139
|
assert_not_nil last_email
|
|
143
|
assert_not_nil last_email
|
|
140
|
assert_select_email do
|
|
144
|
assert_select_email do
|
|
141
|
assert_select 'a[href=?]', 'http://localhost:3000/issues/2', :text => 'Feature request #2'
|
|
145
|
assert_select 'a[href=?]', 'http://localhost:3000/issues/2', :text => 'Feature request #2'
|
|
142
|
end
|
|
146
|
end
|
|
143
|
end
|
|
147
|
end
|
|
144
|
|
|
148
|
|
|
145
|
def test_generated_links_with_prefix_and_no_relative_url_root
|
|
149
|
def test_generated_links_with_prefix_and_no_relative_url_root
|
|
146
|
relative_url_root = Redmine::Utils.relative_url_root
|
|
150
|
relative_url_root = Redmine::Utils.relative_url_root
|
|
147
|
Redmine::Utils.relative_url_root = nil
|
|
151
|
Redmine::Utils.relative_url_root = nil
|
|
148
|
|
|
152
|
|
|
149
|
with_settings :host_name => 'mydomain.foo/rdm', :protocol => 'http' do
|
|
153
|
with_settings :host_name => 'mydomain.foo/rdm', :protocol => 'http' do
|
|
150
|
journal = Journal.find(3)
|
|
154
|
journal = Journal.find(3)
|
|
151
|
assert Mailer.deliver_issue_edit(journal)
|
|
155
|
assert Mailer.deliver_issue_edit(journal)
|
|
152
|
end
|
|
156
|
end
|
|
153
|
|
|
157
|
|
|
154
|
mail = last_email
|
|
158
|
mail = last_email
|
|
155
|
assert_not_nil mail
|
|
159
|
assert_not_nil mail
|
|
156
|
|
|
160
|
|
|
157
|
assert_select_email do
|
|
161
|
assert_select_email do
|
|
158
|
# link to the main ticket
|
|
162
|
# link to the main ticket
|
|
159
|
assert_select 'a[href=?]',
|
|
163
|
assert_select 'a[href=?]',
|
|
160
|
'http://mydomain.foo/rdm/issues/2#change-3',
|
|
164
|
'http://mydomain.foo/rdm/issues/2#change-3',
|
|
161
|
:text => 'Feature request #2: Add ingredients categories'
|
|
165
|
:text => 'Feature request #2: Add ingredients categories'
|
|
162
|
# link to a referenced ticket
|
|
166
|
# link to a referenced ticket
|
|
163
|
assert_select 'a[href=?][title=?]',
|
|
167
|
assert_select 'a[href=?][title=?]',
|
|
164
|
'http://mydomain.foo/rdm/issues/1',
|
|
168
|
'http://mydomain.foo/rdm/issues/1',
|
|
165
|
"Bug: Cannot print recipes (New)",
|
|
169
|
"Bug: Cannot print recipes (New)",
|
|
166
|
:text => '#1'
|
|
170
|
:text => '#1'
|
|
167
|
# link to a changeset
|
|
171
|
# link to a changeset
|
|
168
|
assert_select 'a[href=?][title=?]',
|
|
172
|
assert_select 'a[href=?][title=?]',
|
|
169
|
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
|
173
|
'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
|
|
170
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
174
|
'This commit fixes #1, #2 and references #1 & #3',
|
|
171
|
:text => 'r2'
|
|
175
|
:text => 'r2'
|
|
172
|
# link to a description diff
|
|
176
|
# link to a description diff
|
|
173
|
assert_select 'a[href^=?][title=?]',
|
|
177
|
assert_select 'a[href^=?][title=?]',
|
|
174
|
# should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
|
|
178
|
# should be http://mydomain.foo/rdm/journals/diff/3?detail_id=4
|
|
175
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
179
|
# but the Rails 4.2 DOM assertion doesn't handle the ? in the
|
|
176
|
# attribute value
|
|
180
|
# attribute value
|
|
177
|
'http://mydomain.foo/rdm/journals/3/diff',
|
|
181
|
'http://mydomain.foo/rdm/journals/3/diff',
|
|
178
|
'View differences',
|
|
182
|
'View differences',
|
|
179
|
:text => 'diff'
|
|
183
|
:text => 'diff'
|
|
180
|
# link to an attachment
|
|
184
|
# link to an attachment
|
|
181
|
assert_select 'a[href=?]',
|
|
185
|
assert_select 'a[href=?]',
|
|
182
|
'http://mydomain.foo/rdm/attachments/download/4/source.rb',
|
|
186
|
'http://mydomain.foo/rdm/attachments/download/4/source.rb',
|
|
183
|
:text => 'source.rb'
|
|
187
|
:text => 'source.rb'
|
|
184
|
end
|
|
188
|
end
|
|
185
|
ensure
|
|
189
|
ensure
|
|
186
|
# restore it
|
|
190
|
# restore it
|
|
187
|
Redmine::Utils.relative_url_root = relative_url_root
|
|
191
|
Redmine::Utils.relative_url_root = relative_url_root
|
|
188
|
end
|
|
192
|
end
|
|
189
|
|
|
193
|
|
|
190
|
def test_email_headers
|
|
194
|
def test_email_headers
|
|
191
|
issue = Issue.find(1)
|
|
195
|
issue = Issue.find(1)
|
|
192
|
Mailer.deliver_issue_add(issue)
|
|
196
|
Mailer.deliver_issue_add(issue)
|
|
193
|
mail = last_email
|
|
197
|
mail = last_email
|
|
194
|
assert_not_nil mail
|
|
198
|
assert_not_nil mail
|
|
195
|
assert_equal 'All', mail.header['X-Auto-Response-Suppress'].to_s
|
|
199
|
assert_equal 'All', mail.header['X-Auto-Response-Suppress'].to_s
|
|
196
|
assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
|
|
200
|
assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
|
|
197
|
assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
|
|
201
|
assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
|
|
198
|
end
|
|
202
|
end
|
|
199
|
|
|
203
|
|
|
200
|
def test_email_headers_should_include_sender
|
|
204
|
def test_email_headers_should_include_sender
|
|
201
|
issue = Issue.find(1)
|
|
205
|
issue = Issue.find(1)
|
|
202
|
Mailer.deliver_issue_add(issue)
|
|
206
|
Mailer.deliver_issue_add(issue)
|
|
203
|
mail = last_email
|
|
207
|
mail = last_email
|
|
204
|
assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
|
|
208
|
assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
|
|
205
|
end
|
|
209
|
end
|
|
206
|
|
|
210
|
|
|
207
|
def test_plain_text_mail
|
|
211
|
def test_plain_text_mail
|
|
208
|
Setting.plain_text_mail = 1
|
|
212
|
Setting.plain_text_mail = 1
|
|
209
|
journal = Journal.find(2)
|
|
213
|
journal = Journal.find(2)
|
|
210
|
Mailer.deliver_issue_edit(journal)
|
|
214
|
Mailer.deliver_issue_edit(journal)
|
|
211
|
mail = last_email
|
|
215
|
mail = last_email
|
|
212
|
assert_equal "text/plain; charset=UTF-8", mail.content_type
|
|
216
|
assert_equal "text/plain; charset=UTF-8", mail.content_type
|
|
213
|
assert_equal 0, mail.parts.size
|
|
217
|
assert_equal 0, mail.parts.size
|
|
214
|
assert !mail.encoded.include?('href')
|
|
218
|
assert !mail.encoded.include?('href')
|
|
215
|
end
|
|
219
|
end
|
|
216
|
|
|
220
|
|
|
217
|
def test_html_mail
|
|
221
|
def test_html_mail
|
|
218
|
Setting.plain_text_mail = 0
|
|
222
|
Setting.plain_text_mail = 0
|
|
219
|
journal = Journal.find(2)
|
|
223
|
journal = Journal.find(2)
|
|
220
|
Mailer.deliver_issue_edit(journal)
|
|
224
|
Mailer.deliver_issue_edit(journal)
|
|
221
|
mail = last_email
|
|
225
|
mail = last_email
|
|
222
|
assert_equal 2, mail.parts.size
|
|
226
|
assert_equal 2, mail.parts.size
|
|
223
|
assert mail.encoded.include?('href')
|
|
227
|
assert mail.encoded.include?('href')
|
|
224
|
end
|
|
228
|
end
|
|
225
|
|
|
229
|
|
|
226
|
def test_from_header
|
|
230
|
def test_from_header
|
|
227
|
with_settings :mail_from => 'redmine@example.net' do
|
|
231
|
with_settings :mail_from => 'redmine@example.net' do
|
|
228
|
Mailer.test_email(User.find(1)).deliver
|
|
232
|
Mailer.test_email(User.find(1)).deliver
|
|
229
|
end
|
|
233
|
end
|
|
230
|
mail = last_email
|
|
234
|
mail = last_email
|
|
231
|
assert_equal 'redmine@example.net', mail.from_addrs.first
|
|
235
|
assert_equal 'redmine@example.net', mail.from_addrs.first
|
|
232
|
end
|
|
236
|
end
|
|
233
|
|
|
237
|
|
|
234
|
def test_from_header_with_phrase
|
|
238
|
def test_from_header_with_phrase
|
|
235
|
with_settings :mail_from => 'Redmine app <redmine@example.net>' do
|
|
239
|
with_settings :mail_from => 'Redmine app <redmine@example.net>' do
|
|
236
|
Mailer.test_email(User.find(1)).deliver
|
|
240
|
Mailer.test_email(User.find(1)).deliver
|
|
237
|
end
|
|
241
|
end
|
|
238
|
mail = last_email
|
|
242
|
mail = last_email
|
|
239
|
assert_equal 'redmine@example.net', mail.from_addrs.first
|
|
243
|
assert_equal 'redmine@example.net', mail.from_addrs.first
|
|
240
|
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
|
244
|
assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
|
|
241
|
end
|
|
245
|
end
|
|
242
|
|
|
246
|
|
|
243
|
def test_should_not_send_email_without_recipient
|
|
247
|
def test_should_not_send_email_without_recipient
|
|
244
|
news = News.first
|
|
248
|
news = News.first
|
|
245
|
user = news.author
|
|
249
|
user = news.author
|
|
246
|
# Remove members except news author
|
|
250
|
# Remove members except news author
|
|
247
|
news.project.memberships.each {|m| m.destroy unless m.user == user}
|
|
251
|
news.project.memberships.each {|m| m.destroy unless m.user == user}
|
|
248
|
|
|
252
|
|
|
249
|
user.pref.no_self_notified = false
|
|
253
|
user.pref.no_self_notified = false
|
|
250
|
user.pref.save
|
|
254
|
user.pref.save
|
|
251
|
User.current = user
|
|
255
|
User.current = user
|
|
252
|
Mailer.news_added(news.reload).deliver
|
|
256
|
Mailer.news_added(news.reload).deliver
|
|
253
|
assert_equal 1, last_email.bcc.size
|
|
257
|
assert_equal 1, last_email.bcc.size
|
|
254
|
|
|
258
|
|
|
255
|
# nobody to notify
|
|
259
|
# nobody to notify
|
|
256
|
user.pref.no_self_notified = true
|
|
260
|
user.pref.no_self_notified = true
|
|
257
|
user.pref.save
|
|
261
|
user.pref.save
|
|
258
|
User.current = user
|
|
262
|
User.current = user
|
|
259
|
ActionMailer::Base.deliveries.clear
|
|
263
|
ActionMailer::Base.deliveries.clear
|
|
260
|
Mailer.news_added(news.reload).deliver
|
|
264
|
Mailer.news_added(news.reload).deliver
|
|
261
|
assert ActionMailer::Base.deliveries.empty?
|
|
265
|
assert ActionMailer::Base.deliveries.empty?
|
|
262
|
end
|
|
266
|
end
|
|
263
|
|
|
267
|
|
|
264
|
def test_issue_add_message_id
|
|
268
|
def test_issue_add_message_id
|
|
265
|
issue = Issue.find(2)
|
|
269
|
issue = Issue.find(2)
|
|
266
|
Mailer.deliver_issue_add(issue)
|
|
270
|
Mailer.deliver_issue_add(issue)
|
|
267
|
mail = last_email
|
|
271
|
mail = last_email
|
|
268
|
assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id
|
|
272
|
assert_match /^redmine\.issue-2\.20060719190421\.[a-f0-9]+@example\.net/, mail.message_id
|
|
269
|
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
|
273
|
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
|
270
|
end
|
|
274
|
end
|
|
271
|
|
|
275
|
|
|
272
|
def test_issue_edit_message_id
|
|
276
|
def test_issue_edit_message_id
|
|
273
|
journal = Journal.find(3)
|
|
277
|
journal = Journal.find(3)
|
|
274
|
journal.issue = Issue.find(2)
|
|
278
|
journal.issue = Issue.find(2)
|
|
275
|
|
|
279
|
|
|
276
|
Mailer.deliver_issue_edit(journal)
|
|
280
|
Mailer.deliver_issue_edit(journal)
|
|
277
|
mail = last_email
|
|
281
|
mail = last_email
|
|
278
|
assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
282
|
assert_match /^redmine\.journal-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
279
|
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
|
283
|
assert_include "redmine.issue-2.20060719190421@example.net", mail.references
|
|
280
|
assert_select_email do
|
|
284
|
assert_select_email do
|
|
281
|
# link to the update
|
|
285
|
# link to the update
|
|
282
|
assert_select "a[href=?]",
|
|
286
|
assert_select "a[href=?]",
|
|
283
|
"http://localhost:3000/issues/#{journal.journalized_id}#change-#{journal.id}"
|
|
287
|
"http://localhost:3000/issues/#{journal.journalized_id}#change-#{journal.id}"
|
|
284
|
end
|
|
288
|
end
|
|
285
|
end
|
|
289
|
end
|
|
286
|
|
|
290
|
|
|
287
|
def test_message_posted_message_id
|
|
291
|
def test_message_posted_message_id
|
|
288
|
message = Message.find(1)
|
|
292
|
message = Message.find(1)
|
|
289
|
Mailer.message_posted(message).deliver
|
|
293
|
Mailer.message_posted(message).deliver
|
|
290
|
mail = last_email
|
|
294
|
mail = last_email
|
|
291
|
assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
295
|
assert_match /^redmine\.message-1\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
292
|
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
|
296
|
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
|
293
|
assert_select_email do
|
|
297
|
assert_select_email do
|
|
294
|
# link to the message
|
|
298
|
# link to the message
|
|
295
|
assert_select "a[href=?]",
|
|
299
|
assert_select "a[href=?]",
|
|
296
|
"http://localhost:3000/boards/#{message.board.id}/topics/#{message.id}",
|
|
300
|
"http://localhost:3000/boards/#{message.board.id}/topics/#{message.id}",
|
|
297
|
:text => message.subject
|
|
301
|
:text => message.subject
|
|
298
|
end
|
|
302
|
end
|
|
299
|
end
|
|
303
|
end
|
|
300
|
|
|
304
|
|
|
301
|
def test_reply_posted_message_id
|
|
305
|
def test_reply_posted_message_id
|
|
302
|
message = Message.find(3)
|
|
306
|
message = Message.find(3)
|
|
303
|
Mailer.message_posted(message).deliver
|
|
307
|
Mailer.message_posted(message).deliver
|
|
304
|
mail = last_email
|
|
308
|
mail = last_email
|
|
305
|
assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
309
|
assert_match /^redmine\.message-3\.\d+\.[a-f0-9]+@example\.net/, mail.message_id
|
|
306
|
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
|
310
|
assert_include "redmine.message-1.20070512151532@example.net", mail.references
|
|
307
|
assert_select_email do
|
|
311
|
assert_select_email do
|
|
308
|
# link to the reply
|
|
312
|
# link to the reply
|
|
309
|
assert_select "a[href=?]",
|
|
313
|
assert_select "a[href=?]",
|
|
310
|
"http://localhost:3000/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
|
|
314
|
"http://localhost:3000/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
|
|
311
|
:text => message.subject
|
|
315
|
:text => message.subject
|
|
312
|
end
|
|
316
|
end
|
|
313
|
end
|
|
317
|
end
|
|
314
|
|
|
318
|
|
|
315
|
test "#issue_add should notify project members" do
|
|
319
|
test "#issue_add should notify project members" do
|
|
316
|
issue = Issue.find(1)
|
|
320
|
issue = Issue.find(1)
|
|
317
|
assert Mailer.deliver_issue_add(issue)
|
|
321
|
assert Mailer.deliver_issue_add(issue)
|
|
318
|
assert last_email.bcc.include?('dlopper@somenet.foo')
|
|
322
|
assert last_email.bcc.include?('dlopper@somenet.foo')
|
|
319
|
end
|
|
323
|
end
|
|
320
|
|
|
324
|
|
|
321
|
def test_issue_add_should_send_mail_to_all_user_email_address
|
|
325
|
def test_issue_add_should_send_mail_to_all_user_email_address
|
|
322
|
EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo')
|
|
326
|
EmailAddress.create!(:user_id => 3, :address => 'otheremail@somenet.foo')
|
|
323
|
issue = Issue.find(1)
|
|
327
|
issue = Issue.find(1)
|
|
324
|
assert Mailer.deliver_issue_add(issue)
|
|
328
|
assert Mailer.deliver_issue_add(issue)
|
|
325
|
assert last_email.bcc.include?('dlopper@somenet.foo')
|
|
329
|
assert last_email.bcc.include?('dlopper@somenet.foo')
|
|
326
|
assert last_email.bcc.include?('otheremail@somenet.foo')
|
|
330
|
assert last_email.bcc.include?('otheremail@somenet.foo')
|
|
327
|
end
|
|
331
|
end
|
|
328
|
|
|
332
|
|
|
329
|
test "#issue_add should not notify project members that are not allow to view the issue" do
|
|
333
|
test "#issue_add should not notify project members that are not allow to view the issue" do
|
|
330
|
issue = Issue.find(1)
|
|
334
|
issue = Issue.find(1)
|
|
331
|
Role.find(2).remove_permission!(:view_issues)
|
|
335
|
Role.find(2).remove_permission!(:view_issues)
|
|
332
|
assert Mailer.deliver_issue_add(issue)
|
|
336
|
assert Mailer.deliver_issue_add(issue)
|
|
333
|
assert !last_email.bcc.include?('dlopper@somenet.foo')
|
|
337
|
assert !last_email.bcc.include?('dlopper@somenet.foo')
|
|
334
|
end
|
|
338
|
end
|
|
335
|
|
|
339
|
|
|
336
|
test "#issue_add should notify issue watchers" do
|
|
340
|
test "#issue_add should notify issue watchers" do
|
|
337
|
issue = Issue.find(1)
|
|
341
|
issue = Issue.find(1)
|
|
338
|
user = User.find(9)
|
|
342
|
user = User.find(9)
|
|
339
|
# minimal email notification options
|
|
343
|
# minimal email notification options
|
|
340
|
user.pref.no_self_notified = '1'
|
|
344
|
user.pref.no_self_notified = '1'
|
|
341
|
user.pref.save
|
|
345
|
user.pref.save
|
|
342
|
user.mail_notification = false
|
|
346
|
user.mail_notification = false
|
|
343
|
user.save
|
|
347
|
user.save
|
|
344
|
|
|
348
|
|
|
345
|
Watcher.create!(:watchable => issue, :user => user)
|
|
349
|
Watcher.create!(:watchable => issue, :user => user)
|
|
346
|
assert Mailer.deliver_issue_add(issue)
|
|
350
|
assert Mailer.deliver_issue_add(issue)
|
|
347
|
assert last_email.bcc.include?(user.mail)
|
|
351
|
assert last_email.bcc.include?(user.mail)
|
|
348
|
end
|
|
352
|
end
|
|
349
|
|
|
353
|
|
|
350
|
test "#issue_add should not notify watchers not allowed to view the issue" do
|
|
354
|
test "#issue_add should not notify watchers not allowed to view the issue" do
|
|
351
|
issue = Issue.find(1)
|
|
355
|
issue = Issue.find(1)
|
|
352
|
user = User.find(9)
|
|
356
|
user = User.find(9)
|
|
353
|
Watcher.create!(:watchable => issue, :user => user)
|
|
357
|
Watcher.create!(:watchable => issue, :user => user)
|
|
354
|
Role.non_member.remove_permission!(:view_issues)
|
|
358
|
Role.non_member.remove_permission!(:view_issues)
|
|
355
|
assert Mailer.deliver_issue_add(issue)
|
|
359
|
assert Mailer.deliver_issue_add(issue)
|
|
356
|
assert !last_email.bcc.include?(user.mail)
|
|
360
|
assert !last_email.bcc.include?(user.mail)
|
|
357
|
end
|
|
361
|
end
|
|
358
|
|
|
362
|
|
|
359
|
def test_issue_add_should_include_enabled_fields
|
|
363
|
def test_issue_add_should_include_enabled_fields
|
|
360
|
issue = Issue.find(2)
|
|
364
|
issue = Issue.find(2)
|
|
361
|
assert Mailer.deliver_issue_add(issue)
|
|
365
|
assert Mailer.deliver_issue_add(issue)
|
|
362
|
assert_mail_body_match '* Target version: 1.0', last_email
|
|
366
|
assert_mail_body_match '* Target version: 1.0', last_email
|
|
363
|
assert_select_email do
|
|
367
|
assert_select_email do
|
|
364
|
assert_select 'li', :text => 'Target version: 1.0'
|
|
368
|
assert_select 'li', :text => 'Target version: 1.0'
|
|
365
|
end
|
|
369
|
end
|
|
366
|
end
|
|
370
|
end
|
|
367
|
|
|
371
|
|
|
368
|
def test_issue_add_should_not_include_disabled_fields
|
|
372
|
def test_issue_add_should_not_include_disabled_fields
|
|
369
|
issue = Issue.find(2)
|
|
373
|
issue = Issue.find(2)
|
|
370
|
tracker = issue.tracker
|
|
374
|
tracker = issue.tracker
|
|
371
|
tracker.core_fields -= ['fixed_version_id']
|
|
375
|
tracker.core_fields -= ['fixed_version_id']
|
|
372
|
tracker.save!
|
|
376
|
tracker.save!
|
|
373
|
assert Mailer.deliver_issue_add(issue)
|
|
377
|
assert Mailer.deliver_issue_add(issue)
|
|
374
|
assert_mail_body_no_match 'Target version', last_email
|
|
378
|
assert_mail_body_no_match 'Target version', last_email
|
|
375
|
assert_select_email do
|
|
379
|
assert_select_email do
|
|
376
|
assert_select 'li', :text => /Target version/, :count => 0
|
|
380
|
assert_select 'li', :text => /Target version/, :count => 0
|
|
377
|
end
|
|
381
|
end
|
|
378
|
end
|
|
382
|
end
|
|
379
|
|
|
383
|
|
|
380
|
# test mailer methods for each language
|
|
384
|
# test mailer methods for each language
|
|
381
|
def test_issue_add
|
|
385
|
def test_issue_add
|
|
382
|
issue = Issue.find(1)
|
|
386
|
issue = Issue.find(1)
|
|
383
|
with_each_language_as_default do
|
|
387
|
with_each_language_as_default do
|
|
384
|
assert Mailer.deliver_issue_add(issue)
|
|
388
|
assert Mailer.deliver_issue_add(issue)
|
|
385
|
end
|
|
389
|
end
|
|
386
|
end
|
|
390
|
end
|
|
387
|
|
|
391
|
|
|
388
|
def test_issue_edit
|
|
392
|
def test_issue_edit
|
|
389
|
journal = Journal.find(1)
|
|
393
|
journal = Journal.find(1)
|
|
390
|
with_each_language_as_default do
|
|
394
|
with_each_language_as_default do
|
|
391
|
assert Mailer.deliver_issue_edit(journal)
|
|
395
|
assert Mailer.deliver_issue_edit(journal)
|
|
392
|
end
|
|
396
|
end
|
|
393
|
end
|
|
397
|
end
|
|
394
|
|
|
398
|
|
|
395
|
def test_issue_edit_should_send_private_notes_to_users_with_permission_only
|
|
399
|
def test_issue_edit_should_send_private_notes_to_users_with_permission_only
|
|
396
|
journal = Journal.find(1)
|
|
400
|
journal = Journal.find(1)
|
|
397
|
journal.private_notes = true
|
|
401
|
journal.private_notes = true
|
|
398
|
journal.save!
|
|
402
|
journal.save!
|
|
399
|
|
|
403
|
|
|
400
|
Role.find(2).add_permission! :view_private_notes
|
|
404
|
Role.find(2).add_permission! :view_private_notes
|
|
401
|
Mailer.deliver_issue_edit(journal)
|
|
405
|
Mailer.deliver_issue_edit(journal)
|
|
402
|
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
|
|
406
|
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
|
|
403
|
|
|
407
|
|
|
404
|
Role.find(2).remove_permission! :view_private_notes
|
|
408
|
Role.find(2).remove_permission! :view_private_notes
|
|
405
|
Mailer.deliver_issue_edit(journal)
|
|
409
|
Mailer.deliver_issue_edit(journal)
|
|
406
|
assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
|
|
410
|
assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
|
|
407
|
end
|
|
411
|
end
|
|
408
|
|
|
412
|
|
|
409
|
def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
|
|
413
|
def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
|
|
410
|
Issue.find(1).set_watcher(User.find_by_login('someone'))
|
|
414
|
Issue.find(1).set_watcher(User.find_by_login('someone'))
|
|
411
|
journal = Journal.find(1)
|
|
415
|
journal = Journal.find(1)
|
|
412
|
journal.private_notes = true
|
|
416
|
journal.private_notes = true
|
|
413
|
journal.save!
|
|
417
|
journal.save!
|
|
414
|
|
|
418
|
|
|
415
|
Role.non_member.add_permission! :view_private_notes
|
|
419
|
Role.non_member.add_permission! :view_private_notes
|
|
416
|
Mailer.deliver_issue_edit(journal)
|
|
420
|
Mailer.deliver_issue_edit(journal)
|
|
417
|
assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
|
421
|
assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
|
418
|
|
|
422
|
|
|
419
|
Role.non_member.remove_permission! :view_private_notes
|
|
423
|
Role.non_member.remove_permission! :view_private_notes
|
|
420
|
Mailer.deliver_issue_edit(journal)
|
|
424
|
Mailer.deliver_issue_edit(journal)
|
|
421
|
assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
|
425
|
assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
|
|
422
|
end
|
|
426
|
end
|
|
423
|
|
|
427
|
|
|
424
|
def test_issue_edit_should_mark_private_notes
|
|
428
|
def test_issue_edit_should_mark_private_notes
|
|
425
|
journal = Journal.find(2)
|
|
429
|
journal = Journal.find(2)
|
|
426
|
journal.private_notes = true
|
|
430
|
journal.private_notes = true
|
|
427
|
journal.save!
|
|
431
|
journal.save!
|
|
428
|
|
|
432
|
|
|
429
|
with_settings :default_language => 'en' do
|
|
433
|
with_settings :default_language => 'en' do
|
|
430
|
Mailer.deliver_issue_edit(journal)
|
|
434
|
Mailer.deliver_issue_edit(journal)
|
|
431
|
end
|
|
435
|
end
|
|
432
|
assert_mail_body_match '(Private notes)', last_email
|
|
436
|
assert_mail_body_match '(Private notes)', last_email
|
|
433
|
end
|
|
437
|
end
|
|
434
|
|
|
438
|
|
|
435
|
def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue
|
|
439
|
def test_issue_edit_with_relation_should_notify_users_who_can_see_the_related_issue
|
|
436
|
issue = Issue.generate!
|
|
440
|
issue = Issue.generate!
|
|
437
|
issue.init_journal(User.find(1))
|
|
441
|
issue.init_journal(User.find(1))
|
|
438
|
private_issue = Issue.generate!(:is_private => true)
|
|
442
|
private_issue = Issue.generate!(:is_private => true)
|
|
439
|
IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates')
|
|
443
|
IssueRelation.create!(:issue_from => issue, :issue_to => private_issue, :relation_type => 'relates')
|
|
440
|
issue.reload
|
|
444
|
issue.reload
|
|
441
|
assert_equal 1, issue.journals.size
|
|
445
|
assert_equal 1, issue.journals.size
|
|
442
|
journal = issue.journals.first
|
|
446
|
journal = issue.journals.first
|
|
443
|
ActionMailer::Base.deliveries.clear
|
|
447
|
ActionMailer::Base.deliveries.clear
|
|
444
|
|
|
448
|
|
|
445
|
Mailer.deliver_issue_edit(journal)
|
|
449
|
Mailer.deliver_issue_edit(journal)
|
|
446
|
last_email.bcc.each do |email|
|
|
450
|
last_email.bcc.each do |email|
|
|
447
|
user = User.find_by_mail(email)
|
|
451
|
user = User.find_by_mail(email)
|
|
448
|
assert private_issue.visible?(user), "Issue was not visible to #{user}"
|
|
452
|
assert private_issue.visible?(user), "Issue was not visible to #{user}"
|
|
449
|
end
|
|
453
|
end
|
|
450
|
end
|
|
454
|
end
|
|
451
|
|
|
455
|
|
|
452
|
def test_document_added
|
|
456
|
def test_document_added
|
|
453
|
document = Document.find(1)
|
|
457
|
document = Document.find(1)
|
|
454
|
with_each_language_as_default do
|
|
458
|
with_each_language_as_default do
|
|
455
|
assert Mailer.document_added(document).deliver
|
|
459
|
assert Mailer.document_added(document).deliver
|
|
456
|
end
|
|
460
|
end
|
|
457
|
end
|
|
461
|
end
|
|
458
|
|
|
462
|
|
|
459
|
def test_attachments_added
|
|
463
|
def test_attachments_added
|
|
460
|
attachements = [ Attachment.find_by_container_type('Document') ]
|
|
464
|
attachements = [ Attachment.find_by_container_type('Document') ]
|
|
461
|
with_each_language_as_default do
|
|
465
|
with_each_language_as_default do
|
|
462
|
assert Mailer.attachments_added(attachements).deliver
|
|
466
|
assert Mailer.attachments_added(attachements).deliver
|
|
463
|
end
|
|
467
|
end
|
|
464
|
end
|
|
468
|
end
|
|
465
|
|
|
469
|
|
|
466
|
def test_version_file_added
|
|
470
|
def test_version_file_added
|
|
467
|
attachements = [ Attachment.find_by_container_type('Version') ]
|
|
471
|
attachements = [ Attachment.find_by_container_type('Version') ]
|
|
468
|
assert Mailer.attachments_added(attachements).deliver
|
|
472
|
assert Mailer.attachments_added(attachements).deliver
|
|
469
|
assert_not_nil last_email.bcc
|
|
473
|
assert_not_nil last_email.bcc
|
|
470
|
assert last_email.bcc.any?
|
|
474
|
assert last_email.bcc.any?
|
|
471
|
assert_select_email do
|
|
475
|
assert_select_email do
|
|
472
|
assert_select "a[href=?]", "http://localhost:3000/projects/ecookbook/files"
|
|
476
|
assert_select "a[href=?]", "http://localhost:3000/projects/ecookbook/files"
|
|
473
|
end
|
|
477
|
end
|
|
474
|
end
|
|
478
|
end
|
|
475
|
|
|
479
|
|
|
476
|
def test_project_file_added
|
|
480
|
def test_project_file_added
|
|
477
|
attachements = [ Attachment.find_by_container_type('Project') ]
|
|
481
|
attachements = [ Attachment.find_by_container_type('Project') ]
|
|
478
|
assert Mailer.attachments_added(attachements).deliver
|
|
482
|
assert Mailer.attachments_added(attachements).deliver
|
|
479
|
assert_not_nil last_email.bcc
|
|
483
|
assert_not_nil last_email.bcc
|
|
480
|
assert last_email.bcc.any?
|
|
484
|
assert last_email.bcc.any?
|
|
481
|
assert_select_email do
|
|
485
|
assert_select_email do
|
|
482
|
assert_select "a[href=?]", "http://localhost:3000/projects/ecookbook/files"
|
|
486
|
assert_select "a[href=?]", "http://localhost:3000/projects/ecookbook/files"
|
|
483
|
end
|
|
487
|
end
|
|
484
|
end
|
|
488
|
end
|
|
485
|
|
|
489
|
|
|
486
|
def test_news_added
|
|
490
|
def test_news_added
|
|
487
|
news = News.first
|
|
491
|
news = News.first
|
|
488
|
with_each_language_as_default do
|
|
492
|
with_each_language_as_default do
|
|
489
|
assert Mailer.news_added(news).deliver
|
|
493
|
assert Mailer.news_added(news).deliver
|
|
490
|
end
|
|
494
|
end
|
|
491
|
end
|
|
495
|
end
|
|
492
|
|
|
496
|
|
|
493
|
def test_news_added_should_notify_project_news_watchers
|
|
497
|
def test_news_added_should_notify_project_news_watchers
|
|
494
|
user1 = User.generate!
|
|
498
|
user1 = User.generate!
|
|
495
|
user2 = User.generate!
|
|
499
|
user2 = User.generate!
|
|
496
|
news = News.find(1)
|
|
500
|
news = News.find(1)
|
|
497
|
news.project.enabled_module('news').add_watcher(user1)
|
|
501
|
news.project.enabled_module('news').add_watcher(user1)
|
|
498
|
|
|
502
|
|
|
499
|
Mailer.news_added(news).deliver
|
|
503
|
Mailer.news_added(news).deliver
|
|
500
|
assert_include user1.mail, last_email.bcc
|
|
504
|
assert_include user1.mail, last_email.bcc
|
|
501
|
assert_not_include user2.mail, last_email.bcc
|
|
505
|
assert_not_include user2.mail, last_email.bcc
|
|
502
|
end
|
|
506
|
end
|
|
503
|
|
|
507
|
|
|
504
|
def test_news_comment_added
|
|
508
|
def test_news_comment_added
|
|
505
|
comment = Comment.find(2)
|
|
509
|
comment = Comment.find(2)
|
|
506
|
with_each_language_as_default do
|
|
510
|
with_each_language_as_default do
|
|
507
|
assert Mailer.news_comment_added(comment).deliver
|
|
511
|
assert Mailer.news_comment_added(comment).deliver
|
|
508
|
end
|
|
512
|
end
|
|
509
|
end
|
|
513
|
end
|
|
510
|
|
|
514
|
|
|
511
|
def test_message_posted
|
|
515
|
def test_message_posted
|
|
512
|
message = Message.first
|
|
516
|
message = Message.first
|
|
513
|
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
|
|
517
|
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
|
|
514
|
recipients = recipients.compact.uniq
|
|
518
|
recipients = recipients.compact.uniq
|
|
515
|
with_each_language_as_default do
|
|
519
|
with_each_language_as_default do
|
|
516
|
assert Mailer.message_posted(message).deliver
|
|
520
|
assert Mailer.message_posted(message).deliver
|
|
517
|
end
|
|
521
|
end
|
|
518
|
end
|
|
522
|
end
|
|
519
|
|
|
523
|
|
|
520
|
def test_wiki_content_added
|
|
524
|
def test_wiki_content_added
|
|
521
|
content = WikiContent.find(1)
|
|
525
|
content = WikiContent.find(1)
|
|
522
|
with_each_language_as_default do
|
|
526
|
with_each_language_as_default do
|
|
523
|
assert_difference 'ActionMailer::Base.deliveries.size' do
|
|
527
|
assert_difference 'ActionMailer::Base.deliveries.size' do
|
|
524
|
assert Mailer.wiki_content_added(content).deliver
|
|
528
|
assert Mailer.wiki_content_added(content).deliver
|
|
525
|
assert_select_email do
|
|
529
|
assert_select_email do
|
|
526
|
assert_select 'a[href=?]',
|
|
530
|
assert_select 'a[href=?]',
|
|
527
|
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
|
531
|
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
|
528
|
:text => 'CookBook documentation'
|
|
532
|
:text => 'CookBook documentation'
|
|
529
|
end
|
|
533
|
end
|
|
530
|
end
|
|
534
|
end
|
|
531
|
end
|
|
535
|
end
|
|
532
|
end
|
|
536
|
end
|
|
533
|
|
|
537
|
|
|
534
|
def test_wiki_content_updated
|
|
538
|
def test_wiki_content_updated
|
|
535
|
content = WikiContent.find(1)
|
|
539
|
content = WikiContent.find(1)
|
|
536
|
with_each_language_as_default do
|
|
540
|
with_each_language_as_default do
|
|
537
|
assert_difference 'ActionMailer::Base.deliveries.size' do
|
|
541
|
assert_difference 'ActionMailer::Base.deliveries.size' do
|
|
538
|
assert Mailer.wiki_content_updated(content).deliver
|
|
542
|
assert Mailer.wiki_content_updated(content).deliver
|
|
539
|
assert_select_email do
|
|
543
|
assert_select_email do
|
|
540
|
assert_select 'a[href=?]',
|
|
544
|
assert_select 'a[href=?]',
|
|
541
|
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
|
545
|
'http://localhost:3000/projects/ecookbook/wiki/CookBook_documentation',
|
|
542
|
:text => 'CookBook documentation'
|
|
546
|
:text => 'CookBook documentation'
|
|
543
|
end
|
|
547
|
end
|
|
544
|
end
|
|
548
|
end
|
|
545
|
end
|
|
549
|
end
|
|
546
|
end
|
|
550
|
end
|
|
547
|
|
|
551
|
|
|
548
|
def test_account_information
|
|
552
|
def test_account_information
|
|
549
|
user = User.find(2)
|
|
553
|
user = User.find(2)
|
|
550
|
valid_languages.each do |lang|
|
|
554
|
valid_languages.each do |lang|
|
|
551
|
user.update_attribute :language, lang.to_s
|
|
555
|
user.update_attribute :language, lang.to_s
|
|
552
|
user.reload
|
|
556
|
user.reload
|
|
553
|
assert Mailer.account_information(user, 'pAsswORd').deliver
|
|
557
|
assert Mailer.account_information(user, 'pAsswORd').deliver
|
|
554
|
end
|
|
558
|
end
|
|
555
|
end
|
|
559
|
end
|
|
556
|
|
|
560
|
|
|
557
|
def test_lost_password
|
|
561
|
def test_lost_password
|
|
558
|
token = Token.find(2)
|
|
562
|
token = Token.find(2)
|
|
559
|
valid_languages.each do |lang|
|
|
563
|
valid_languages.each do |lang|
|
|
560
|
token.user.update_attribute :language, lang.to_s
|
|
564
|
token.user.update_attribute :language, lang.to_s
|
|
561
|
token.reload
|
|
565
|
token.reload
|
|
562
|
assert Mailer.lost_password(token).deliver
|
|
566
|
assert Mailer.lost_password(token).deliver
|
|
563
|
end
|
|
567
|
end
|
|
564
|
end
|
|
568
|
end
|
|
565
|
|
|
569
|
|
|
566
|
def test_register
|
|
570
|
def test_register
|
|
567
|
token = Token.find(1)
|
|
571
|
token = Token.find(1)
|
|
568
|
valid_languages.each do |lang|
|
|
572
|
valid_languages.each do |lang|
|
|
569
|
token.user.update_attribute :language, lang.to_s
|
|
573
|
token.user.update_attribute :language, lang.to_s
|
|
570
|
token.reload
|
|
574
|
token.reload
|
|
571
|
ActionMailer::Base.deliveries.clear
|
|
575
|
ActionMailer::Base.deliveries.clear
|
|
572
|
assert Mailer.register(token).deliver
|
|
576
|
assert Mailer.register(token).deliver
|
|
573
|
mail = last_email
|
|
577
|
mail = last_email
|
|
574
|
assert_select_email do
|
|
578
|
assert_select_email do
|
|
575
|
assert_select "a[href=?]",
|
|
579
|
assert_select "a[href=?]",
|
|
576
|
"http://localhost:3000/account/activate?token=#{token.value}",
|
|
580
|
"http://localhost:3000/account/activate?token=#{token.value}",
|
|
577
|
:text => "http://localhost:3000/account/activate?token=#{token.value}"
|
|
581
|
:text => "http://localhost:3000/account/activate?token=#{token.value}"
|
|
578
|
end
|
|
582
|
end
|
|
579
|
end
|
|
583
|
end
|
|
580
|
end
|
|
584
|
end
|
|
581
|
|
|
585
|
|
|
582
|
def test_test
|
|
586
|
def test_test
|
|
583
|
user = User.find(1)
|
|
587
|
user = User.find(1)
|
|
584
|
valid_languages.each do |lang|
|
|
588
|
valid_languages.each do |lang|
|
|
585
|
user.update_attribute :language, lang.to_s
|
|
589
|
user.update_attribute :language, lang.to_s
|
|
586
|
assert Mailer.test_email(user).deliver
|
|
590
|
assert Mailer.test_email(user).deliver
|
|
587
|
end
|
|
591
|
end
|
|
588
|
end
|
|
592
|
end
|
|
589
|
|
|
593
|
|
|
590
|
def test_reminders
|
|
594
|
def test_reminders
|
|
591
|
Mailer.reminders(:days => 42)
|
|
595
|
Mailer.reminders(:days => 42)
|
|
592
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
596
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
593
|
mail = last_email
|
|
597
|
mail = last_email
|
|
594
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
598
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
595
|
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
|
599
|
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
|
596
|
assert_equal '1 issue(s) due in the next 42 days', mail.subject
|
|
600
|
assert_equal '1 issue(s) due in the next 42 days', mail.subject
|
|
597
|
end
|
|
601
|
end
|
|
598
|
|
|
602
|
|
|
599
|
def test_reminders_should_not_include_closed_issues
|
|
603
|
def test_reminders_should_not_include_closed_issues
|
|
600
|
with_settings :default_language => 'en' do
|
|
604
|
with_settings :default_language => 'en' do
|
|
601
|
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
|
|
605
|
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
|
|
602
|
:subject => 'Closed issue', :assigned_to_id => 3,
|
|
606
|
:subject => 'Closed issue', :assigned_to_id => 3,
|
|
603
|
:due_date => 5.days.from_now,
|
|
607
|
:due_date => 5.days.from_now,
|
|
604
|
:author_id => 2)
|
|
608
|
:author_id => 2)
|
|
605
|
ActionMailer::Base.deliveries.clear
|
|
609
|
ActionMailer::Base.deliveries.clear
|
|
606
|
|
|
610
|
|
|
607
|
Mailer.reminders(:days => 42)
|
|
611
|
Mailer.reminders(:days => 42)
|
|
608
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
612
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
609
|
mail = last_email
|
|
613
|
mail = last_email
|
|
610
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
614
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
611
|
assert_mail_body_no_match 'Closed issue', mail
|
|
615
|
assert_mail_body_no_match 'Closed issue', mail
|
|
612
|
end
|
|
616
|
end
|
|
613
|
end
|
|
617
|
end
|
|
614
|
|
|
618
|
|
|
615
|
def test_reminders_for_users
|
|
619
|
def test_reminders_for_users
|
|
616
|
Mailer.reminders(:days => 42, :users => ['5'])
|
|
620
|
Mailer.reminders(:days => 42, :users => ['5'])
|
|
617
|
assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
|
|
621
|
assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
|
|
618
|
Mailer.reminders(:days => 42, :users => ['3'])
|
|
622
|
Mailer.reminders(:days => 42, :users => ['3'])
|
|
619
|
assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
|
|
623
|
assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
|
|
620
|
mail = last_email
|
|
624
|
mail = last_email
|
|
621
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
625
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
622
|
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
|
626
|
assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
|
|
623
|
end
|
|
627
|
end
|
|
624
|
|
|
628
|
|
|
625
|
def test_reminder_should_include_issues_assigned_to_groups
|
|
629
|
def test_reminder_should_include_issues_assigned_to_groups
|
|
626
|
with_settings :default_language => 'en' do
|
|
630
|
with_settings :default_language => 'en' do
|
|
627
|
group = Group.generate!
|
|
631
|
group = Group.generate!
|
|
628
|
group.users << User.find(2)
|
|
632
|
group.users << User.find(2)
|
|
629
|
group.users << User.find(3)
|
|
633
|
group.users << User.find(3)
|
|
630
|
|
|
634
|
|
|
631
|
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
|
|
635
|
Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
|
|
632
|
:subject => 'Assigned to group', :assigned_to => group,
|
|
636
|
:subject => 'Assigned to group', :assigned_to => group,
|
|
633
|
:due_date => 5.days.from_now,
|
|
637
|
:due_date => 5.days.from_now,
|
|
634
|
:author_id => 2)
|
|
638
|
:author_id => 2)
|
|
635
|
ActionMailer::Base.deliveries.clear
|
|
639
|
ActionMailer::Base.deliveries.clear
|
|
636
|
|
|
640
|
|
|
637
|
Mailer.reminders(:days => 7)
|
|
641
|
Mailer.reminders(:days => 7)
|
|
638
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
|
642
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
|
639
|
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
|
|
643
|
assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
|
|
640
|
ActionMailer::Base.deliveries.each do |mail|
|
|
644
|
ActionMailer::Base.deliveries.each do |mail|
|
|
641
|
assert_mail_body_match 'Assigned to group', mail
|
|
645
|
assert_mail_body_match 'Assigned to group', mail
|
|
642
|
end
|
|
646
|
end
|
|
643
|
end
|
|
647
|
end
|
|
644
|
end
|
|
648
|
end
|
|
645
|
|
|
649
|
|
|
646
|
def test_reminders_with_version_option
|
|
650
|
def test_reminders_with_version_option
|
|
647
|
with_settings :default_language => 'en' do
|
|
651
|
with_settings :default_language => 'en' do
|
|
648
|
version = Version.generate!(:name => 'Acme', :project_id => 1)
|
|
652
|
version = Version.generate!(:name => 'Acme', :project_id => 1)
|
|
649
|
Issue.generate!(:assigned_to => User.find(2), :due_date => 5.days.from_now)
|
|
653
|
Issue.generate!(:assigned_to => User.find(2), :due_date => 5.days.from_now)
|
|
650
|
Issue.generate!(:assigned_to => User.find(3), :due_date => 5.days.from_now, :fixed_version => version)
|
|
654
|
Issue.generate!(:assigned_to => User.find(3), :due_date => 5.days.from_now, :fixed_version => version)
|
|
651
|
ActionMailer::Base.deliveries.clear
|
|
655
|
ActionMailer::Base.deliveries.clear
|
|
652
|
|
|
656
|
|
|
653
|
Mailer.reminders(:days => 42, :version => 'acme')
|
|
657
|
Mailer.reminders(:days => 42, :version => 'acme')
|
|
654
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
658
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
655
|
|
|
659
|
|
|
656
|
mail = last_email
|
|
660
|
mail = last_email
|
|
657
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
661
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
|
658
|
end
|
|
662
|
end
|
|
659
|
end
|
|
663
|
end
|
|
660
|
|
|
664
|
|
|
661
|
def test_security_notification
|
|
665
|
def test_security_notification
|
|
662
|
set_language_if_valid User.find(1).language
|
|
666
|
set_language_if_valid User.find(1).language
|
|
663
|
with_settings :emails_footer => "footer without link" do
|
|
667
|
with_settings :emails_footer => "footer without link" do
|
|
664
|
User.current.remote_ip = '192.168.1.1'
|
|
668
|
User.current.remote_ip = '192.168.1.1'
|
|
665
|
assert Mailer.security_notification(User.find(1), message: :notice_account_password_updated).deliver
|
|
669
|
assert Mailer.security_notification(User.find(1), message: :notice_account_password_updated).deliver
|
|
666
|
mail = last_email
|
|
670
|
mail = last_email
|
|
667
|
assert_not_nil mail
|
|
671
|
assert_not_nil mail
|
|
668
|
assert_mail_body_match '192.168.1.1', mail
|
|
672
|
assert_mail_body_match '192.168.1.1', mail
|
|
669
|
assert_mail_body_match I18n.t(:notice_account_password_updated), mail
|
|
673
|
assert_mail_body_match I18n.t(:notice_account_password_updated), mail
|
|
670
|
assert_select_email do
|
|
674
|
assert_select_email do
|
|
671
|
assert_select "h1", false
|
|
675
|
assert_select "h1", false
|
|
672
|
assert_select "a", false
|
|
676
|
assert_select "a", false
|
|
673
|
end
|
|
677
|
end
|
|
674
|
end
|
|
678
|
end
|
|
675
|
end
|
|
679
|
end
|
|
676
|
|
|
680
|
|
|
677
|
def test_security_notification_should_include_title
|
|
681
|
def test_security_notification_should_include_title
|
|
678
|
set_language_if_valid User.find(2).language
|
|
682
|
set_language_if_valid User.find(2).language
|
|
679
|
with_settings :emails_footer => "footer without link" do
|
|
683
|
with_settings :emails_footer => "footer without link" do
|
|
680
|
assert Mailer.security_notification(User.find(2),
|
|
684
|
assert Mailer.security_notification(User.find(2),
|
|
681
|
message: :notice_account_password_updated,
|
|
685
|
message: :notice_account_password_updated,
|
|
682
|
title: :label_my_account
|
|
686
|
title: :label_my_account
|
|
683
|
).deliver
|
|
687
|
).deliver
|
|
684
|
assert_select_email do
|
|
688
|
assert_select_email do
|
|
685
|
assert_select "a", false
|
|
689
|
assert_select "a", false
|
|
686
|
assert_select "h1", :text => I18n.t(:label_my_account)
|
|
690
|
assert_select "h1", :text => I18n.t(:label_my_account)
|
|
687
|
end
|
|
691
|
end
|
|
688
|
end
|
|
692
|
end
|
|
689
|
end
|
|
693
|
end
|
|
690
|
|
|
694
|
|
|
691
|
def test_security_notification_should_include_link
|
|
695
|
def test_security_notification_should_include_link
|
|
692
|
set_language_if_valid User.find(3).language
|
|
696
|
set_language_if_valid User.find(3).language
|
|
693
|
with_settings :emails_footer => "footer without link" do
|
|
697
|
with_settings :emails_footer => "footer without link" do
|
|
694
|
assert Mailer.security_notification(User.find(3),
|
|
698
|
assert Mailer.security_notification(User.find(3),
|
|
695
|
message: :notice_account_password_updated,
|
|
699
|
message: :notice_account_password_updated,
|
|
696
|
title: :label_my_account,
|
|
700
|
title: :label_my_account,
|
|
697
|
url: {controller: 'my', action: 'account'}
|
|
701
|
url: {controller: 'my', action: 'account'}
|
|
698
|
).deliver
|
|
702
|
).deliver
|
|
699
|
assert_select_email do
|
|
703
|
assert_select_email do
|
|
700
|
assert_select "h1", false
|
|
704
|
assert_select "h1", false
|
|
701
|
assert_select 'a[href=?]', 'http://localhost:3000/my/account', :text => I18n.t(:label_my_account)
|
|
705
|
assert_select 'a[href=?]', 'http://localhost:3000/my/account', :text => I18n.t(:label_my_account)
|
|
702
|
end
|
|
706
|
end
|
|
703
|
end
|
|
707
|
end
|
|
704
|
end
|
|
708
|
end
|
|
705
|
|
|
709
|
|
|
706
|
def test_mailer_should_not_change_locale
|
|
710
|
def test_mailer_should_not_change_locale
|
|
707
|
# Set current language to italian
|
|
711
|
# Set current language to italian
|
|
708
|
set_language_if_valid 'it'
|
|
712
|
set_language_if_valid 'it'
|
|
709
|
# Send an email to a french user
|
|
713
|
# Send an email to a french user
|
|
710
|
user = User.find(1)
|
|
714
|
user = User.find(1)
|
|
711
|
user.language = 'fr'
|
|
715
|
user.language = 'fr'
|
|
712
|
Mailer.account_activated(user).deliver
|
|
716
|
Mailer.account_activated(user).deliver
|
|
713
|
mail = last_email
|
|
717
|
mail = last_email
|
|
714
|
assert_mail_body_match 'Votre compte', mail
|
|
718
|
assert_mail_body_match 'Votre compte', mail
|
|
715
|
|
|
719
|
|
|
716
|
assert_equal :it, current_language
|
|
720
|
assert_equal :it, current_language
|
|
717
|
end
|
|
721
|
end
|
|
718
|
|
|
722
|
|
|
719
|
def test_with_deliveries_off
|
|
723
|
def test_with_deliveries_off
|
|
720
|
Mailer.with_deliveries false do
|
|
724
|
Mailer.with_deliveries false do
|
|
721
|
Mailer.test_email(User.find(1)).deliver
|
|
725
|
Mailer.test_email(User.find(1)).deliver
|
|
722
|
end
|
|
726
|
end
|
|
723
|
assert ActionMailer::Base.deliveries.empty?
|
|
727
|
assert ActionMailer::Base.deliveries.empty?
|
|
724
|
# should restore perform_deliveries
|
|
728
|
# should restore perform_deliveries
|
|
725
|
assert ActionMailer::Base.perform_deliveries
|
|
729
|
assert ActionMailer::Base.perform_deliveries
|
|
726
|
end
|
|
730
|
end
|
|
727
|
|
|
731
|
|
|
728
|
def test_token_for_should_strip_trailing_gt_from_address_with_full_name
|
|
732
|
def test_token_for_should_strip_trailing_gt_from_address_with_full_name
|
|
729
|
with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do
|
|
733
|
with_settings :mail_from => "Redmine Mailer<no-reply@redmine.org>" do
|
|
730
|
assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!)
|
|
734
|
assert_match /\Aredmine.issue-\d+\.\d+\.[0-9a-f]+@redmine.org\z/, Mailer.token_for(Issue.generate!)
|
|
731
|
end
|
|
735
|
end
|
|
732
|
end
|
|
736
|
end
|
|
733
|
|
|
737
|
|
|
734
|
def test_layout_should_include_the_emails_header
|
|
738
|
def test_layout_should_include_the_emails_header
|
|
735
|
with_settings :emails_header => "*Header content*" do
|
|
739
|
with_settings :emails_header => "*Header content*" do
|
|
736
|
with_settings :plain_text_mail => 0 do
|
|
740
|
with_settings :plain_text_mail => 0 do
|
|
737
|
assert Mailer.test_email(User.find(1)).deliver
|
|
741
|
assert Mailer.test_email(User.find(1)).deliver
|
|
738
|
assert_select_email do
|
|
742
|
assert_select_email do
|
|
739
|
assert_select ".header" do
|
|
743
|
assert_select ".header" do
|
|
740
|
assert_select "strong", :text => "Header content"
|
|
744
|
assert_select "strong", :text => "Header content"
|
|
741
|
end
|
|
745
|
end
|
|
742
|
end
|
|
746
|
end
|
|
743
|
end
|
|
747
|
end
|
|
744
|
with_settings :plain_text_mail => 1 do
|
|
748
|
with_settings :plain_text_mail => 1 do
|
|
745
|
assert Mailer.test_email(User.find(1)).deliver
|
|
749
|
assert Mailer.test_email(User.find(1)).deliver
|
|
746
|
mail = last_email
|
|
750
|
mail = last_email
|
|
747
|
assert_not_nil mail
|
|
751
|
assert_not_nil mail
|
|
748
|
assert_include "*Header content*", mail.body.decoded
|
|
752
|
assert_include "*Header content*", mail.body.decoded
|
|
749
|
end
|
|
753
|
end
|
|
750
|
end
|
|
754
|
end
|
|
751
|
end
|
|
755
|
end
|
|
752
|
|
|
756
|
|
|
753
|
def test_layout_should_not_include_empty_emails_header
|
|
757
|
def test_layout_should_not_include_empty_emails_header
|
|
754
|
with_settings :emails_header => "", :plain_text_mail => 0 do
|
|
758
|
with_settings :emails_header => "", :plain_text_mail => 0 do
|
|
755
|
assert Mailer.test_email(User.find(1)).deliver
|
|
759
|
assert Mailer.test_email(User.find(1)).deliver
|
|
756
|
assert_select_email do
|
|
760
|
assert_select_email do
|
|
757
|
assert_select ".header", false
|
|
761
|
assert_select ".header", false
|
|
758
|
end
|
|
762
|
end
|
|
759
|
end
|
|
763
|
end
|
|
760
|
end
|
|
764
|
end
|
|
761
|
|
|
765
|
|
|
762
|
def test_layout_should_include_the_emails_footer
|
|
766
|
def test_layout_should_include_the_emails_footer
|
|
763
|
with_settings :emails_footer => "*Footer content*" do
|
|
767
|
with_settings :emails_footer => "*Footer content*" do
|
|
764
|
with_settings :plain_text_mail => 0 do
|
|
768
|
with_settings :plain_text_mail => 0 do
|
|
765
|
assert Mailer.test_email(User.find(1)).deliver
|
|
769
|
assert Mailer.test_email(User.find(1)).deliver
|
|
766
|
assert_select_email do
|
|
770
|
assert_select_email do
|
|
767
|
assert_select ".footer" do
|
|
771
|
assert_select ".footer" do
|
|
768
|
assert_select "strong", :text => "Footer content"
|
|
772
|
assert_select "strong", :text => "Footer content"
|
|
769
|
end
|
|
773
|
end
|
|
770
|
end
|
|
774
|
end
|
|
771
|
end
|
|
775
|
end
|
|
772
|
with_settings :plain_text_mail => 1 do
|
|
776
|
with_settings :plain_text_mail => 1 do
|
|
773
|
assert Mailer.test_email(User.find(1)).deliver
|
|
777
|
assert Mailer.test_email(User.find(1)).deliver
|
|
774
|
mail = last_email
|
|
778
|
mail = last_email
|
|
775
|
assert_not_nil mail
|
|
779
|
assert_not_nil mail
|
|
776
|
assert_include "\n-- \n", mail.body.decoded
|
|
780
|
assert_include "\n-- \n", mail.body.decoded
|
|
777
|
assert_include "*Footer content*", mail.body.decoded
|
|
781
|
assert_include "*Footer content*", mail.body.decoded
|
|
778
|
end
|
|
782
|
end
|
|
779
|
end
|
|
783
|
end
|
|
780
|
end
|
|
784
|
end
|
|
781
|
|
|
785
|
|
|
782
|
def test_layout_should_not_include_empty_emails_footer
|
|
786
|
def test_layout_should_not_include_empty_emails_footer
|
|
783
|
with_settings :emails_footer => "" do
|
|
787
|
with_settings :emails_footer => "" do
|
|
784
|
with_settings :plain_text_mail => 0 do
|
|
788
|
with_settings :plain_text_mail => 0 do
|
|
785
|
assert Mailer.test_email(User.find(1)).deliver
|
|
789
|
assert Mailer.test_email(User.find(1)).deliver
|
|
786
|
assert_select_email do
|
|
790
|
assert_select_email do
|
|
787
|
assert_select ".footer", false
|
|
791
|
assert_select ".footer", false
|
|
788
|
end
|
|
792
|
end
|
|
789
|
end
|
|
793
|
end
|
|
790
|
with_settings :plain_text_mail => 1 do
|
|
794
|
with_settings :plain_text_mail => 1 do
|
|
791
|
assert Mailer.test_email(User.find(1)).deliver
|
|
795
|
assert Mailer.test_email(User.find(1)).deliver
|
|
792
|
mail = last_email
|
|
796
|
mail = last_email
|
|
793
|
assert_not_nil mail
|
|
797
|
assert_not_nil mail
|
|
794
|
assert_not_include "\n-- \n", mail.body.decoded
|
|
798
|
assert_not_include "\n-- \n", mail.body.decoded
|
|
795
|
end
|
|
799
|
end
|
|
796
|
end
|
|
800
|
end
|
|
797
|
end
|
|
801
|
end
|
|
798
|
|
|
802
|
|
|
799
|
def test_should_escape_html_templates_only
|
|
803
|
def test_should_escape_html_templates_only
|
|
800
|
Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
|
|
804
|
Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
|
|
801
|
mail = last_email
|
|
805
|
mail = last_email
|
|
802
|
assert_equal 2, mail.parts.size
|
|
806
|
assert_equal 2, mail.parts.size
|
|
803
|
assert_include '<tag>', text_part.body.encoded
|
|
807
|
assert_include '<tag>', text_part.body.encoded
|
|
804
|
assert_include '<tag>', html_part.body.encoded
|
|
808
|
assert_include '<tag>', html_part.body.encoded
|
|
805
|
end
|
|
809
|
end
|
|
806
|
|
|
810
|
|
|
807
|
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
|
|
811
|
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
|
|
808
|
mail = Mailer.test_email(User.find(1))
|
|
812
|
mail = Mailer.test_email(User.find(1))
|
|
809
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
|
813
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
|
810
|
|
|
814
|
|
|
811
|
ActionMailer::Base.raise_delivery_errors = true
|
|
815
|
ActionMailer::Base.raise_delivery_errors = true
|
|
812
|
assert_raise Exception, "delivery error" do
|
|
816
|
assert_raise Exception, "delivery error" do
|
|
813
|
mail.deliver
|
|
817
|
mail.deliver
|
|
814
|
end
|
|
818
|
end
|
|
815
|
ensure
|
|
819
|
ensure
|
|
816
|
ActionMailer::Base.raise_delivery_errors = false
|
|
820
|
ActionMailer::Base.raise_delivery_errors = false
|
|
817
|
end
|
|
821
|
end
|
|
818
|
|
|
822
|
|
|
819
|
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
|
|
823
|
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
|
|
820
|
mail = Mailer.test_email(User.find(1))
|
|
824
|
mail = Mailer.test_email(User.find(1))
|
|
821
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
|
825
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
|
822
|
|
|
826
|
|
|
823
|
Rails.logger.expects(:error).with("Email delivery error: delivery error")
|
|
827
|
Rails.logger.expects(:error).with("Email delivery error: delivery error")
|
|
824
|
ActionMailer::Base.raise_delivery_errors = false
|
|
828
|
ActionMailer::Base.raise_delivery_errors = false
|
|
825
|
assert_nothing_raised do
|
|
829
|
assert_nothing_raised do
|
|
826
|
mail.deliver
|
|
830
|
mail.deliver
|
|
827
|
end
|
|
831
|
end
|
|
828
|
end
|
|
832
|
end
|
|
829
|
|
|
833
|
|
|
830
|
def test_with_synched_deliveries_should_yield_with_synced_deliveries
|
|
834
|
def test_with_synched_deliveries_should_yield_with_synced_deliveries
|
|
831
|
ActionMailer::Base.delivery_method = :async_smtp
|
|
835
|
ActionMailer::Base.delivery_method = :async_smtp
|
|
832
|
ActionMailer::Base.async_smtp_settings = {:foo => 'bar'}
|
|
836
|
ActionMailer::Base.async_smtp_settings = {:foo => 'bar'}
|
|
833
|
|
|
837
|
|
|
834
|
Mailer.with_synched_deliveries do
|
|
838
|
Mailer.with_synched_deliveries do
|
|
835
|
assert_equal :smtp, ActionMailer::Base.delivery_method
|
|
839
|
assert_equal :smtp, ActionMailer::Base.delivery_method
|
|
836
|
assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings)
|
|
840
|
assert_equal({:foo => 'bar'}, ActionMailer::Base.smtp_settings)
|
|
837
|
end
|
|
841
|
end
|
|
838
|
assert_equal :async_smtp, ActionMailer::Base.delivery_method
|
|
842
|
assert_equal :async_smtp, ActionMailer::Base.delivery_method
|
|
839
|
ensure
|
|
843
|
ensure
|
|
840
|
ActionMailer::Base.delivery_method = :test
|
|
844
|
ActionMailer::Base.delivery_method = :test
|
|
841
|
end
|
|
845
|
end
|
|
842
|
|
|
846
|
|
|
843
|
def test_email_addresses_should_keep_addresses
|
|
847
|
def test_email_addresses_should_keep_addresses
|
|
844
|
assert_equal ["foo@example.net"],
|
|
848
|
assert_equal ["foo@example.net"],
|
|
845
|
Mailer.email_addresses("foo@example.net")
|
|
849
|
Mailer.email_addresses("foo@example.net")
|
|
846
|
|
|
850
|
|
|
847
|
assert_equal ["foo@example.net", "bar@example.net"],
|
|
851
|
assert_equal ["foo@example.net", "bar@example.net"],
|
|
848
|
Mailer.email_addresses(["foo@example.net", "bar@example.net"])
|
|
852
|
Mailer.email_addresses(["foo@example.net", "bar@example.net"])
|
|
849
|
end
|
|
853
|
end
|
|
850
|
|
|
854
|
|
|
851
|
def test_email_addresses_should_replace_users_with_their_email_addresses
|
|
855
|
def test_email_addresses_should_replace_users_with_their_email_addresses
|
|
852
|
assert_equal ["admin@somenet.foo"],
|
|
856
|
assert_equal ["admin@somenet.foo"],
|
|
853
|
Mailer.email_addresses(User.find(1))
|
|
857
|
Mailer.email_addresses(User.find(1))
|
|
854
|
|
|
858
|
|
|
855
|
assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"],
|
|
859
|
assert_equal ["admin@somenet.foo", "jsmith@somenet.foo"],
|
|
856
|
Mailer.email_addresses(User.where(:id => [1,2])).sort
|
|
860
|
Mailer.email_addresses(User.where(:id => [1,2])).sort
|
|
857
|
end
|
|
861
|
end
|
|
858
|
|
|
862
|
|
|
859
|
def test_email_addresses_should_include_notified_emails_addresses_only
|
|
863
|
def test_email_addresses_should_include_notified_emails_addresses_only
|
|
860
|
EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false)
|
|
864
|
EmailAddress.create!(:user_id => 2, :address => "another@somenet.foo", :notify => false)
|
|
861
|
EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo")
|
|
865
|
EmailAddress.create!(:user_id => 2, :address => "another2@somenet.foo")
|
|
862
|
|
|
866
|
|
|
863
|
assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"],
|
|
867
|
assert_equal ["another2@somenet.foo", "jsmith@somenet.foo"],
|
|
864
|
Mailer.email_addresses(User.find(2)).sort
|
|
868
|
Mailer.email_addresses(User.find(2)).sort
|
|
865
|
end
|
|
869
|
end
|
|
866
|
|
|
870
|
|
|
867
|
private
|
|
871
|
private
|
|
868
|
|
|
872
|
|
|
869
|
def last_email
|
|
873
|
def last_email
|
|
870
|
mail = ActionMailer::Base.deliveries.last
|
|
874
|
mail = ActionMailer::Base.deliveries.last
|
|
871
|
assert_not_nil mail
|
|
875
|
assert_not_nil mail
|
|
872
|
mail
|
|
876
|
mail
|
|
873
|
end
|
|
877
|
end
|
|
874
|
|
|
878
|
|
|
875
|
def text_part
|
|
879
|
def text_part
|
|
876
|
last_email.parts.detect {|part| part.content_type.include?('text/plain')}
|
|
880
|
last_email.parts.detect {|part| part.content_type.include?('text/plain')}
|
|
877
|
end
|
|
881
|
end
|
|
878
|
|
|
882
|
|
|
879
|
def html_part
|
|
883
|
def html_part
|
|
880
|
last_email.parts.detect {|part| part.content_type.include?('text/html')}
|
|
884
|
last_email.parts.detect {|part| part.content_type.include?('text/html')}
|
|
881
|
end
|
|
885
|
end
|
|
882
|
|
|
886
|
|
|
883
|
def with_each_language_as_default(&block)
|
|
887
|
def with_each_language_as_default(&block)
|
|
884
|
valid_languages.each do |lang|
|
|
888
|
valid_languages.each do |lang|
|
|
885
|
with_settings :default_language => lang.to_s do
|
|
889
|
with_settings :default_language => lang.to_s do
|
|
886
|
yield lang
|
|
890
|
yield lang
|
|
887
|
end
|
|
891
|
end
|
|
888
|
end
|
|
892
|
end
|
|
889
|
end
|
|
893
|
end
|
|
890
|
end
|
|
894
|
end
|