mail_service_test.rb 38.3 KB
Newer Older
1
# encoding: utf-8
2
require 'abstract_unit'
D
Initial  
David Heinemeier Hansson 已提交
3

4
class FunkyPathMailer < ActionMailer::Base
5
  self.view_paths = "#{File.dirname(__FILE__)}/../fixtures/path.with.dots"
6

7 8
  def multipart_with_template_path_with_dots(recipient)
    recipients recipient
9
    subject    "This path has dots"
10
    from       "Chad Fowler <chad@chadfowler.com>"
11
    attachment :content_type => "text/plain",
12
      :data => "dots dots dots..."
13 14 15
  end
end

D
Initial  
David Heinemeier Hansson 已提交
16 17
class TestMailer < ActionMailer::Base
  def signed_up(recipient)
18 19 20 21 22
    recipients recipient
    subject    "[Signed up] Welcome #{recipient}"
    from       "system@loudthinking.com"

    @recipient = recipient
D
Initial  
David Heinemeier Hansson 已提交
23 24 25
  end

  def cancelled_account(recipient)
26 27 28 29
    recipients recipient
    subject    "[Cancelled] Goodbye #{recipient}"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)
30
    body       "Goodbye, Mr. #{recipient}"
D
Initial  
David Heinemeier Hansson 已提交
31
  end
32

33 34 35
  def from_with_name
    from       "System <system@loudthinking.com>"
    recipients "root@loudthinking.com"
36
    body       "Nothing to see here."
37 38 39 40 41
  end

  def from_without_name
    from       "system@loudthinking.com"
    recipients "root@loudthinking.com"
42
    body       "Nothing to see here."
43 44
  end

45
  def cc_bcc(recipient)
46 47 48 49 50 51
    recipients recipient
    subject    "testing bcc/cc"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)
    cc         "nobody@loudthinking.com"
    bcc        "root@loudthinking.com"
52

53
    body       "Nothing to see here."
54 55
  end

56 57 58 59 60 61
  def different_reply_to(recipient)
    recipients recipient
    subject    "testing reply_to"
    from       "system@loudthinking.com"
    sent_on    Time.local(2008, 5, 23)
    reply_to   "atraver@gmail.com"
62

63
    body       "Nothing to see here."
64 65
  end

66
  def iso_charset(recipient)
67 68 69 70 71 72 73 74
    recipients recipient
    subject    "testing isø charsets"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)
    cc         "nobody@loudthinking.com"
    bcc        "root@loudthinking.com"
    charset    "iso-8859-1"

75
    body       "Nothing to see here."
76 77 78
  end

  def unencoded_subject(recipient)
79 80 81 82 83 84 85
    recipients recipient
    subject    "testing unencoded subject"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)
    cc         "nobody@loudthinking.com"
    bcc        "root@loudthinking.com"

86
    body       "Nothing to see here."
87 88 89
  end

  def extended_headers(recipient)
90 91 92 93 94 95 96 97
    recipients recipient
    subject    "testing extended headers"
    from       "Grytøyr <stian1@example.net>"
    sent_on    Time.local(2004, 12, 12)
    cc         "Grytøyr <stian2@example.net>"
    bcc        "Grytøyr <stian3@example.net>"
    charset    "iso-8859-1"

98
    body       "Nothing to see here."
99 100
  end

D
David Heinemeier Hansson 已提交
101
  def utf8_body(recipient)
102 103 104 105 106 107 108
    recipients recipient
    subject    "testing utf-8 body"
    from       "Foo áëô îü <extended@example.net>"
    sent_on    Time.local(2004, 12, 12)
    cc         "Foo áëô îü <extended@example.net>"
    bcc        "Foo áëô îü <extended@example.net>"
    charset    "utf-8"
109
    
110
    body       "åœö blah"
D
David Heinemeier Hansson 已提交
111
  end
112

113 114 115 116 117 118 119 120 121
  def multipart_with_mime_version(recipient)
    recipients   recipient
    subject      "multipart with mime_version"
    from         "test@example.com"
    sent_on      Time.local(2004, 12, 12)
    mime_version "1.1"
    content_type "multipart/alternative"

    part "text/plain" do |p|
122
      p.body = render(:text => "blah")
123 124 125
    end

    part "text/html" do |p|
126
      p.body = render(:inline => "<%= content_tag(:b, 'blah') %>")
127 128 129
    end
  end

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
  def multipart_with_utf8_subject(recipient)
    recipients   recipient
    subject      "Foo áëô îü"
    from         "test@example.com"
    charset      "utf-8"

    part "text/plain" do |p|
      p.body = "blah"
    end

    part "text/html" do |p|
      p.body = "<b>blah</b>"
    end
  end

145 146 147 148 149 150
  def explicitly_multipart_example(recipient, ct=nil)
    recipients   recipient
    subject      "multipart example"
    from         "test@example.com"
    sent_on      Time.local(2004, 12, 12)
    content_type ct if ct
151 152 153 154 155 156

    part "text/html" do |p|
      p.charset = "iso-8859-1"
      p.body = "blah"
    end

