mail_service_test.rb 38.4 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 30 31
    recipients recipient
    subject    "[Cancelled] Goodbye #{recipient}"
    from       "system@loudthinking.com"
    sent_on    Time.local(2004, 12, 12)

    render :text => "Goodbye, Mr. #{recipient}"
D
Initial  
David Heinemeier Hansson 已提交
32
  end
33

34 35 36
  def from_with_name
    from       "System <system@loudthinking.com>"
    recipients "root@loudthinking.com"
37
    render :text => "Nothing to see here."
38 39 40 41 42
  end

  def from_without_name
    from       "system@loudthinking.com"
    recipients "root@loudthinking.com"
43
    render :text => "Nothing to see here."
44 45
  end

46
  def cc_bcc(recipient)
47 48 49 50 51 52
    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"
53 54

    render :text => "Nothing to see here."
55 56
  end

57 58 59 60 61 62
  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"
63 64

    render :text => "Nothing to see here."
65 66
  end

67
  def iso_charset(recipient)
68 69 70 71 72 73 74 75 76
    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"

    render :text => "Nothing to see here."
77 78 79
  end

  def unencoded_subject(recipient)
80 81 82 83 84 85 86 87
    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"

    render :text => "Nothing to see here."
88 89 90
  end

  def extended_headers(recipient)
91 92 93 94 95 96 97 98 99
    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"

    render :text => "Nothing to see here."
100 101
  end

D
David Heinemeier Hansson 已提交
102
  def utf8_body(recipient)
103 104 105 106 107 108 109
    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"
110
    
111
    render :text => "åœö blah"
D
David Heinemeier Hansson 已提交
112
  end
113

114 115 116 117 118 119 120 121 122
  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|
123
      p.body = render(:text => "blah")
124 125 126
    end

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

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  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

146 147 148 149 150 151
  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
152 153 154 155 156 157

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

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

    render :text => "plain text default"
162 163
  end

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

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

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

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

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

    render :text => "<em>Emphasize</em> <strong>this</strong>"
191 192
  end

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

198 199 200 201 202 203 204
  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"

205
    @recipient = recipient
206 207
  end

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

214
    @recipient = recipient
215 216
  end

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

    render :text => "line #1\nline #2\rline #3\r\nline #4\r\r" +
                    "line #5\n\nline#6\r\n\r\nline #7"
224 225
  end

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

232 233 234 235
    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

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

242
    part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p|
243 244 245
      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
246

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

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

256 257 258 259 260
    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

261 262 263 264 265
  def attachment_with_custom_header(recipient)
    recipients   recipient
    subject      "custom header in attachment"
    from         "test@example.com"
    content_type "multipart/related"
266
    part         :content_type => "text/html", :body => 'yo'
267
    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>'
268
  end
269 270 271 272 273

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

  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>"
285
    render :text => "testing"
286
  end
M
Mikel Lindsaar 已提交
287

288 289 290 291 292
  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"
293
    render :text => "testing"
294 295
  end

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

304 305 306 307 308 309
  def subject_with_i18n(recipient)
    recipients recipient
    from       "system@loudthinking.com"
    render :text => "testing"
  end

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

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

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

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

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

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

342
    @original_logger = TestMailer.logger
D
Initial  
David Heinemeier Hansson 已提交
343 344
    @recipient = 'test@localhost'
  end
345

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

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

357 358
    assert_equal "multipart/mixed", created.mime_type
    assert_equal "multipart/alternative", created.parts[0].mime_type
359
    assert_equal "bar", created.parts[0].header['foo'].to_s
360
    assert_nil created.parts[0].charset
361 362 363
    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
364
    
365 366
  end

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

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

375 376 377
    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
378
    assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
379
    assert_equal "text/html", created.parts.first.parts.second.mime_type
380
    assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
381 382
  end

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

D
Initial  
David Heinemeier Hansson 已提交
389
  def test_signed_up
390 391
    Time.stubs(:now => Time.now)

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

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

