##// END OF EJS Templates
Adds markings to emails generated by private comments (#12888)....
Jean-Philippe Lang -
r11639:1093454193bd
parent child
Show More
@@ -1,11 +1,14
1 <% if @journal.private_notes? %>
2 (<%= l(:field_private_notes) %>)
3 <% end %>
1 4 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => h(@journal.user)) %>
2 5
3 6 <ul>
4 7 <% details_to_strings(@journal.details, false, :only_path => false).each do |string| %>
5 8 <li><%= string %></li>
6 9 <% end %>
7 10 </ul>
8 11
9 12 <%= textilizable(@journal, :notes, :only_path => false) %>
10 13 <hr />
11 14 <%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,12 +1,12
1 <%= l(:text_issue_updated, :id => "##{@issue.id}", :author => @journal.user) %>
1 <%= "(#{l(:field_private_notes)}) " if @journal.private_notes? -%><%= l(:text_issue_updated, :id => "##{@issue.id}", :author => @journal.user) %>
2 2
3 3 <% details_to_strings(@journal.details, true).each do |string| -%>
4 4 <%= string %>
5 5 <% end -%>
6 6
7 7 <% if @journal.notes? -%>
8 8 <%= @journal.notes %>
9 9
10 10 <% end -%>
11 11 ----------------------------------------
12 12 <%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :issue_url => @issue_url } %>
@@ -1,668 +1,679
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class MailerTest < ActiveSupport::TestCase
21 21 include Redmine::I18n
22 22 include ActionDispatch::Assertions::SelectorAssertions
23 23 fixtures :projects, :enabled_modules, :issues, :users, :members,
24 24 :member_roles, :roles, :documents, :attachments, :news,
25 25 :tokens, :journals, :journal_details, :changesets,
26 26 :trackers, :projects_trackers,
27 27 :issue_statuses, :enumerations, :messages, :boards, :repositories,
28 28 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
29 29 :versions,
30 30 :comments
31 31
32 32 def setup
33 33 ActionMailer::Base.deliveries.clear
34 34 Setting.host_name = 'mydomain.foo'
35 35 Setting.protocol = 'http'
36 36 Setting.plain_text_mail = '0'
37 37 end
38 38
39 39 def test_generated_links_in_emails
40 40 Setting.default_language = 'en'
41 41 Setting.host_name = 'mydomain.foo'
42 42 Setting.protocol = 'https'
43 43
44 44 journal = Journal.find(3)
45 45 assert Mailer.issue_edit(journal).deliver
46 46
47 47 mail = last_email
48 48 assert_not_nil mail
49 49
50 50 assert_select_email do
51 51 # link to the main ticket
52 52 assert_select 'a[href=?]',
53 53 'https://mydomain.foo/issues/2#change-3',
54 54 :text => 'Feature request #2: Add ingredients categories'
55 55 # link to a referenced ticket
56 56 assert_select 'a[href=?][title=?]',
57 57 'https://mydomain.foo/issues/1',
58 58 'Can&#x27;t print recipes (New)',
59 59 :text => '#1'
60 60 # link to a changeset
61 61 assert_select 'a[href=?][title=?]',
62 62 'https://mydomain.foo/projects/ecookbook/repository/revisions/2',
63 63 'This commit fixes #1, #2 and references #1 &amp; #3',
64 64 :text => 'r2'
65 65 # link to a description diff
66 66 assert_select 'a[href=?][title=?]',
67 67 'https://mydomain.foo/journals/diff/3?detail_id=4',
68 68 'View differences',
69 69 :text => 'diff'
70 70 # link to an attachment
71 71 assert_select 'a[href=?]',
72 72 'https://mydomain.foo/attachments/download/4/source.rb',
73 73 :text => 'source.rb'
74 74 end
75 75 end
76 76
77 77 def test_generated_links_with_prefix
78 78 Setting.default_language = 'en'
79 79 relative_url_root = Redmine::Utils.relative_url_root
80 80 Setting.host_name = 'mydomain.foo/rdm'
81 81 Setting.protocol = 'http'
82 82
83 83 journal = Journal.find(3)
84 84 assert Mailer.issue_edit(journal).deliver
85 85
86 86 mail = last_email
87 87 assert_not_nil mail
88 88
89 89 assert_select_email do
90 90 # link to the main ticket
91 91 assert_select 'a[href=?]',
92 92 'http://mydomain.foo/rdm/issues/2#change-3',
93 93 :text => 'Feature request #2: Add ingredients categories'
94 94 # link to a referenced ticket
95 95 assert_select 'a[href=?][title=?]',
96 96 'http://mydomain.foo/rdm/issues/1',
97 97 'Can&#x27;t print recipes (New)',
98 98 :text => '#1'
99 99 # link to a changeset
100 100 assert_select 'a[href=?][title=?]',
101 101 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
102 102 'This commit fixes #1, #2 and references #1 &amp; #3',
103 103 :text => 'r2'
104 104 # link to a description diff
105 105 assert_select 'a[href=?][title=?]',
106 106 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
107 107 'View differences',
108 108 :text => 'diff'
109 109 # link to an attachment
110 110 assert_select 'a[href=?]',
111 111 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
112 112 :text => 'source.rb'
113 113 end
114 114 end
115 115
116 116 def test_generated_links_with_prefix_and_no_relative_url_root
117 117 Setting.default_language = 'en'
118 118 relative_url_root = Redmine::Utils.relative_url_root
119 119 Setting.host_name = 'mydomain.foo/rdm'
120 120 Setting.protocol = 'http'
121 121 Redmine::Utils.relative_url_root = nil
122 122
123 123 journal = Journal.find(3)
124 124 assert Mailer.issue_edit(journal).deliver
125 125
126 126 mail = last_email
127 127 assert_not_nil mail
128 128
129 129 assert_select_email do
130 130 # link to the main ticket
131 131 assert_select 'a[href=?]',
132 132 'http://mydomain.foo/rdm/issues/2#change-3',
133 133 :text => 'Feature request #2: Add ingredients categories'
134 134 # link to a referenced ticket
135 135 assert_select 'a[href=?][title=?]',
136 136 'http://mydomain.foo/rdm/issues/1',
137 137 'Can&#x27;t print recipes (New)',
138 138 :text => '#1'
139 139 # link to a changeset
140 140 assert_select 'a[href=?][title=?]',
141 141 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2',
142 142 'This commit fixes #1, #2 and references #1 &amp; #3',
143 143 :text => 'r2'
144 144 # link to a description diff
145 145 assert_select 'a[href=?][title=?]',
146 146 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4',
147 147 'View differences',
148 148 :text => 'diff'
149 149 # link to an attachment
150 150 assert_select 'a[href=?]',
151 151 'http://mydomain.foo/rdm/attachments/download/4/source.rb',
152 152 :text => 'source.rb'
153 153 end
154 154 ensure
155 155 # restore it
156 156 Redmine::Utils.relative_url_root = relative_url_root
157 157 end
158 158
159 159 def test_email_headers
160 160 issue = Issue.find(1)
161 161 Mailer.issue_add(issue).deliver
162 162 mail = last_email
163 163 assert_not_nil mail
164 164 assert_equal 'OOF', mail.header['X-Auto-Response-Suppress'].to_s
165 165 assert_equal 'auto-generated', mail.header['Auto-Submitted'].to_s
166 166 assert_equal '<redmine.example.net>', mail.header['List-Id'].to_s
167 167 end
168 168
169 169 def test_email_headers_should_include_sender
170 170 issue = Issue.find(1)
171 171 Mailer.issue_add(issue).deliver
172 172 mail = last_email
173 173 assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
174 174 end
175 175
176 176 def test_plain_text_mail
177 177 Setting.plain_text_mail = 1
178 178 journal = Journal.find(2)
179 179 Mailer.issue_edit(journal).deliver
180 180 mail = last_email
181 181 assert_equal "text/plain; charset=UTF-8", mail.content_type
182 182 assert_equal 0, mail.parts.size
183 183 assert !mail.encoded.include?('href')
184 184 end
185 185
186 186 def test_html_mail
187 187 Setting.plain_text_mail = 0
188 188 journal = Journal.find(2)
189 189 Mailer.issue_edit(journal).deliver
190 190 mail = last_email
191 191 assert_equal 2, mail.parts.size
192 192 assert mail.encoded.include?('href')
193 193 end
194 194
195 195 def test_from_header
196 196 with_settings :mail_from => 'redmine@example.net' do
197 197 Mailer.test_email(User.find(1)).deliver
198 198 end
199 199 mail = last_email
200 200 assert_equal 'redmine@example.net', mail.from_addrs.first
201 201 end
202 202
203 203 def test_from_header_with_phrase
204 204 with_settings :mail_from => 'Redmine app <redmine@example.net>' do
205 205 Mailer.test_email(User.find(1)).deliver
206 206 end
207 207 mail = last_email
208 208 assert_equal 'redmine@example.net', mail.from_addrs.first
209 209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s
210 210 end
211 211
212 212 def test_should_not_send_email_without_recipient
213 213 news = News.first
214 214 user = news.author
215 215 # Remove members except news author
216 216 news.project.memberships.each {|m| m.destroy unless m.user == user}
217 217
218 218 user.pref.no_self_notified = false
219 219 user.pref.save
220 220 User.current = user
221 221 Mailer.news_added(news.reload).deliver
222 222 assert_equal 1, last_email.bcc.size
223 223
224 224 # nobody to notify
225 225 user.pref.no_self_notified = true
226 226 user.pref.save
227 227 User.current = user
228 228 ActionMailer::Base.deliveries.clear
229 229 Mailer.news_added(news.reload).deliver
230 230 assert ActionMailer::Base.deliveries.empty?
231 231 end
232 232
233 233 def test_issue_add_message_id
234 234 issue = Issue.find(1)
235 235 Mailer.issue_add(issue).deliver
236 236 mail = last_email
237 237 assert_equal Mailer.message_id_for(issue), mail.message_id
238 238 assert_nil mail.references
239 239 end
240 240
241 241 def test_issue_edit_message_id
242 242 journal = Journal.find(1)
243 243 Mailer.issue_edit(journal).deliver
244 244 mail = last_email
245 245 assert_equal Mailer.message_id_for(journal), mail.message_id
246 246 assert_include Mailer.message_id_for(journal.issue), mail.references
247 247 assert_select_email do
248 248 # link to the update
249 249 assert_select "a[href=?]",
250 250 "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}"
251 251 end
252 252 end
253 253
254 254 def test_message_posted_message_id
255 255 message = Message.find(1)
256 256 Mailer.message_posted(message).deliver
257 257 mail = last_email
258 258 assert_equal Mailer.message_id_for(message), mail.message_id
259 259 assert_nil mail.references
260 260 assert_select_email do
261 261 # link to the message
262 262 assert_select "a[href=?]",
263 263 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}",
264 264 :text => message.subject
265 265 end
266 266 end
267 267
268 268 def test_reply_posted_message_id
269 269 message = Message.find(3)
270 270 Mailer.message_posted(message).deliver
271 271 mail = last_email
272 272 assert_equal Mailer.message_id_for(message), mail.message_id
273 273 assert_include Mailer.message_id_for(message.parent), mail.references
274 274 assert_select_email do
275 275 # link to the reply
276 276 assert_select "a[href=?]",
277 277 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}",
278 278 :text => message.subject
279 279 end
280 280 end
281 281
282 282 test "#issue_add should notify project members" do
283 283 issue = Issue.find(1)
284 284 assert Mailer.issue_add(issue).deliver
285 285 assert last_email.bcc.include?('dlopper@somenet.foo')
286 286 end
287 287
288 288 test "#issue_add should not notify project members that are not allow to view the issue" do
289 289 issue = Issue.find(1)
290 290 Role.find(2).remove_permission!(:view_issues)
291 291 assert Mailer.issue_add(issue).deliver
292 292 assert !last_email.bcc.include?('dlopper@somenet.foo')
293 293 end
294 294
295 295 test "#issue_add should notify issue watchers" do
296 296 issue = Issue.find(1)
297 297 user = User.find(9)
298 298 # minimal email notification options
299 299 user.pref.no_self_notified = '1'
300 300 user.pref.save
301 301 user.mail_notification = false
302 302 user.save
303 303
304 304 Watcher.create!(:watchable => issue, :user => user)
305 305 assert Mailer.issue_add(issue).deliver
306 306 assert last_email.bcc.include?(user.mail)
307 307 end
308 308
309 309 test "#issue_add should not notify watchers not allowed to view the issue" do
310 310 issue = Issue.find(1)
311 311 user = User.find(9)
312 312 Watcher.create!(:watchable => issue, :user => user)
313 313 Role.non_member.remove_permission!(:view_issues)
314 314 assert Mailer.issue_add(issue).deliver
315 315 assert !last_email.bcc.include?(user.mail)
316 316 end
317 317
318 318 # test mailer methods for each language
319 319 def test_issue_add
320 320 issue = Issue.find(1)
321 321 valid_languages.each do |lang|
322 322 Setting.default_language = lang.to_s
323 323 assert Mailer.issue_add(issue).deliver
324 324 end
325 325 end
326 326
327 327 def test_issue_edit
328 328 journal = Journal.find(1)
329 329 valid_languages.each do |lang|
330 330 Setting.default_language = lang.to_s
331 331 assert Mailer.issue_edit(journal).deliver
332 332 end
333 333 end
334 334
335 335 def test_issue_edit_should_send_private_notes_to_users_with_permission_only
336 336 journal = Journal.find(1)
337 337 journal.private_notes = true
338 338 journal.save!
339 339
340 340 Role.find(2).add_permission! :view_private_notes
341 341 Mailer.issue_edit(journal).deliver
342 342 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
343 343
344 344 Role.find(2).remove_permission! :view_private_notes
345 345 Mailer.issue_edit(journal).deliver
346 346 assert_equal %w(jsmith@somenet.foo), ActionMailer::Base.deliveries.last.bcc.sort
347 347 end
348 348
349 349 def test_issue_edit_should_send_private_notes_to_watchers_with_permission_only
350 350 Issue.find(1).set_watcher(User.find_by_login('someone'))
351 351 journal = Journal.find(1)
352 352 journal.private_notes = true
353 353 journal.save!
354 354
355 355 Role.non_member.add_permission! :view_private_notes
356 356 Mailer.issue_edit(journal).deliver
357 357 assert_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
358 358
359 359 Role.non_member.remove_permission! :view_private_notes
360 360 Mailer.issue_edit(journal).deliver
361 361 assert_not_include 'someone@foo.bar', ActionMailer::Base.deliveries.last.bcc.sort
362 362 end
363 363
364 def test_issue_edit_should_mark_private_notes
365 journal = Journal.find(2)
366 journal.private_notes = true
367 journal.save!
368
369 with_settings :default_language => 'en' do
370 Mailer.issue_edit(journal).deliver
371 end
372 assert_mail_body_match '(Private notes)', last_email
373 end
374
364 375 def test_document_added
365 376 document = Document.find(1)
366 377 valid_languages.each do |lang|
367 378 Setting.default_language = lang.to_s
368 379 assert Mailer.document_added(document).deliver
369 380 end
370 381 end
371 382
372 383 def test_attachments_added
373 384 attachements = [ Attachment.find_by_container_type('Document') ]
374 385 valid_languages.each do |lang|
375 386 Setting.default_language = lang.to_s
376 387 assert Mailer.attachments_added(attachements).deliver
377 388 end
378 389 end
379 390
380 391 def test_version_file_added
381 392 attachements = [ Attachment.find_by_container_type('Version') ]
382 393 assert Mailer.attachments_added(attachements).deliver
383 394 assert_not_nil last_email.bcc
384 395 assert last_email.bcc.any?
385 396 assert_select_email do
386 397 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
387 398 end
388 399 end
389 400
390 401 def test_project_file_added
391 402 attachements = [ Attachment.find_by_container_type('Project') ]
392 403 assert Mailer.attachments_added(attachements).deliver
393 404 assert_not_nil last_email.bcc
394 405 assert last_email.bcc.any?
395 406 assert_select_email do
396 407 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files"
397 408 end
398 409 end
399 410
400 411 def test_news_added
401 412 news = News.first
402 413 valid_languages.each do |lang|
403 414 Setting.default_language = lang.to_s
404 415 assert Mailer.news_added(news).deliver
405 416 end
406 417 end
407 418
408 419 def test_news_comment_added
409 420 comment = Comment.find(2)
410 421 valid_languages.each do |lang|
411 422 Setting.default_language = lang.to_s
412 423 assert Mailer.news_comment_added(comment).deliver
413 424 end
414 425 end
415 426
416 427 def test_message_posted
417 428 message = Message.first
418 429 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
419 430 recipients = recipients.compact.uniq
420 431 valid_languages.each do |lang|
421 432 Setting.default_language = lang.to_s
422 433 assert Mailer.message_posted(message).deliver
423 434 end
424 435 end
425 436
426 437 def test_wiki_content_added
427 438 content = WikiContent.find(1)
428 439 valid_languages.each do |lang|
429 440 Setting.default_language = lang.to_s
430 441 assert_difference 'ActionMailer::Base.deliveries.size' do
431 442 assert Mailer.wiki_content_added(content).deliver
432 443 assert_select_email do
433 444 assert_select 'a[href=?]',
434 445 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
435 446 :text => 'CookBook documentation'
436 447 end
437 448 end
438 449 end
439 450 end
440 451
441 452 def test_wiki_content_updated
442 453 content = WikiContent.find(1)
443 454 valid_languages.each do |lang|
444 455 Setting.default_language = lang.to_s
445 456 assert_difference 'ActionMailer::Base.deliveries.size' do
446 457 assert Mailer.wiki_content_updated(content).deliver
447 458 assert_select_email do
448 459 assert_select 'a[href=?]',
449 460 'http://mydomain.foo/projects/ecookbook/wiki/CookBook_documentation',
450 461 :text => 'CookBook documentation'
451 462 end
452 463 end
453 464 end
454 465 end
455 466
456 467 def test_account_information
457 468 user = User.find(2)
458 469 valid_languages.each do |lang|
459 470 user.update_attribute :language, lang.to_s
460 471 user.reload
461 472 assert Mailer.account_information(user, 'pAsswORd').deliver
462 473 end
463 474 end
464 475
465 476 def test_lost_password
466 477 token = Token.find(2)
467 478 valid_languages.each do |lang|
468 479 token.user.update_attribute :language, lang.to_s
469 480 token.reload
470 481 assert Mailer.lost_password(token).deliver
471 482 end
472 483 end
473 484
474 485 def test_register
475 486 token = Token.find(1)
476 487 Setting.host_name = 'redmine.foo'
477 488 Setting.protocol = 'https'
478 489
479 490 valid_languages.each do |lang|
480 491 token.user.update_attribute :language, lang.to_s
481 492 token.reload
482 493 ActionMailer::Base.deliveries.clear
483 494 assert Mailer.register(token).deliver
484 495 mail = last_email
485 496 assert_select_email do
486 497 assert_select "a[href=?]",
487 498 "https://redmine.foo/account/activate?token=#{token.value}",
488 499 :text => "https://redmine.foo/account/activate?token=#{token.value}"
489 500 end
490 501 end
491 502 end
492 503
493 504 def test_test
494 505 user = User.find(1)
495 506 valid_languages.each do |lang|
496 507 user.update_attribute :language, lang.to_s
497 508 assert Mailer.test_email(user).deliver
498 509 end
499 510 end
500 511
501 512 def test_reminders
502 513 Mailer.reminders(:days => 42)
503 514 assert_equal 1, ActionMailer::Base.deliveries.size
504 515 mail = last_email
505 516 assert mail.bcc.include?('dlopper@somenet.foo')
506 517 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
507 518 assert_equal '1 issue(s) due in the next 42 days', mail.subject
508 519 end
509 520
510 521 def test_reminders_should_not_include_closed_issues
511 522 with_settings :default_language => 'en' do
512 523 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5,
513 524 :subject => 'Closed issue', :assigned_to_id => 3,
514 525 :due_date => 5.days.from_now,
515 526 :author_id => 2)
516 527 ActionMailer::Base.deliveries.clear
517 528
518 529 Mailer.reminders(:days => 42)
519 530 assert_equal 1, ActionMailer::Base.deliveries.size
520 531 mail = last_email
521 532 assert mail.bcc.include?('dlopper@somenet.foo')
522 533 assert_mail_body_no_match 'Closed issue', mail
523 534 end
524 535 end
525 536
526 537 def test_reminders_for_users
527 538 Mailer.reminders(:days => 42, :users => ['5'])
528 539 assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper
529 540 Mailer.reminders(:days => 42, :users => ['3'])
530 541 assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper
531 542 mail = last_email
532 543 assert mail.bcc.include?('dlopper@somenet.foo')
533 544 assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail
534 545 end
535 546
536 547 def test_reminder_should_include_issues_assigned_to_groups
537 548 with_settings :default_language => 'en' do
538 549 group = Group.generate!
539 550 group.users << User.find(2)
540 551 group.users << User.find(3)
541 552
542 553 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
543 554 :subject => 'Assigned to group', :assigned_to => group,
544 555 :due_date => 5.days.from_now,
545 556 :author_id => 2)
546 557 ActionMailer::Base.deliveries.clear
547 558
548 559 Mailer.reminders(:days => 7)
549 560 assert_equal 2, ActionMailer::Base.deliveries.size
550 561 assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort
551 562 ActionMailer::Base.deliveries.each do |mail|
552 563 assert_mail_body_match 'Assigned to group', mail
553 564 end
554 565 end
555 566 end
556 567
557 568 def test_mailer_should_not_change_locale
558 569 Setting.default_language = 'en'
559 570 # Set current language to italian
560 571 set_language_if_valid 'it'
561 572 # Send an email to a french user
562 573 user = User.find(1)
563 574 user.language = 'fr'
564 575 Mailer.account_activated(user).deliver
565 576 mail = last_email
566 577 assert_mail_body_match 'Votre compte', mail
567 578
568 579 assert_equal :it, current_language
569 580 end
570 581
571 582 def test_with_deliveries_off
572 583 Mailer.with_deliveries false do
573 584 Mailer.test_email(User.find(1)).deliver
574 585 end
575 586 assert ActionMailer::Base.deliveries.empty?
576 587 # should restore perform_deliveries
577 588 assert ActionMailer::Base.perform_deliveries
578 589 end
579 590
580 591 def test_layout_should_include_the_emails_header
581 592 with_settings :emails_header => "*Header content*" do
582 593 with_settings :plain_text_mail => 0 do
583 594 assert Mailer.test_email(User.find(1)).deliver
584 595 assert_select_email do
585 596 assert_select ".header" do
586 597 assert_select "strong", :text => "Header content"
587 598 end
588 599 end
589 600 end
590 601 with_settings :plain_text_mail => 1 do
591 602 assert Mailer.test_email(User.find(1)).deliver
592 603 mail = last_email
593 604 assert_not_nil mail
594 605 assert_include "*Header content*", mail.body.decoded
595 606 end
596 607 end
597 608 end
598 609
599 610 def test_layout_should_not_include_empty_emails_header
600 611 with_settings :emails_header => "", :plain_text_mail => 0 do
601 612 assert Mailer.test_email(User.find(1)).deliver
602 613 assert_select_email do
603 614 assert_select ".header", false
604 615 end
605 616 end
606 617 end
607 618
608 619 def test_layout_should_include_the_emails_footer
609 620 with_settings :emails_footer => "*Footer content*" do
610 621 with_settings :plain_text_mail => 0 do
611 622 assert Mailer.test_email(User.find(1)).deliver
612 623 assert_select_email do
613 624 assert_select ".footer" do
614 625 assert_select "strong", :text => "Footer content"
615 626 end
616 627 end
617 628 end
618 629 with_settings :plain_text_mail => 1 do
619 630 assert Mailer.test_email(User.find(1)).deliver
620 631 mail = last_email
621 632 assert_not_nil mail
622 633 assert_include "\n-- \n", mail.body.decoded
623 634 assert_include "*Footer content*", mail.body.decoded
624 635 end
625 636 end
626 637 end
627 638
628 639 def test_layout_should_not_include_empty_emails_footer
629 640 with_settings :emails_footer => "" do
630 641 with_settings :plain_text_mail => 0 do
631 642 assert Mailer.test_email(User.find(1)).deliver
632 643 assert_select_email do
633 644 assert_select ".footer", false
634 645 end
635 646 end
636 647 with_settings :plain_text_mail => 1 do
637 648 assert Mailer.test_email(User.find(1)).deliver
638 649 mail = last_email
639 650 assert_not_nil mail
640 651 assert_not_include "\n-- \n", mail.body.decoded
641 652 end
642 653 end
643 654 end
644 655
645 656 def test_should_escape_html_templates_only
646 657 Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'Subject with a <tag>')
647 658 mail = last_email
648 659 assert_equal 2, mail.parts.size
649 660 assert_include '<tag>', text_part.body.encoded
650 661 assert_include '&lt;tag&gt;', html_part.body.encoded
651 662 end
652 663
653 664 private
654 665
655 666 def last_email
656 667 mail = ActionMailer::Base.deliveries.last
657 668 assert_not_nil mail
658 669 mail
659 670 end
660 671
661 672 def text_part
662 673 last_email.parts.detect {|part| part.content_type.include?('text/plain')}
663 674 end
664 675
665 676 def html_part
666 677 last_email.parts.detect {|part| part.content_type.include?('text/html')}
667 678 end
668 679 end
General Comments 0
You need to be logged in to leave comments. Login now