M
Mikel Lindsaar 已提交
157
    attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"),
158
      :data => "123456789"
159

160
    body       "plain text default"
161 162
  end

163
  def implicitly_multipart_example(recipient, cs = nil, order = nil)
164 165 166 167 168 169 170
    recipients recipient
    subject    "multipart example"
    from       "test@example.com"
    sent_on    Time.local(2004, 12, 12)

    @charset = cs if cs
    @recipient = recipient
171
    @implicit_parts_order = order if order
172 173
  end

174 175 176 177 178
  def implicitly_multipart_with_utf8
    recipients "no.one@nowhere.test"
    subject    "Foo áëô îü"
    from       "some.one@somewhere.test"
    template   "implicitly_multipart_example"
179 180

    @recipient = "no.one@nowhere.test"
181 182
  end

183 184 185 186 187
  def html_mail(recipient)
    recipients   recipient
    subject      "html mail"
    from         "test@example.com"
    content_type "text/html"
188

189
    body       "<em>Emphasize</em> <strong>this</strong>"
190 191
  end

192 193
  def html_mail_with_underscores(recipient)
    subject      "html mail with underscores"
194
    body       %{<a href="http://google.com" target="_blank">_Google</a>}
195 196
  end

197 198 199 200 201 202 203
  def custom_template(recipient)
    recipients recipient
    subject    "[Signed up] Welcome #{recipient}"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)
    template   "signed_up"

204
    @recipient = recipient
205 206
  end

207 208 209 210 211 212
  def custom_templating_extension(recipient)
    recipients recipient
    subject    "[Signed up] Welcome #{recipient}"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)

213
    @recipient = recipient
214 215
  end

216 217 218 219
  def various_newlines(recipient)
    recipients   recipient
    subject      "various newlines"
    from         "test@example.com"
220

221
    body       "line #1\nline #2\rline #3\r\nline #4\r\r" +
222
                    "line #5\n\nline#6\r\n\r\nline #7"
223 224
  end

225 226 227 228 229
  def various_newlines_multipart(recipient)
    recipients   recipient
    subject      "various newlines multipart"
    from         "test@example.com"
    content_type "multipart/alternative"
230

231 232 233 234
    part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
    part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"
  end

235 236 237 238 239
  def nested_multipart(recipient)
    recipients   recipient
    subject      "nested multipart"
    from         "test@example.com"
    content_type "multipart/mixed"
240

241
    part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p|
242 243 244
      p.part :content_type => "text/plain", :body => "test text\nline #2"
      p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
    end
245

246
    attachment :content_type => "application/octet-stream", :filename => "test.txt", :data => "test abcdefghijklmnopqstuvwxyz"
247
  end
248

249 250 251 252 253
  def nested_multipart_with_body(recipient)
    recipients   recipient
    subject      "nested multipart with body"
    from         "test@example.com"
    content_type "multipart/mixed"
254

255 256 257 258 259
    part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
      p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
    end
  end

260 261 262 263 264
  def attachment_with_custom_header(recipient)
    recipients   recipient
    subject      "custom header in attachment"
    from         "test@example.com"
    content_type "multipart/related"
265
    part         :content_type => "text/html", :body => 'yo'
266
    attachment   :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", 'Content-ID' => '<test@test.com>'
267
  end
268 269 270 271 272

  def unnamed_attachment(recipient)
    recipients   recipient
    subject      "nested multipart"
    from         "test@example.com"
273
    content_type "multipart/mixed"
274
    part :content_type => "text/plain", :body => "hullo"
275
    attachment :content_type => "application/octet-stream", :data => "test abcdefghijklmnopqstuvwxyz"
276
  end
277 278 279 280 281 282 283

  def headers_with_nonalpha_chars(recipient)
    recipients   recipient
    subject      "nonalpha chars"
    from         "One: Two <test@example.com>"
    cc           "Three: Four <test@example.com>"
    bcc          "Five: Six <test@example.com>"
284
    body       "testing"
285
  end
M
Mikel Lindsaar 已提交
286

287 288 289 290 291
  def custom_content_type_attributes
    recipients   "no.one@nowhere.test"
    subject      "custom content types"
    from         "some.one@somewhere.test"
    content_type "text/plain; format=flowed"
292
    body       "testing"
293 294
  end

295 296 297 298
  def return_path
    recipients   "no.one@nowhere.test"
    subject      "return path test"
    from         "some.one@somewhere.test"
299
    headers["return-path"] = "another@somewhere.test"
300
    body       "testing"
301 302
  end

303 304 305
  def subject_with_i18n(recipient)
    recipients recipient
    from       "system@loudthinking.com"
306
    body       "testing"
307 308
  end

309
  class << self
310 311 312 313 314 315
    attr_accessor :received_body
  end

  def receive(mail)
    self.class.received_body = mail.body
  end
D
Initial  
David Heinemeier Hansson 已提交
316 317 318
end

class ActionMailerTest < Test::Unit::TestCase
319
  include ActionMailer::Quoting
320

321
  def encode( text, charset="utf-8" )