D
Initial  
David Heinemeier Hansson 已提交
406 407
    assert_equal expected.encoded, created.encoded

408
    assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
M
Mikel Lindsaar 已提交
409 410 411 412 413 414 415 416

    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 已提交
417
  end
418

419 420 421 422 423 424 425 426 427
  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
428
    assert_nothing_raised { created = TestMailer.custom_template(@recipient) }
429
    assert_not_nil created
M
Mikel Lindsaar 已提交
430 431
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
432 433
    assert_equal expected.encoded, created.encoded
  end
434 435

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

438 439 440 441 442 443 444
    # 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)
445

446 447
    # Stub the render method so no alternative renderers need be present.
    ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
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 536 537 538 539 540 541 542 543 544 545 546
  def test_reply_to
    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
547
      created = TestMailer.different_reply_to @recipient
548 549
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
550 551 552 553
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
    
554 555 556
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
557
      TestMailer.different_reply_to(@recipient).deliver
558 559
    end

M
Mikel Lindsaar 已提交
560 561 562 563 564 565 566
    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
567 568
  end

569 570 571
  def test_iso_charset
    expected = new_mail( "iso-8859-1" )
    expected.to      = @recipient
572
    expected.subject = encode "testing isø charsets", "iso-8859-1"
573 574 575 576 577 578 579 580
    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
581
      created = TestMailer.iso_charset @recipient
582 583
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
584 585 586
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
M
Mikel Lindsaar 已提交
587

588 589 590
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
591
      TestMailer.iso_charset(@recipient).deliver
592 593
    end

M
Mikel Lindsaar 已提交
594 595 596 597 598 599 600
    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
601 602 603 604 605 606 607 608 609 610 611 612 613 614
  end

  def test_unencoded_subject
    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
615
      created = TestMailer.unencoded_subject @recipient
616 617
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
618 619 620 621

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

622 623 624
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
625
      TestMailer.unencoded_subject(@recipient).deliver
626 627
    end

M
Mikel Lindsaar 已提交
628 629 630 631 632 633 634
    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
635 636
  end

D
Initial  
David Heinemeier Hansson 已提交
637 638 639
  def test_deliveries_array
    assert_not_nil ActionMailer::Base.deliveries
    assert_equal 0, ActionMailer::Base.deliveries.size
640
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
641 642 643 644 645 646
    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
647
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
648 649
    assert_equal 0, ActionMailer::Base.deliveries.size
    ActionMailer::Base.perform_deliveries = true
650
    TestMailer.signed_up(@recipient).deliver
D
Initial  
David Heinemeier Hansson 已提交
651 652
    assert_equal 1, ActionMailer::Base.deliveries.size
  end
653

654 655
  def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
    ActionMailer::Base.raise_delivery_errors = false
656
    Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception)
657
    assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
658
  end
659 660

  def test_performs_delivery_via_sendmail
661
    IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+')
662
    TestMailer.delivery_method = :sendmail
663
    TestMailer.signed_up(@recipient).deliver
664 665
  end

666
  def test_unquote_quoted_printable_subject
667 668 669 670 671
    msg = <<EOF
From: me@example.com
Subject: =?utf-8?Q?testing_testing_=D6=A4?=
Content-Type: text/plain; charset=iso-8859-1

672
The body
673
EOF
674
    mail = Mail.new(msg)
675 676
    assert_equal "testing testing \326\244", mail.subject
    assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
677 678 679 680 681 682 683 684 685 686
  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
687
    mail = Mail.new(msg)
688 689
    assert_equal "this == working?", mail.subject
    assert_equal "Subject: this == working?\r\n", mail[:subject].encoded
690 691 692 693 694 695 696 697 698 699 700
  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
701
    mail = Mail.new(msg)
702
    assert_equal "The=3Dbody", mail.body.to_s.strip
703
    assert_equal "The=3Dbody", mail.body.encoded.strip
704 705 706 707 708 709 710 711 712 713 714
  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
715
    mail = Mail.new(msg)
