##// END OF EJS Templates
code layout clean up of test_message_posted_message_id at test/unit/mailer_test.rb...
Toshi MARUYAMA -
r7381:af3c96e0af95
parent child
Show More
@@ -1,475 +1,477
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 ActionController::Assertions::SelectorAssertions
22 include ActionController::Assertions::SelectorAssertions
23 fixtures :projects, :enabled_modules, :issues, :users, :members,
23 fixtures :projects, :enabled_modules, :issues, :users, :members,
24 :member_roles, :roles, :documents, :attachments, :news,
24 :member_roles, :roles, :documents, :attachments, :news,
25 :tokens, :journals, :journal_details, :changesets, :trackers,
25 :tokens, :journals, :journal_details, :changesets, :trackers,
26 :issue_statuses, :enumerations, :messages, :boards, :repositories,
26 :issue_statuses, :enumerations, :messages, :boards, :repositories,
27 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
27 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
28 :versions,
28 :versions,
29 :comments
29 :comments
30
30
31 def setup
31 def setup
32 ActionMailer::Base.deliveries.clear
32 ActionMailer::Base.deliveries.clear
33 Setting.host_name = 'mydomain.foo'
33 Setting.host_name = 'mydomain.foo'
34 Setting.protocol = 'http'
34 Setting.protocol = 'http'
35 Setting.plain_text_mail = '0'
35 Setting.plain_text_mail = '0'
36 end
36 end
37
37
38 def test_generated_links_in_emails
38 def test_generated_links_in_emails
39 Setting.host_name = 'mydomain.foo'
39 Setting.host_name = 'mydomain.foo'
40 Setting.protocol = 'https'
40 Setting.protocol = 'https'
41
41
42 journal = Journal.find(2)
42 journal = Journal.find(2)
43 assert Mailer.deliver_issue_edit(journal)
43 assert Mailer.deliver_issue_edit(journal)
44
44
45 mail = ActionMailer::Base.deliveries.last
45 mail = ActionMailer::Base.deliveries.last
46 assert_kind_of TMail::Mail, mail
46 assert_kind_of TMail::Mail, mail
47
47
48 assert_select_email do
48 assert_select_email do
49 # link to the main ticket
49 # link to the main ticket
50 assert_select "a[href=?]",
50 assert_select "a[href=?]",
51 "https://mydomain.foo/issues/1",
51 "https://mydomain.foo/issues/1",
52 :text => "Bug #1: Can't print recipes"
52 :text => "Bug #1: Can't print recipes"
53 # link to a referenced ticket
53 # link to a referenced ticket
54 assert_select "a[href=?][title=?]",
54 assert_select "a[href=?][title=?]",
55 "https://mydomain.foo/issues/2",
55 "https://mydomain.foo/issues/2",
56 "Add ingredients categories (Assigned)",
56 "Add ingredients categories (Assigned)",
57 :text => "#2"
57 :text => "#2"
58 # link to a changeset
58 # link to a changeset
59 assert_select "a[href=?][title=?]",
59 assert_select "a[href=?][title=?]",
60 "https://mydomain.foo/projects/ecookbook/repository/revisions/2",
60 "https://mydomain.foo/projects/ecookbook/repository/revisions/2",
61 "This commit fixes #1, #2 and references #1 &amp; #3",
61 "This commit fixes #1, #2 and references #1 &amp; #3",
62 :text => "r2"
62 :text => "r2"
63 end
63 end
64 end
64 end
65
65
66 def test_generated_links_with_prefix
66 def test_generated_links_with_prefix
67 relative_url_root = Redmine::Utils.relative_url_root
67 relative_url_root = Redmine::Utils.relative_url_root
68 Setting.host_name = 'mydomain.foo/rdm'
68 Setting.host_name = 'mydomain.foo/rdm'
69 Setting.protocol = 'http'
69 Setting.protocol = 'http'
70 Redmine::Utils.relative_url_root = '/rdm'
70 Redmine::Utils.relative_url_root = '/rdm'
71
71
72 journal = Journal.find(2)
72 journal = Journal.find(2)
73 assert Mailer.deliver_issue_edit(journal)
73 assert Mailer.deliver_issue_edit(journal)
74
74
75 mail = ActionMailer::Base.deliveries.last
75 mail = ActionMailer::Base.deliveries.last
76 assert_kind_of TMail::Mail, mail
76 assert_kind_of TMail::Mail, mail
77
77
78 assert_select_email do
78 assert_select_email do
79 # link to the main ticket
79 # link to the main ticket
80 assert_select "a[href=?]",
80 assert_select "a[href=?]",
81 "http://mydomain.foo/rdm/issues/1",
81 "http://mydomain.foo/rdm/issues/1",
82 :text => "Bug #1: Can't print recipes"
82 :text => "Bug #1: Can't print recipes"
83 # link to a referenced ticket
83 # link to a referenced ticket
84 assert_select "a[href=?][title=?]",
84 assert_select "a[href=?][title=?]",
85 "http://mydomain.foo/rdm/issues/2",
85 "http://mydomain.foo/rdm/issues/2",
86 "Add ingredients categories (Assigned)",
86 "Add ingredients categories (Assigned)",
87 :text => "#2"
87 :text => "#2"
88 # link to a changeset
88 # link to a changeset
89 assert_select "a[href=?][title=?]",
89 assert_select "a[href=?][title=?]",
90 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
90 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
91 "This commit fixes #1, #2 and references #1 &amp; #3",
91 "This commit fixes #1, #2 and references #1 &amp; #3",
92 :text => "r2"
92 :text => "r2"
93 end
93 end
94 ensure
94 ensure
95 # restore it
95 # restore it
96 Redmine::Utils.relative_url_root = relative_url_root
96 Redmine::Utils.relative_url_root = relative_url_root
97 end
97 end
98
98
99 def test_generated_links_with_prefix_and_no_relative_url_root
99 def test_generated_links_with_prefix_and_no_relative_url_root
100 relative_url_root = Redmine::Utils.relative_url_root
100 relative_url_root = Redmine::Utils.relative_url_root
101 Setting.host_name = 'mydomain.foo/rdm'
101 Setting.host_name = 'mydomain.foo/rdm'
102 Setting.protocol = 'http'
102 Setting.protocol = 'http'
103 Redmine::Utils.relative_url_root = nil
103 Redmine::Utils.relative_url_root = nil
104
104
105 journal = Journal.find(2)
105 journal = Journal.find(2)
106 assert Mailer.deliver_issue_edit(journal)
106 assert Mailer.deliver_issue_edit(journal)
107
107
108 mail = ActionMailer::Base.deliveries.last
108 mail = ActionMailer::Base.deliveries.last
109 assert_kind_of TMail::Mail, mail
109 assert_kind_of TMail::Mail, mail
110
110
111 assert_select_email do
111 assert_select_email do
112 # link to the main ticket
112 # link to the main ticket
113 assert_select "a[href=?]",
113 assert_select "a[href=?]",
114 "http://mydomain.foo/rdm/issues/1",
114 "http://mydomain.foo/rdm/issues/1",
115 :text => "Bug #1: Can't print recipes"
115 :text => "Bug #1: Can't print recipes"
116 # link to a referenced ticket
116 # link to a referenced ticket
117 assert_select "a[href=?][title=?]",
117 assert_select "a[href=?][title=?]",
118 "http://mydomain.foo/rdm/issues/2",
118 "http://mydomain.foo/rdm/issues/2",
119 "Add ingredients categories (Assigned)",
119 "Add ingredients categories (Assigned)",
120 :text => "#2"
120 :text => "#2"
121 # link to a changeset
121 # link to a changeset
122 assert_select "a[href=?][title=?]",
122 assert_select "a[href=?][title=?]",
123 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
123 "http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2",
124 "This commit fixes #1, #2 and references #1 &amp; #3",
124 "This commit fixes #1, #2 and references #1 &amp; #3",
125 :text => "r2"
125 :text => "r2"
126 end
126 end
127 ensure
127 ensure
128 # restore it
128 # restore it
129 Redmine::Utils.relative_url_root = relative_url_root
129 Redmine::Utils.relative_url_root = relative_url_root
130 end
130 end
131
131
132 def test_email_headers
132 def test_email_headers
133 issue = Issue.find(1)
133 issue = Issue.find(1)
134 Mailer.deliver_issue_add(issue)
134 Mailer.deliver_issue_add(issue)
135 mail = ActionMailer::Base.deliveries.last
135 mail = ActionMailer::Base.deliveries.last
136 assert_not_nil mail
136 assert_not_nil mail
137 assert_equal 'bulk', mail.header_string('Precedence')
137 assert_equal 'bulk', mail.header_string('Precedence')
138 assert_equal 'auto-generated', mail.header_string('Auto-Submitted')
138 assert_equal 'auto-generated', mail.header_string('Auto-Submitted')
139 end
139 end
140
140
141 def test_plain_text_mail
141 def test_plain_text_mail
142 Setting.plain_text_mail = 1
142 Setting.plain_text_mail = 1
143 journal = Journal.find(2)
143 journal = Journal.find(2)
144 Mailer.deliver_issue_edit(journal)
144 Mailer.deliver_issue_edit(journal)
145 mail = ActionMailer::Base.deliveries.last
145 mail = ActionMailer::Base.deliveries.last
146 assert_equal "text/plain", mail.content_type
146 assert_equal "text/plain", mail.content_type
147 assert_equal 0, mail.parts.size
147 assert_equal 0, mail.parts.size
148 assert !mail.encoded.include?('href')
148 assert !mail.encoded.include?('href')
149 end
149 end
150
150
151 def test_html_mail
151 def test_html_mail
152 Setting.plain_text_mail = 0
152 Setting.plain_text_mail = 0
153 journal = Journal.find(2)
153 journal = Journal.find(2)
154 Mailer.deliver_issue_edit(journal)
154 Mailer.deliver_issue_edit(journal)
155 mail = ActionMailer::Base.deliveries.last
155 mail = ActionMailer::Base.deliveries.last
156 assert_equal 2, mail.parts.size
156 assert_equal 2, mail.parts.size
157 assert mail.encoded.include?('href')
157 assert mail.encoded.include?('href')
158 end
158 end
159
159
160 def test_mail_from_with_phrase
160 def test_mail_from_with_phrase
161 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
161 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
162 Mailer.deliver_test(User.find(1))
162 Mailer.deliver_test(User.find(1))
163 end
163 end
164 mail = ActionMailer::Base.deliveries.last
164 mail = ActionMailer::Base.deliveries.last
165 assert_not_nil mail
165 assert_not_nil mail
166 assert_equal 'Redmine app', mail.from_addrs.first.name
166 assert_equal 'Redmine app', mail.from_addrs.first.name
167 end
167 end
168
168
169 def test_should_not_send_email_without_recipient
169 def test_should_not_send_email_without_recipient
170 news = News.find(:first)
170 news = News.find(:first)
171 user = news.author
171 user = news.author
172 # Remove members except news author
172 # Remove members except news author
173 news.project.memberships.each {|m| m.destroy unless m.user == user}
173 news.project.memberships.each {|m| m.destroy unless m.user == user}
174
174
175 user.pref[:no_self_notified] = false
175 user.pref[:no_self_notified] = false
176 user.pref.save
176 user.pref.save
177 User.current = user
177 User.current = user
178 Mailer.deliver_news_added(news.reload)
178 Mailer.deliver_news_added(news.reload)
179 assert_equal 1, last_email.bcc.size
179 assert_equal 1, last_email.bcc.size
180
180
181 # nobody to notify
181 # nobody to notify
182 user.pref[:no_self_notified] = true
182 user.pref[:no_self_notified] = true
183 user.pref.save
183 user.pref.save
184 User.current = user
184 User.current = user
185 ActionMailer::Base.deliveries.clear
185 ActionMailer::Base.deliveries.clear
186 Mailer.deliver_news_added(news.reload)
186 Mailer.deliver_news_added(news.reload)
187 assert ActionMailer::Base.deliveries.empty?
187 assert ActionMailer::Base.deliveries.empty?
188 end
188 end
189
189
190 def test_issue_add_message_id
190 def test_issue_add_message_id
191 issue = Issue.find(1)
191 issue = Issue.find(1)
192 Mailer.deliver_issue_add(issue)
192 Mailer.deliver_issue_add(issue)
193 mail = ActionMailer::Base.deliveries.last
193 mail = ActionMailer::Base.deliveries.last
194 assert_not_nil mail
194 assert_not_nil mail
195 assert_equal Mailer.message_id_for(issue), mail.message_id
195 assert_equal Mailer.message_id_for(issue), mail.message_id
196 assert_nil mail.references
196 assert_nil mail.references
197 end
197 end
198
198
199 def test_issue_edit_message_id
199 def test_issue_edit_message_id
200 journal = Journal.find(1)
200 journal = Journal.find(1)
201 Mailer.deliver_issue_edit(journal)
201 Mailer.deliver_issue_edit(journal)
202 mail = ActionMailer::Base.deliveries.last
202 mail = ActionMailer::Base.deliveries.last
203 assert_not_nil mail
203 assert_not_nil mail
204 assert_equal Mailer.message_id_for(journal), mail.message_id
204 assert_equal Mailer.message_id_for(journal), mail.message_id
205 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s
205 assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s
206 end
206 end
207
207
208 def test_message_posted_message_id
208 def test_message_posted_message_id
209 message = Message.find(1)
209 message = Message.find(1)
210 Mailer.deliver_message_posted(message)
210 Mailer.deliver_message_posted(message)
211 mail = ActionMailer::Base.deliveries.last
211 mail = ActionMailer::Base.deliveries.last
212 assert_not_nil mail
212 assert_not_nil mail
213 assert_equal Mailer.message_id_for(message), mail.message_id
213 assert_equal Mailer.message_id_for(message), mail.message_id
214 assert_nil mail.references
214 assert_nil mail.references
215 assert_select_email do
215 assert_select_email do
216 # link to the message
216 # link to the message
217 assert_select "a[href=?]", "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", :text => message.subject
217 assert_select "a[href=?]",
218 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
219 :text => message.subject
218 end
220 end
219 end
221 end
220
222
221 def test_reply_posted_message_id
223 def test_reply_posted_message_id
222 message = Message.find(3)
224 message = Message.find(3)
223 Mailer.deliver_message_posted(message)
225 Mailer.deliver_message_posted(message)
224 mail = ActionMailer::Base.deliveries.last
226 mail = ActionMailer::Base.deliveries.last
225 assert_not_nil mail
227 assert_not_nil mail
226 assert_equal Mailer.message_id_for(message), mail.message_id
228 assert_equal Mailer.message_id_for(message), mail.message_id
227 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s
229 assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s
228 assert_select_email do
230 assert_select_email do
229 # link to the reply
231 # link to the reply
230 assert_select "a[href=?]", "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", :text => message.subject
232 assert_select "a[href=?]", "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", :text => message.subject
231 end
233 end
232 end
234 end
233
235
234 context("#issue_add") do
236 context("#issue_add") do
235 setup do
237 setup do
236 ActionMailer::Base.deliveries.clear
238 ActionMailer::Base.deliveries.clear
237 Setting.bcc_recipients = '1'
239 Setting.bcc_recipients = '1'
238 @issue = Issue.find(1)
240 @issue = Issue.find(1)
239 end
241 end
240
242
241 should "notify project members" do
243 should "notify project members" do
242 assert Mailer.deliver_issue_add(@issue)
244 assert Mailer.deliver_issue_add(@issue)
243 assert last_email.bcc.include?('dlopper@somenet.foo')
245 assert last_email.bcc.include?('dlopper@somenet.foo')
244 end
246 end
245
247
246 should "not notify project members that are not allow to view the issue" do
248 should "not notify project members that are not allow to view the issue" do
247 Role.find(2).remove_permission!(:view_issues)
249 Role.find(2).remove_permission!(:view_issues)
248 assert Mailer.deliver_issue_add(@issue)
250 assert Mailer.deliver_issue_add(@issue)
249 assert !last_email.bcc.include?('dlopper@somenet.foo')
251 assert !last_email.bcc.include?('dlopper@somenet.foo')
250 end
252 end
251
253
252 should "notify issue watchers" do
254 should "notify issue watchers" do
253 user = User.find(9)
255 user = User.find(9)
254 # minimal email notification options
256 # minimal email notification options
255 user.pref[:no_self_notified] = '1'
257 user.pref[:no_self_notified] = '1'
256 user.pref.save
258 user.pref.save
257 user.mail_notification = false
259 user.mail_notification = false
258 user.save
260 user.save
259
261
260 Watcher.create!(:watchable => @issue, :user => user)
262 Watcher.create!(:watchable => @issue, :user => user)
261 assert Mailer.deliver_issue_add(@issue)
263 assert Mailer.deliver_issue_add(@issue)
262 assert last_email.bcc.include?(user.mail)
264 assert last_email.bcc.include?(user.mail)
263 end
265 end
264
266
265 should "not notify watchers not allowed to view the issue" do
267 should "not notify watchers not allowed to view the issue" do
266 user = User.find(9)
268 user = User.find(9)
267 Watcher.create!(:watchable => @issue, :user => user)
269 Watcher.create!(:watchable => @issue, :user => user)
268 Role.non_member.remove_permission!(:view_issues)
270 Role.non_member.remove_permission!(:view_issues)
269 assert Mailer.deliver_issue_add(@issue)
271 assert Mailer.deliver_issue_add(@issue)
270 assert !last_email.bcc.include?(user.mail)
272 assert !last_email.bcc.include?(user.mail)
271 end
273 end
272 end
274 end
273
275
274 # test mailer methods for each language
276 # test mailer methods for each language
275 def test_issue_add
277 def test_issue_add
276 issue = Issue.find(1)
278 issue = Issue.find(1)
277 valid_languages.each do |lang|
279 valid_languages.each do |lang|
278 Setting.default_language = lang.to_s
280 Setting.default_language = lang.to_s
279 assert Mailer.deliver_issue_add(issue)
281 assert Mailer.deliver_issue_add(issue)
280 end
282 end
281 end
283 end
282
284
283 def test_issue_edit
285 def test_issue_edit
284 journal = Journal.find(1)
286 journal = Journal.find(1)
285 valid_languages.each do |lang|
287 valid_languages.each do |lang|
286 Setting.default_language = lang.to_s
288 Setting.default_language = lang.to_s
287 assert Mailer.deliver_issue_edit(journal)
289 assert Mailer.deliver_issue_edit(journal)
288 end
290 end
289 end
291 end
290
292
291 def test_document_added
293 def test_document_added
292 document = Document.find(1)
294 document = Document.find(1)
293 valid_languages.each do |lang|
295 valid_languages.each do |lang|
294 Setting.default_language = lang.to_s
296 Setting.default_language = lang.to_s
295 assert Mailer.deliver_document_added(document)
297 assert Mailer.deliver_document_added(document)
296 end
298 end
297 end
299 end
298
300
299 def test_attachments_added
301 def test_attachments_added
300 attachements = [ Attachment.find_by_container_type('Document') ]
302 attachements = [ Attachment.find_by_container_type('Document') ]
301 valid_languages.each do |lang|
303 valid_languages.each do |lang|
302 Setting.default_language = lang.to_s
304 Setting.default_language = lang.to_s
303 assert Mailer.deliver_attachments_added(attachements)
305 assert Mailer.deliver_attachments_added(attachements)
304 end
306 end
305 end
307 end
306
308
307 def test_version_file_added
309 def test_version_file_added
308 attachements = [ Attachment.find_by_container_type('Version') ]
310 attachements = [ Attachment.find_by_container_type('Version') ]
309 assert Mailer.deliver_attachments_added(attachements)
311 assert Mailer.deliver_attachments_added(attachements)
310 assert_not_nil last_email.bcc
312 assert_not_nil last_email.bcc
311 assert last_email.bcc.any?
313 assert last_email.bcc.any?
312 assert_select_email do
314 assert_select_email do
313 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
315 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
314 end
316 end
315 end
317 end
316
318
317 def test_project_file_added
319 def test_project_file_added
318 attachements = [ Attachment.find_by_container_type('Project') ]
320 attachements = [ Attachment.find_by_container_type('Project') ]
319 assert Mailer.deliver_attachments_added(attachements)
321 assert Mailer.deliver_attachments_added(attachements)
320 assert_not_nil last_email.bcc
322 assert_not_nil last_email.bcc
321 assert last_email.bcc.any?
323 assert last_email.bcc.any?
322 assert_select_email do
324 assert_select_email do
323 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
325 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
324 end
326 end
325 end
327 end
326
328
327 def test_news_added
329 def test_news_added
328 news = News.find(:first)
330 news = News.find(:first)
329 valid_languages.each do |lang|
331 valid_languages.each do |lang|
330 Setting.default_language = lang.to_s
332 Setting.default_language = lang.to_s
331 assert Mailer.deliver_news_added(news)
333 assert Mailer.deliver_news_added(news)
332 end
334 end
333 end
335 end
334
336
335 def test_news_comment_added
337 def test_news_comment_added
336 comment = Comment.find(2)
338 comment = Comment.find(2)
337 valid_languages.each do |lang|
339 valid_languages.each do |lang|
338 Setting.default_language = lang.to_s
340 Setting.default_language = lang.to_s
339 assert Mailer.deliver_news_comment_added(comment)
341 assert Mailer.deliver_news_comment_added(comment)
340 end
342 end
341 end
343 end
342
344
343 def test_message_posted
345 def test_message_posted
344 message = Message.find(:first)
346 message = Message.find(:first)
345 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
347 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
346 recipients = recipients.compact.uniq
348 recipients = recipients.compact.uniq
347 valid_languages.each do |lang|
349 valid_languages.each do |lang|
348 Setting.default_language = lang.to_s
350 Setting.default_language = lang.to_s
349 assert Mailer.deliver_message_posted(message)
351 assert Mailer.deliver_message_posted(message)
350 end
352 end
351 end
353 end
352
354
353 def test_wiki_content_added
355 def test_wiki_content_added
354 content = WikiContent.find(:first)
356 content = WikiContent.find(:first)
355 valid_languages.each do |lang|
357 valid_languages.each do |lang|
356 Setting.default_language = lang.to_s
358 Setting.default_language = lang.to_s
357 assert_difference 'ActionMailer::Base.deliveries.size' do
359 assert_difference 'ActionMailer::Base.deliveries.size' do
358 assert Mailer.deliver_wiki_content_added(content)
360 assert Mailer.deliver_wiki_content_added(content)
359 end
361 end
360 end
362 end
361 end
363 end
362
364
363 def test_wiki_content_updated
365 def test_wiki_content_updated
364 content = WikiContent.find(:first)
366 content = WikiContent.find(:first)
365 valid_languages.each do |lang|
367 valid_languages.each do |lang|
366 Setting.default_language = lang.to_s
368 Setting.default_language = lang.to_s
367 assert_difference 'ActionMailer::Base.deliveries.size' do
369 assert_difference 'ActionMailer::Base.deliveries.size' do
368 assert Mailer.deliver_wiki_content_updated(content)
370 assert Mailer.deliver_wiki_content_updated(content)
369 end
371 end
370 end
372 end
371 end
373 end
372
374
373 def test_account_information
375 def test_account_information
374 user = User.find(2)
376 user = User.find(2)
375 valid_languages.each do |lang|
377 valid_languages.each do |lang|
376 user.update_attribute :language, lang.to_s
378 user.update_attribute :language, lang.to_s
377 user.reload
379 user.reload
378 assert Mailer.deliver_account_information(user, 'pAsswORd')
380 assert Mailer.deliver_account_information(user, 'pAsswORd')
379 end
381 end
380 end
382 end
381
383
382 def test_lost_password
384 def test_lost_password
383 token = Token.find(2)
385 token = Token.find(2)
384 valid_languages.each do |lang|
386 valid_languages.each do |lang|
385 token.user.update_attribute :language, lang.to_s
387 token.user.update_attribute :language, lang.to_s
386 token.reload
388 token.reload
387 assert Mailer.deliver_lost_password(token)
389 assert Mailer.deliver_lost_password(token)
388 end
390 end
389 end
391 end
390
392
391 def test_register
393 def test_register
392 token = Token.find(1)
394 token = Token.find(1)
393 Setting.host_name = 'redmine.foo'
395 Setting.host_name = 'redmine.foo'
394 Setting.protocol = 'https'
396 Setting.protocol = 'https'
395
397
396 valid_languages.each do |lang|
398 valid_languages.each do |lang|
397 token.user.update_attribute :language, lang.to_s
399 token.user.update_attribute :language, lang.to_s
398 token.reload
400 token.reload
399 ActionMailer::Base.deliveries.clear
401 ActionMailer::Base.deliveries.clear
400 assert Mailer.deliver_register(token)
402 assert Mailer.deliver_register(token)
401 mail = ActionMailer::Base.deliveries.last
403 mail = ActionMailer::Base.deliveries.last
402 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}")
404 assert mail.body.include?("https://redmine.foo/account/activate?token=#{token.value}")
403 end
405 end
404 end
406 end
405
407
406 def test_test
408 def test_test
407 user = User.find(1)
409 user = User.find(1)
408 valid_languages.each do |lang|
410 valid_languages.each do |lang|
409 user.update_attribute :language, lang.to_s
411 user.update_attribute :language, lang.to_s
410 assert Mailer.deliver_test(user)
412 assert Mailer.deliver_test(user)
411 end
413 end
412 end
414 end
413
415
414 def test_reminders
416 def test_reminders
415 Mailer.reminders(:days => 42)
417 Mailer.reminders(:days => 42)
416 assert_equal 1, ActionMailer::Base.deliveries.size
418 assert_equal 1, ActionMailer::Base.deliveries.size
417 mail = ActionMailer::Base.deliveries.last
419 mail = ActionMailer::Base.deliveries.last
418 assert mail.bcc.include?('dlopper@somenet.foo')
420 assert mail.bcc.include?('dlopper@somenet.foo')
419 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
421 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
420 assert_equal '1 issue(s) due in the next 42 days', mail.subject
422 assert_equal '1 issue(s) due in the next 42 days', mail.subject
421 end
423 end
422
424
423 def test_reminders_for_users
425 def test_reminders_for_users
424 Mailer.reminders(:days => 42, :users => ['5'])
426 Mailer.reminders(:days => 42, :users => ['5'])
425 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
427 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
426 Mailer.reminders(:days => 42, :users => ['3'])
428 Mailer.reminders(:days => 42, :users => ['3'])
427 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
429 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
428 mail = ActionMailer::Base.deliveries.last
430 mail = ActionMailer::Base.deliveries.last
429 assert mail.bcc.include?('dlopper@somenet.foo')
431 assert mail.bcc.include?('dlopper@somenet.foo')
430 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
432 assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
431 end
433 end
432
434
433 def last_email
435 def last_email
434 mail = ActionMailer::Base.deliveries.last
436 mail = ActionMailer::Base.deliveries.last
435 assert_not_nil mail
437 assert_not_nil mail
436 mail
438 mail
437 end
439 end
438
440
439 def test_mailer_should_not_change_locale
441 def test_mailer_should_not_change_locale
440 Setting.default_language = 'en'
442 Setting.default_language = 'en'
441 # Set current language to italian
443 # Set current language to italian
442 set_language_if_valid 'it'
444 set_language_if_valid 'it'
443 # Send an email to a french user
445 # Send an email to a french user
444 user = User.find(1)
446 user = User.find(1)
445 user.language = 'fr'
447 user.language = 'fr'
446 Mailer.deliver_account_activated(user)
448 Mailer.deliver_account_activated(user)
447 mail = ActionMailer::Base.deliveries.last
449 mail = ActionMailer::Base.deliveries.last
448 assert mail.body.include?('Votre compte')
450 assert mail.body.include?('Votre compte')
449
451
450 assert_equal :it, current_language
452 assert_equal :it, current_language
451 end
453 end
452
454
453 def test_with_deliveries_off
455 def test_with_deliveries_off
454 Mailer.with_deliveries false do
456 Mailer.with_deliveries false do
455 Mailer.deliver_test(User.find(1))
457 Mailer.deliver_test(User.find(1))
456 end
458 end
457 assert ActionMailer::Base.deliveries.empty?
459 assert ActionMailer::Base.deliveries.empty?
458 # should restore perform_deliveries
460 # should restore perform_deliveries
459 assert ActionMailer::Base.perform_deliveries
461 assert ActionMailer::Base.perform_deliveries
460 end
462 end
461
463
462 context "layout" do
464 context "layout" do
463 should "include the emails_header" do
465 should "include the emails_header" do
464 with_settings(:emails_header => "*Header content*") do
466 with_settings(:emails_header => "*Header content*") do
465 assert Mailer.deliver_test(User.find(1))
467 assert Mailer.deliver_test(User.find(1))
466
468
467 assert_select_email do
469 assert_select_email do
468 assert_select ".header" do
470 assert_select ".header" do
469 assert_select "strong", :text => "Header content"
471 assert_select "strong", :text => "Header content"
470 end
472 end
471 end
473 end
472 end
474 end
473 end
475 end
474 end
476 end
475 end
477 end
General Comments 0
You need to be logged in to leave comments. Login now