322
    quoted_printable( text, charset )
323 324 325
  end

  def new_mail( charset="utf-8" )
326
    mail = Mail.new
327
    mail.mime_version = "1.0"
328
    if charset
329
      mail.content_type ["text", "plain", { "charset" => charset }]
330 331 332 333
    end
    mail
  end

334
  # Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3
D
Initial  
David Heinemeier Hansson 已提交
335
  def setup
336
    set_delivery_method :test
D
Initial  
David Heinemeier Hansson 已提交
337
    ActionMailer::Base.perform_deliveries = true
338
    ActionMailer::Base.raise_delivery_errors = true
339
    ActionMailer::Base.deliveries.clear
D
Initial  
David Heinemeier Hansson 已提交
340

341
    @original_logger = TestMailer.logger
D
Initial  
David Heinemeier Hansson 已提交
342
    @recipient = 'test@localhost'
E
Evan Phoenix 已提交
343 344

    TestMailer.delivery_method = :test
D
Initial  
David Heinemeier Hansson 已提交
345
  end
346

347 348
  def teardown
    TestMailer.logger = @original_logger
349
    restore_delivery_method
350
  end
D
Initial  
David Heinemeier Hansson 已提交
351

352 353
  def test_nested_parts
    created = nil
354
    assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)}
355 356 357
    assert_equal 2, created.parts.size
    assert_equal 2, created.parts.first.parts.size

358 359
    assert_equal "multipart/mixed", created.mime_type
    assert_equal "multipart/alternative", created.parts[0].mime_type
360
    assert_equal "bar", created.parts[0].header['foo'].to_s
361
    assert_nil created.parts[0].charset
362 363 364
    assert_equal "text/plain", created.parts[0].parts[0].mime_type
    assert_equal "text/html", created.parts[0].parts[1].mime_type
    assert_equal "application/octet-stream", created.parts[1].mime_type
365
    
366 367
  end

368 369
  def test_nested_parts_with_body
    created = nil
370 371
    TestMailer.nested_multipart_with_body(@recipient)
    assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)}
372

373 374 375
    assert_equal 1,created.parts.size
    assert_equal 2,created.parts.first.parts.size

376 377 378
    assert_equal "multipart/mixed", created.mime_type
    assert_equal "multipart/alternative", created.parts.first.mime_type
    assert_equal "text/plain", created.parts.first.parts.first.mime_type
379
    assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
380
    assert_equal "text/html", created.parts.first.parts.second.mime_type
381
    assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
382 383
  end

384 385
  def test_attachment_with_custom_header
    created = nil
386
    assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) }
387
    assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
388 389
  end

D
Initial  
David Heinemeier Hansson 已提交
390
  def test_signed_up
391 392
    TestMailer.delivery_method = :test

393 394
    Time.stubs(:now => Time.now)

395
    expected = new_mail
D
Initial  
David Heinemeier Hansson 已提交
396
    expected.to      = @recipient
397
    expected.subject = "[Signed up] Welcome #{@recipient}"
D
Initial  
David Heinemeier Hansson 已提交
398 399
    expected.body    = "Hello there, \n\nMr. #{@recipient}"
    expected.from    = "system@loudthinking.com"
400
    expected.date    = Time.now
D
Initial  
David Heinemeier Hansson 已提交
401 402

    created = nil
403
    assert_nothing_raised { created = TestMailer.signed_up(@recipient) }
D
Initial  
David Heinemeier Hansson 已提交
404
    assert_not_nil created
M
Mikel Lindsaar 已提交
405 406 407 408
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'

D
Initial  
David Heinemeier Hansson 已提交
409 410
    assert_equal expected.encoded, created.encoded

411
    assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
M
Mikel Lindsaar 已提交
412 413 414 415 416 417 418 419

    delivered = ActionMailer::Base.deliveries.first
    assert_not_nil delivered

    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'

    assert_equal expected.encoded, delivered.encoded
D
Initial  
David Heinemeier Hansson 已提交
420
  end
421

422 423 424 425 426 427 428 429 430
  def test_custom_template
    expected = new_mail
    expected.to      = @recipient
    expected.subject = "[Signed up] Welcome #{@recipient}"
    expected.body    = "Hello there, \n\nMr. #{@recipient}"
    expected.from    = "system@loudthinking.com"
    expected.date    = Time.local(2004, 12, 12)

    created = nil
431
    assert_nothing_raised { created = TestMailer.custom_template(@recipient) }
432
    assert_not_nil created
M
Mikel Lindsaar 已提交
433 434
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
435 436
    assert_equal expected.encoded, created.encoded
  end
437 438

  def test_custom_templating_extension
439 440
    assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered"

441 442 443 444 445 446 447
    # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
    expected = new_mail
    expected.to      = @recipient
    expected.subject = "[Signed up] Welcome #{@recipient}"
    expected.body    = "Hello there, \n\nMr. #{@recipient}"
    expected.from    = "system@loudthinking.com"
    expected.date    = Time.local(2004, 12, 12)
448

449 450
    # Now that the template is registered, there should be one part. The text/plain part.
    created = nil