716
    assert_equal "The=body", mail.body.to_s.strip
717
    assert_equal "The=3Dbody", mail.body.encoded.strip
718 719 720 721 722 723 724 725 726 727 728
  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
729
    mail = Mail.new(msg)
730
    assert_equal "The body", mail.body.to_s.strip
731
    assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip
732 733
  end

734 735 736 737
  def test_extended_headers
    @recipient = "Grytøyr <test@localhost>"

    expected = new_mail "iso-8859-1"
738
    expected.to      = quote_address_if_necessary @recipient, "iso-8859-1"
739 740
    expected.subject = "testing extended headers"
    expected.body    = "Nothing to see here."
741 742 743
    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"
744 745 746 747
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
748
      created = TestMailer.extended_headers @recipient
749 750 751
    end

    assert_not_nil created
M
Mikel Lindsaar 已提交
752 753 754
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'

755 756 757
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
758
      TestMailer.extended_headers(@recipient).deliver
759 760
    end

M
Mikel Lindsaar 已提交
761 762 763 764 765 766 767
    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
768
  end
769

D
David Heinemeier Hansson 已提交
770
  def test_utf8_body_is_not_quoted
771
    @recipient = "Foo áëô îü <extended@example.net>"
D
David Heinemeier Hansson 已提交
772
    expected = new_mail "utf-8"
773
    expected.to      = quote_address_if_necessary @recipient, "utf-8"
D
David Heinemeier Hansson 已提交
774
    expected.subject = "testing utf-8 body"
775
    expected.body    = "åœö blah"
776 777 778
    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 已提交
779 780
    expected.date    = Time.local 2004, 12, 12

781
    created = TestMailer.utf8_body @recipient
782
    assert_match(/åœö blah/, created.encoded)
783 784 785
  end

  def test_multiple_utf8_recipients
786
    @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
787
    expected = new_mail "utf-8"
788
    expected.to      = quote_address_if_necessary @recipient, "utf-8"
789
    expected.subject = "testing utf-8 body"
790
    expected.body    = "åœö blah"
791 792 793
    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"
794 795
    expected.date    = Time.local 2004, 12, 12

796
    created = TestMailer.utf8_body @recipient
797
    assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
798
    assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
799
  end
800

801
  def test_receive_decodes_base64_encoded_mail
802
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email")
803
    TestMailer.receive(fixture)
804
    assert_match(/Jamis/, TestMailer.received_body.to_s)
805 806
  end

807
  def test_receive_attachments
808
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email2")
809
    mail = Mail.new(fixture)
810
    attachment = mail.attachments.last
811
    assert_equal "smime.p7s", attachment.filename
812
    assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
813 814 815
  end

  def test_decode_attachment_without_charset
816
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email3")
817
    mail = Mail.new(fixture)
818 819 820 821
    attachment = mail.attachments.last
    assert_equal 1026, attachment.read.length
  end

822
  def test_attachment_using_content_location
823
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email12")
824
    mail = Mail.new(fixture)
825
    assert_equal 1, mail.attachments.length
826
    assert_equal "Photo25.jpg", mail.attachments.first.filename
827 828
  end

829
  def test_attachment_with_text_type
830
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email13")
831
    mail = Mail.new(fixture)
832
    assert mail.has_attachments?
833
    assert_equal 1, mail.attachments.length
834
    assert_equal "hello.rb", mail.attachments.first.filename
835 836
  end

837
  def test_decode_part_without_content_type
838
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email4")
839
    mail = Mail.new(fixture)
840 841 842
    assert_nothing_raised { mail.body }
  end

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

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

855
  def test_multipart_with_mime_version
856
    mail = TestMailer.multipart_with_mime_version(@recipient)
857
    assert_equal "1.1", mail.mime_version
858
  end
859

860
  def test_multipart_with_utf8_subject
861
    mail = TestMailer.multipart_with_utf8_subject(@recipient)
862 863
    assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
  end
864

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

870
  def test_explicitly_multipart_messages