451
    assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) }
452 453
    assert_not_nil created
    assert_equal 2, created.parts.length
454 455
    assert_equal 'text/plain', created.parts[0].mime_type
    assert_equal 'text/html', created.parts[1].mime_type
456 457
  end

D
Initial  
David Heinemeier Hansson 已提交
458
  def test_cancelled_account
M
Mikel Lindsaar 已提交
459
    expected = new_mail
D
Initial  
David Heinemeier Hansson 已提交
460
    expected.to      = @recipient
461
    expected.subject = "[Cancelled] Goodbye #{@recipient}"
D
Initial  
David Heinemeier Hansson 已提交
462 463 464 465 466
    expected.body    = "Goodbye, Mr. #{@recipient}"
    expected.from    = "system@loudthinking.com"
    expected.date    = Time.local(2004, 12, 12)

    created = nil
467
    assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) }
D
Initial  
David Heinemeier Hansson 已提交
468
    assert_not_nil created
469 470
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
D
Initial  
David Heinemeier Hansson 已提交
471 472
    assert_equal expected.encoded, created.encoded

473
    assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
D
Initial  
David Heinemeier Hansson 已提交
474
    assert_not_nil ActionMailer::Base.deliveries.first
475 476 477 478 479
    delivered = ActionMailer::Base.deliveries.first
    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'

    assert_equal expected.encoded, delivered.encoded
D
Initial  
David Heinemeier Hansson 已提交
480
  end
481

482
  def test_cc_bcc
M
Mikel Lindsaar 已提交
483
    expected = new_mail
484
    expected.to      = @recipient
485
    expected.subject = "testing bcc/cc"
486 487 488 489 490 491 492 493
    expected.body    = "Nothing to see here."
    expected.from    = "system@loudthinking.com"
    expected.cc      = "nobody@loudthinking.com"
    expected.bcc     = "root@loudthinking.com"
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
494
      created = TestMailer.cc_bcc @recipient
495 496
    end
    assert_not_nil created
497 498
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
499 500 501
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
502
      TestMailer.cc_bcc(@recipient).deliver
503 504 505
    end

    assert_not_nil ActionMailer::Base.deliveries.first
506 507 508 509 510
    delivered = ActionMailer::Base.deliveries.first
    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'
    
    assert_equal expected.encoded, delivered.encoded
511 512
  end

513
  def test_from_without_name_for_smtp
514
    TestMailer.delivery_method = :smtp
515
    TestMailer.from_without_name.deliver
516 517 518 519 520

    mail = MockSMTP.deliveries.first
    assert_not_nil mail
    mail, from, to = mail

521
    assert_equal 'system@loudthinking.com', from.to_s
522 523 524
  end

  def test_from_with_name_for_smtp
525
    TestMailer.delivery_method = :smtp
526
    TestMailer.from_with_name.deliver
527 528 529 530 531

    mail = MockSMTP.deliveries.first
    assert_not_nil mail
    mail, from, to = mail

532
    assert_equal 'system@loudthinking.com', from
533 534
  end

535
  def test_reply_to
536 537
    TestMailer.delivery_method = :test

538 539 540 541 542 543 544 545 546 547 548
    expected = new_mail

    expected.to       = @recipient
    expected.subject  = "testing reply_to"
    expected.body     = "Nothing to see here."
    expected.from     = "system@loudthinking.com"
    expected.reply_to = "atraver@gmail.com"
    expected.date     = Time.local 2008, 5, 23

    created = nil
    assert_nothing_raised do
549
      created = TestMailer.different_reply_to @recipient
550 551
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
552 553 554 555
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
    
556 557 558
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
559
      TestMailer.different_reply_to(@recipient).deliver
560 561
    end

M
Mikel Lindsaar 已提交
562 563 564 565 566 567 568
    delivered = ActionMailer::Base.deliveries.first
    assert_not_nil delivered
    
    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'
    
    assert_equal expected.encoded, delivered.encoded
569 570
  end

571
  def test_iso_charset
572 573
    TestMailer.delivery_method = :test

574 575
    expected = new_mail( "iso-8859-1" )
    expected.to      = @recipient
576
    expected.subject = encode "testing isø charsets", "iso-8859-1"
577 578 579 580 581 582 583 584
    expected.body    = "Nothing to see here."
    expected.from    = "system@loudthinking.com"
    expected.cc      = "nobody@loudthinking.com"
    expected.bcc     = "root@loudthinking.com"
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
585
      created = TestMailer.iso_charset @recipient
586 587
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
588 589 590
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
M
Mikel Lindsaar 已提交
591

592 593 594
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
595
      TestMailer.iso_charset(@recipient).deliver
596 597
    end

M
Mikel Lindsaar 已提交
598 599 600 601 602 603 604
    delivered = ActionMailer::Base.deliveries.first
    assert_not_nil delivered

    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'
    
    assert_equal expected.encoded, delivered.encoded
605 606 607
  end

  def test_unencoded_subject
608
    TestMailer.delivery_method = :test