871
    mail = TestMailer.explicitly_multipart_example(@recipient)
872
    assert_equal 3, mail.parts.length
873 874
    assert_equal 'multipart/mixed', mail.mime_type
    assert_equal "text/plain", mail.parts[0].mime_type
875

876
    assert_equal "text/html", mail.parts[1].mime_type
M
Mikel Lindsaar 已提交
877
    assert_equal "iso-8859-1", mail.parts[1].charset
878

879
    assert_equal "image/jpeg", mail.parts[2].mime_type
880
    
881 882 883
    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
884
    assert_nil mail.parts[2].charset
885 886
  end

887
  def test_explicitly_multipart_with_content_type
888
    mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
889
    assert_equal 3, mail.parts.length
890
    assert_equal "multipart/alternative", mail.mime_type
891 892 893
  end

  def test_explicitly_multipart_with_invalid_content_type
894
    mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
895
    assert_equal 3, mail.parts.length
896
    assert_equal 'multipart/mixed', mail.mime_type
897 898
  end

899
  def test_implicitly_multipart_messages
900 901
    assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"

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

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

917
    mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
J
Jeremy Kemper 已提交
918
    assert_equal 3, mail.parts.length
919 920 921
    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
922 923
  end

924
  def test_implicitly_multipart_messages_with_charset
925
    mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
926

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

929 930 931
    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]
932 933
  end

934
  def test_html_mail
935
    mail = TestMailer.html_mail(@recipient)
936
    assert_equal "text/html", mail.mime_type
937 938
  end

939
  def test_html_mail_with_underscores
940
    mail = TestMailer.html_mail_with_underscores(@recipient)
941
    assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
942 943
  end

944
  def test_various_newlines
945
    mail = TestMailer.various_newlines(@recipient)
946
    assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
947
                 "line #5\n\nline#6\n\nline #7", mail.body.to_s)
948 949
  end

950
  def test_various_newlines_multipart
951
    mail = TestMailer.various_newlines_multipart(@recipient)
952 953
    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 已提交
954 955
    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
956
  end
957

958
  def test_headers_removed_on_smtp_delivery
959
    TestMailer.delivery_method = :smtp
960
    TestMailer.cc_bcc(@recipient).deliver
961 962 963 964 965 966 967
    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
968

969
   def test_file_delivery_should_create_a_file
970 971
     TestMailer.delivery_method = :file
     tmp_location = TestMailer.file_settings[:location]
972

973
     result = TestMailer.cc_bcc(@recipient).deliver
974 975 976 977 978
     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'))
979 980
   end

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

  def test_decode_encoded_attachment_filename
993
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8")
994
    mail = Mail.new(fixture)
995
    attachment = mail.attachments.last
996 997

    expected = "01 Quien Te Dij\212at. Pitbull.mp3"
998 999
    
    if expected.respond_to?(:force_encoding)
1000
      result = attachment.filename.dup
1001 1002 1003 1004
      expected.force_encoding(Encoding::ASCII_8BIT)
      result.force_encoding(Encoding::ASCII_8BIT)
      assert_equal expected, result
    else
1005
      assert_equal expected, attachment.filename
1006
    end
1007
  end
1008

1009
  def test_decode_message_with_unknown_charset
1010
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10")
1011
    mail = Mail.new(fixture)
1012 1013
    assert_nothing_raised { mail.body }
  end
1014

1015
  def test_empty_header_values_omitted
1016
    result = TestMailer.unnamed_attachment(@recipient).encoded
1017
    assert_match %r{Content-Type: application/octet-stream;}, result
1018
    assert_match %r{Content-Disposition: attachment;}, result
1019
  end
1020 1021

  def test_headers_with_nonalpha_chars
1022
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
1023 1024 1025
    assert !mail.from_addrs.empty?
    assert !mail.cc_addrs.empty?
    assert !mail.bcc_addrs.empty?
1026 1027 1028
    assert_match(/:/, mail[:from].decoded)
    assert_match(/:/, mail[:cc].decoded)
    assert_match(/:/, mail[:bcc].decoded)