609 610 611 612 613 614 615 616 617 618 619
    expected = new_mail
    expected.to      = @recipient
    expected.subject = "testing unencoded subject"
    expected.body    = "Nothing to see here."
    expected.from    = "system@loudthinking.com"
    expected.cc      = "nobody@loudthinking.com"
    expected.bcc     = "root@loudthinking.com"
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
620
      created = TestMailer.unencoded_subject @recipient
621 622
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
623 624 625 626

    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'

627 628 629
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
630
      TestMailer.unencoded_subject(@recipient).deliver
631 632
    end

M
Mikel Lindsaar 已提交
633 634 635 636 637 638 639
    delivered = ActionMailer::Base.deliveries.first
    assert_not_nil delivered

    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'
    
    assert_equal expected.encoded, delivered.encoded
640 641
  end

D
Initial  
David Heinemeier Hansson 已提交
642 643 644
  def test_deliveries_array
    assert_not_nil ActionMailer::Base.deliveries
    assert_equal 0, ActionMailer::Base.deliveries.size
645
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
646 647 648 649 650 651
    assert_equal 1, ActionMailer::Base.deliveries.size
    assert_not_nil ActionMailer::Base.deliveries.first
  end

  def test_perform_deliveries_flag
    ActionMailer::Base.perform_deliveries = false
652
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
653 654
    assert_equal 0, ActionMailer::Base.deliveries.size
    ActionMailer::Base.perform_deliveries = true
655
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
656 657
    assert_equal 1, ActionMailer::Base.deliveries.size
  end
658

659 660
  def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
    ActionMailer::Base.raise_delivery_errors = false
661
    Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception)
662
    assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
663
  end
664 665

  def test_performs_delivery_via_sendmail
666
    IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+')
667
    TestMailer.delivery_method = :sendmail
668
    TestMailer.signed_up(@recipient).deliver
669 670
  end

671
  def test_unquote_quoted_printable_subject
672 673 674 675 676
    msg = <<EOF
From: me@example.com
Subject: =?utf-8?Q?testing_testing_=D6=A4?=
Content-Type: text/plain; charset=iso-8859-1

677
The body
678
EOF
679
    mail = Mail.new(msg)
680 681
    assert_equal "testing testing \326\244", mail.subject
    assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
682 683 684 685 686 687 688 689 690 691
  end

  def test_unquote_7bit_subject
    msg = <<EOF
From: me@example.com
Subject: this == working?
Content-Type: text/plain; charset=iso-8859-1

The body
EOF
692
    mail = Mail.new(msg)
693 694
    assert_equal "this == working?", mail.subject
    assert_equal "Subject: this == working?\r\n", mail[:subject].encoded
695 696 697 698 699 700 701 702 703 704 705
  end

  def test_unquote_7bit_body
    msg = <<EOF
From: me@example.com
Subject: subject
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

The=3Dbody
EOF
706
    mail = Mail.new(msg)
707
    assert_equal "The=3Dbody", mail.body.to_s.strip
708
    assert_equal "The=3Dbody", mail.body.encoded.strip
709 710 711 712 713 714 715 716 717 718 719
  end

  def test_unquote_quoted_printable_body
    msg = <<EOF
From: me@example.com
Subject: subject
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

The=3Dbody
EOF
720
    mail = Mail.new(msg)
721
    assert_equal "The=body", mail.body.to_s.strip
722
    assert_equal "The=3Dbody", mail.body.encoded.strip
723 724 725 726 727 728 729 730 731 732 733
  end

  def test_unquote_base64_body
    msg = <<EOF
From: me@example.com
Subject: subject
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: base64

VGhlIGJvZHk=
EOF
734
    mail = Mail.new(msg)
735
    assert_equal "The body", mail.body.to_s.strip
736
    assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip
737 738
  end

739 740 741 742
  def test_extended_headers
    @recipient = "Grytøyr <test@localhost>"

    expected = new_mail "iso-8859-1"
743
    expected.to      = quote_address_if_necessary @recipient, "iso-8859-1"
744 745
    expected.subject = "testing extended headers"
    expected.body    = "Nothing to see here."
746 747 748
    expected.from    = quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1"
    expected.cc      = quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1"
    expected.bcc     = quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1"
749 750 751 752
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
753
      created = TestMailer.extended_headers @recipient
754 755 756
    end

    assert_not_nil created
M
Mikel Lindsaar 已提交
757 758 759
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'

760 761 762
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
763
      TestMailer.extended_headers(@recipient).deliver
764 765
    end

M
Mikel Lindsaar 已提交
766 767 768 769 770 771 772
    delivered = ActionMailer::Base.deliveries.first
    assert_not_nil delivered
    
    expected.message_id = '<123@456>'
    delivered.message_id = '<123@456>'
    
    assert_equal expected.encoded, delivered.encoded
773
  end
774

D
David Heinemeier Hansson 已提交
775
  def test_utf8_body_is_not_quoted
776
    @recipient = "Foo áëô îü <extended@example.net>"
D
David Heinemeier Hansson 已提交
777
    expected = new_mail "utf-8"
778
    expected.to      = quote_address_if_necessary @recipient, "utf-8"
D
David Heinemeier Hansson 已提交
779
    expected.subject = "testing utf-8 body"
780
    expected.body    = "åœö blah"
781 782 783
    expected.from    = quote_address_if_necessary @recipient, "utf-8"
    expected.cc      = quote_address_if_necessary @recipient, "utf-8"
    expected.bcc     = quote_address_if_necessary @recipient, "utf-8"
D
David Heinemeier Hansson 已提交
784 785
    expected.date    = Time.local 2004, 12, 12

786
    created = TestMailer.utf8_body @recipient
787
    assert_match(/åœö blah/, created.decoded)
788 789 790
  end

  def test_multiple_utf8_recipients
791
    @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
792
    expected = new_mail "utf-8"
793
    expected.to      = quote_address_if_necessary @recipient, "utf-8"
794
    expected.subject = "testing utf-8 body"
795
    expected.body    = "åœö blah"
796 797 798
    expected.from    = quote_address_if_necessary @recipient.first, "utf-8"
    expected.cc      = quote_address_if_necessary @recipient, "utf-8"
    expected.bcc     = quote_address_if_necessary @recipient, "utf-8"
799 800
    expected.date    = Time.local 2004, 12, 12

801
    created = TestMailer.utf8_body @recipient
802
    assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
803
    assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
804
  end
805

806
  def test_receive_decodes_base64_encoded_mail
807
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email")
808
    TestMailer.receive(fixture)
809
    assert_match(/Jamis/, TestMailer.received_body.to_s)
810 811
  end

812
  def test_receive_attachments
813
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email2")
814
    mail = Mail.new(fixture)
815
    attachment = mail.attachments.last
816
    assert_equal "smime.p7s", attachment.filename
817
    assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
818 819 820
  end

  def test_decode_attachment_without_charset
821
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email3")
822
    mail = Mail.new(fixture)
823 824 825 826
    attachment = mail.attachments.last
    assert_equal 1026, attachment.read.length
  end

827
  def test_attachment_using_content_location
828
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email12")
829
    mail = Mail.new(fixture)
830
    assert_equal 1, mail.attachments.length
831
    assert_equal "Photo25.jpg", mail.attachments.first.filename
832 833
  end

834
  def test_attachment_with_text_type
835
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email13")
836
    mail = Mail.new(fixture)
837
    assert mail.has_attachments?
838
    assert_equal 1, mail.attachments.length
839
    assert_equal "hello.rb", mail.attachments.first.filename
840 841
  end

842
  def test_decode_part_without_content_type
843
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email4")
844
    mail = Mail.new(fixture)
845 846 847
    assert_nothing_raised { mail.body }
  end

848
  def test_decode_message_without_content_type
849
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email5")
850
    mail = Mail.new(fixture)
851 852 853
    assert_nothing_raised { mail.body }
  end

854
  def test_decode_message_with_incorrect_charset
855
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email6")
856
    mail = Mail.new(fixture)
857 858 859
    assert_nothing_raised { mail.body }
  end

860
  def test_multipart_with_mime_version
861
    mail = TestMailer.multipart_with_mime_version(@recipient)
862
    assert_equal "1.1", mail.mime_version
863
  end
864

865
  def test_multipart_with_utf8_subject
866
    mail = TestMailer.multipart_with_utf8_subject(@recipient)
867 868
    assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
  end
869

870
  def test_implicitly_multipart_with_utf8
871
    mail = TestMailer.implicitly_multipart_with_utf8
872 873 874
    assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
  end

875
  def test_explicitly_multipart_messages
876
    mail = TestMailer.explicitly_multipart_example(@recipient)
877
    assert_equal 3, mail.parts.length
878 879
    assert_equal 'multipart/mixed', mail.mime_type
    assert_equal "text/plain", mail.parts[0].mime_type
880

881
    assert_equal "text/html", mail.parts[1].mime_type
M
Mikel Lindsaar 已提交
882
    assert_equal "iso-8859-1", mail.parts[1].charset
883

884
    assert_equal "image/jpeg", mail.parts[2].mime_type
885
    
886 887 888
    assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type
    assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename
    assert_equal "foo.jpg", mail.parts[2][:content_type].filename
889
    assert_nil mail.parts[2].charset
890 891
  end

892
  def test_explicitly_multipart_with_content_type
893
    mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
894
    assert_equal 3, mail.parts.length
895
    assert_equal "multipart/alternative", mail.mime_type
896 897 898
  end

  def test_explicitly_multipart_with_invalid_content_type
899
    mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
900
    assert_equal 3, mail.parts.length
901
    assert_equal 'multipart/mixed', mail.mime_type
902 903
  end

904
  def test_implicitly_multipart_messages
905 906
    assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"

907
    mail = TestMailer.implicitly_multipart_example(@recipient)
J
Jeremy Kemper 已提交
908
    assert_equal 3, mail.parts.length
909
    assert_equal "1.0", mail.mime_version.to_s