1029
  end
1030

1031 1032 1033
  def test_with_mail_object_deliver
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
    assert_nothing_raised { mail.deliver }
1034 1035
    assert_equal 1, TestMailer.deliveries.length
  end
1036 1037

  def test_multipart_with_template_path_with_dots
1038
    mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
1039
    assert_equal 2, mail.parts.length
1040
    assert "text/plain", mail.parts[1].mime_type
1041
    assert "utf-8", mail.parts[1].charset
1042
  end
1043 1044

  def test_custom_content_type_attributes
1045
    mail = TestMailer.custom_content_type_attributes
1046 1047
    assert_match %r{format=flowed}, mail.content_type
    assert_match %r{charset=utf-8}, mail.content_type
1048
  end
1049 1050

  def test_return_path_with_create
1051
    mail = TestMailer.return_path
J
José Valim 已提交
1052
    assert_equal "another@somewhere.test", mail.return_path
1053 1054
  end

1055
  def test_return_path_with_deliver
1056
    TestMailer.delivery_method = :smtp
1057
    TestMailer.return_path.deliver
1058
    assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
1059
    assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
1060
  end
1061

1062
  def test_starttls_is_enabled_if_supported
1063
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1064 1065
    MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
    MockSMTP.any_instance.expects(:enable_starttls_auto)
1066
    TestMailer.delivery_method = :smtp
1067
    TestMailer.signed_up(@recipient).deliver
1068 1069 1070
  end

  def test_starttls_is_disabled_if_not_supported
1071
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1072 1073
    MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
    MockSMTP.any_instance.expects(:enable_starttls_auto).never
1074
    TestMailer.delivery_method = :smtp
1075
    TestMailer.signed_up(@recipient).deliver
1076
  end
1077 1078

  def test_starttls_is_not_enabled
1079
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => false)
1080
    MockSMTP.any_instance.expects(:respond_to?).never
1081 1082
    TestMailer.delivery_method = :smtp
    TestMailer.signed_up(@recipient).deliver
1083
  ensure
1084
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1085
  end
D
Initial  
David Heinemeier Hansson 已提交
1086
end
1087

1088
class InheritableTemplateRootTest < ActiveSupport::TestCase
1089
  def test_attr
1090
    expected = File.expand_path("#{File.dirname(__FILE__)}/../fixtures/path.with.dots")
1091
    assert_equal expected, FunkyPathMailer.template_root.to_s
1092 1093

    sub = Class.new(FunkyPathMailer)
1094 1095 1096
    assert_deprecated do
      sub.template_root = 'test/path'
    end
1097

1098
    assert_equal File.expand_path('test/path'), sub.template_root.to_s
1099
    assert_equal expected, FunkyPathMailer.template_root.to_s
1100 1101
  end
end
1102

1103
class MethodNamingTest < ActiveSupport::TestCase
1104 1105
  class TestMailer < ActionMailer::Base
    def send
1106
      render :text => 'foo'
1107 1108 1109 1110
    end
  end

  def setup
1111
    set_delivery_method :test
1112
    ActionMailer::Base.perform_deliveries = true
1113
    ActionMailer::Base.deliveries.clear
1114 1115
  end

1116 1117 1118 1119
  def teardown
    restore_delivery_method
  end

1120 1121 1122
  def test_send_method
    assert_nothing_raised do
      assert_emails 1 do
1123 1124 1125
        assert_deprecated do
          TestMailer.deliver_send
        end
1126 1127 1128 1129
      end
    end
  end
end
1130 1131 1132 1133 1134 1135 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
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
1180

1181 1182 1183 1184
  def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
    assert !RespondToMailer.respond_to?(:foo_deliver_template)
  end

1185
  def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
1186
    error = assert_raise NoMethodError do
1187 1188 1189
      RespondToMailer.not_a_method
    end

1190
    assert_match(/undefined method.*not_a_method/, error.message)
1191
  end
1192
end