910 911
    assert_equal "multipart/alternative", mail.mime_type
    assert_equal "text/plain", mail.parts[0].mime_type
M
Mikel Lindsaar 已提交
912
    assert_equal "utf-8", mail.parts[0].charset
913
    assert_equal "text/html", mail.parts[1].mime_type
M
Mikel Lindsaar 已提交
914
    assert_equal "utf-8", mail.parts[1].charset
915
    assert_equal "application/x-yaml", mail.parts[2].mime_type
M
Mikel Lindsaar 已提交
916
    assert_equal "utf-8", mail.parts[2].charset
917 918 919
  end

  def test_implicitly_multipart_messages_with_custom_order
920 921
    assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"

922
    mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
J
Jeremy Kemper 已提交
923
    assert_equal 3, mail.parts.length
924 925 926
    assert_equal "application/x-yaml", mail.parts[0].mime_type
    assert_equal "text/plain", mail.parts[1].mime_type
    assert_equal "text/html", mail.parts[2].mime_type
927 928
  end

929
  def test_implicitly_multipart_messages_with_charset
930
    mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
931

932
    assert_equal "multipart/alternative", mail.header['content-type'].content_type
933

934 935 936
    assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset]
    assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset]
    assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset]
937 938
  end

939
  def test_html_mail
940
    mail = TestMailer.html_mail(@recipient)
941
    assert_equal "text/html", mail.mime_type
942 943
  end

944
  def test_html_mail_with_underscores
945
    mail = TestMailer.html_mail_with_underscores(@recipient)
946
    assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
947 948
  end

949
  def test_various_newlines
950
    mail = TestMailer.various_newlines(@recipient)
951
    assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
952
                 "line #5\n\nline#6\n\nline #7", mail.body.to_s)
953 954
  end

955
  def test_various_newlines_multipart
956
    mail = TestMailer.various_newlines_multipart(@recipient)
957 958
    assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s
    assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s
M
Mikel Lindsaar 已提交
959 960
    assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded
    assert_equal "<p>line #1</p>\r\n<p>line #2</p>\r\n<p>line #3</p>\r\n<p>line #4</p>\r\n\r\n", mail.parts[1].body.encoded
961
  end
962

963
  def test_headers_removed_on_smtp_delivery
964
    TestMailer.delivery_method = :smtp
965
    TestMailer.cc_bcc(@recipient).deliver
966 967 968 969 970 971 972
    assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
    assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
    assert MockSMTP.deliveries[0][2].include?(@recipient)
    assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
    assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
    assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
  end
973

974
   def test_file_delivery_should_create_a_file
975 976
     TestMailer.delivery_method = :file
     tmp_location = TestMailer.file_settings[:location]
977

978
     result = TestMailer.cc_bcc(@recipient).deliver
979 980 981 982 983
     assert File.exists?(tmp_location)
     assert File.directory?(tmp_location)
     assert File.exists?(File.join(tmp_location, @recipient))
     assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com'))
     assert File.exists?(File.join(tmp_location, 'root@loudthinking.com'))
984 985
   end

986
  def test_recursive_multipart_processing
987
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email7")
988
    mail = Mail.new(fixture)
989 990
    assert_equal(2, mail.parts.length)
    assert_equal(4, mail.parts.first.parts.length)
991
    assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
992
    assert_equal("test.rb", mail.parts.first.parts.second.filename)
993
    assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format])
994
    assert_equal('smime.p7s', mail.parts.second.filename)
995
  end
996 997

  def test_decode_encoded_attachment_filename
998
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8")
999
    mail = Mail.new(fixture)
1000
    attachment = mail.attachments.last
1001 1002

    expected = "01 Quien Te Dij\212at. Pitbull.mp3"
1003 1004
    
    if expected.respond_to?(:force_encoding)
1005
      result = attachment.filename.dup
1006 1007 1008 1009
      expected.force_encoding(Encoding::ASCII_8BIT)
      result.force_encoding(Encoding::ASCII_8BIT)
      assert_equal expected, result
    else
1010
      assert_equal expected, attachment.filename
1011
    end
1012
  end
1013

1014
  def test_decode_message_with_unknown_charset
1015
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10")
1016
    mail = Mail.new(fixture)
1017 1018
    assert_nothing_raised { mail.body }
  end
1019

1020
  def test_empty_header_values_omitted
1021
    result = TestMailer.unnamed_attachment(@recipient).encoded
1022 1023
    assert_match %r{Content-Type: application/octet-stream}, result
    assert_match %r{Content-Disposition: attachment}, result
1024
  end
1025 1026

  def test_headers_with_nonalpha_chars
1027
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
1028 1029 1030
    assert !mail.from_addrs.empty?
    assert !mail.cc_addrs.empty?
    assert !mail.bcc_addrs.empty?
1031 1032 1033
    assert_match(/:/, mail[:from].decoded)
    assert_match(/:/, mail[:cc].decoded)
    assert_match(/:/, mail[:bcc].decoded)
1034
  end
1035

1036
  def test_with_mail_object_deliver
1037
    TestMailer.delivery_method = :test
1038 1039
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
    assert_nothing_raised { mail.deliver }
1040 1041
    assert_equal 1, TestMailer.deliveries.length
  end
1042 1043

  def test_multipart_with_template_path_with_dots
1044
    mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
1045
    assert_equal 2, mail.parts.length
1046
    assert "text/plain", mail.parts[1].mime_type
1047
    assert "utf-8", mail.parts[1].charset
1048
  end
1049 1050

  def test_custom_content_type_attributes
1051
    mail = TestMailer.custom_content_type_attributes
1052 1053
    assert_match %r{format=flowed}, mail.content_type
    assert_match %r{charset=utf-8}, mail.content_type
1054
  end
1055 1056

  def test_return_path_with_create
1057
    mail = TestMailer.return_path
J
José Valim 已提交
1058
    assert_equal "another@somewhere.test", mail.return_path
1059 1060
  end

1061
  def test_return_path_with_deliver
1062
    TestMailer.delivery_method = :smtp
1063
    TestMailer.return_path.deliver
1064
    assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
1065
    assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
1066
  end
1067

1068
  def test_starttls_is_enabled_if_supported
1069
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1070 1071
    MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
    MockSMTP.any_instance.expects(:enable_starttls_auto)
1072
    TestMailer.delivery_method = :smtp
1073
    TestMailer.signed_up(@recipient).deliver
1074 1075 1076
  end

  def test_starttls_is_disabled_if_not_supported
1077
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1078 1079
    MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
    MockSMTP.any_instance.expects(:enable_starttls_auto).never
1080
    TestMailer.delivery_method = :smtp
1081
    TestMailer.signed_up(@recipient).deliver
1082
  end
1083 1084

  def test_starttls_is_not_enabled
1085
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => false)
1086
    MockSMTP.any_instance.expects(:respond_to?).never
1087 1088
    TestMailer.delivery_method = :smtp
    TestMailer.signed_up(@recipient).deliver
1089
  ensure
1090
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1091
  end
D
Initial  
David Heinemeier Hansson 已提交
1092
end
1093

1094
class InheritableTemplateRootTest < ActiveSupport::TestCase
1095
  def test_attr
1096
    expected = File.expand_path("#{File.dirname(__FILE__)}/../fixtures/path.with.dots")
1097
    assert_equal expected, FunkyPathMailer.template_root.to_s
1098 1099

    sub = Class.new(FunkyPathMailer)
1100 1101 1102
    assert_deprecated do
      sub.template_root = 'test/path'
    end
1103

1104
    assert_equal File.expand_path('test/path'), sub.template_root.to_s
1105
    assert_equal expected, FunkyPathMailer.template_root.to_s
1106 1107
  end
end
1108

1109
class MethodNamingTest < ActiveSupport::TestCase
1110 1111
  class TestMailer < ActionMailer::Base
    def send
1112
      body       'foo'
1113 1114 1115 1116
    end
  end

  def setup
1117
    set_delivery_method :test
1118
    ActionMailer::Base.perform_deliveries = true
1119
    ActionMailer::Base.deliveries.clear
1120 1121
  end

1122 1123 1124 1125
  def teardown
    restore_delivery_method
  end

1126 1127 1128
  def test_send_method
    assert_nothing_raised do
      assert_emails 1 do
1129 1130 1131
        assert_deprecated do
          TestMailer.deliver_send
        end
1132 1133 1134 1135
      end
    end
  end
end
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
class RespondToTest < Test::Unit::TestCase
  class RespondToMailer < ActionMailer::Base; end

  def setup
    set_delivery_method :test
  end

  def teardown
    restore_delivery_method
  end

  def test_should_respond_to_new
    assert RespondToMailer.respond_to?(:new)
  end

  def test_should_respond_to_create_with_template_suffix
    assert RespondToMailer.respond_to?(:create_any_old_template)
  end

  def test_should_respond_to_deliver_with_template_suffix
    assert RespondToMailer.respond_to?(:deliver_any_old_template)
  end

  def test_should_not_respond_to_new_with_template_suffix
    assert !RespondToMailer.respond_to?(:new_any_old_template)
  end

  def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
    assert !RespondToMailer.respond_to?(:createany_old_template)
  end

  def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
    assert !RespondToMailer.respond_to?(:deliverany_old_template)
  end

  def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
    assert !RespondToMailer.respond_to?(:create_Any_old_template)
  end

  def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
    assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
  end

  def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
    assert !RespondToMailer.respond_to?(:create_1_template)
  end

  def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
    assert !RespondToMailer.respond_to?(:deliver_1_template)
  end
1186

1187 1188 1189 1190
  def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
    assert !RespondToMailer.respond_to?(:foo_deliver_template)
  end

1191
  def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
1192
    error = assert_raise NoMethodError do
1193 1194 1195
      RespondToMailer.not_a_method
    end

E
Evan Phoenix 已提交
1196
    assert_match(/method.*not_a_method/, error.message)
1197
  end
E
Evan Phoenix 已提交
1198
end