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
    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>"
108
    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
  def multipart_with_utf8_subject(recipient)
    recipients   recipient
    subject      "Foo áëô îü"
    from         "test@example.com"
134
    charset      "UTF-8"
135 136 137 138 139 140 141 142 143 144

    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

320 321
  def encode( text, charset="UTF-8" )
    Mail::Encodings.q_value_encode( text, charset )
322 323
  end

324
  def new_mail( charset="UTF-8" )
325
    mail = Mail.new
326
    mail.charset = charset
327
    mail.mime_version = "1.0"
328 329 330
    mail
  end

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

338
    @original_logger = TestMailer.logger
D
Initial  
David Heinemeier Hansson 已提交
339
    @recipient = 'test@localhost'
E
Evan Phoenix 已提交
340 341

    TestMailer.delivery_method = :test
D
Initial  
David Heinemeier Hansson 已提交
342
  end
343

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

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

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

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

370 371 372
    assert_equal 1,created.parts.size
    assert_equal 2,created.parts.first.parts.size

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

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

D
Initial  
David Heinemeier Hansson 已提交
387
  def test_signed_up
388 389
    TestMailer.delivery_method = :test

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

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

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

470
    assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
D
Initial  
David Heinemeier Hansson 已提交
471
    assert_not_nil ActionMailer::Base.deliveries.first
472 473 474 475 476
    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 已提交
477
  end
478

479
  def test_cc_bcc
M
Mikel Lindsaar 已提交
480
    expected = new_mail
481
    expected.to      = @recipient
482
    expected.subject = "testing bcc/cc"
483 484 485 486 487 488 489 490
    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
491
      created = TestMailer.cc_bcc @recipient
492 493
    end
    assert_not_nil created
494 495
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
496 497 498
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
499
      TestMailer.cc_bcc(@recipient).deliver
500 501 502
    end

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

510
  def test_from_without_name_for_smtp
511
    TestMailer.delivery_method = :smtp
512
    TestMailer.from_without_name.deliver
513 514 515 516 517

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

518
    assert_equal 'system@loudthinking.com', from.to_s
519 520 521
  end

  def test_from_with_name_for_smtp
522
    TestMailer.delivery_method = :smtp
523
    TestMailer.from_with_name.deliver
524 525 526 527 528

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

529
    assert_equal 'system@loudthinking.com', from
530 531
  end

532
  def test_reply_to
533 534
    TestMailer.delivery_method = :test

535 536 537 538 539 540 541 542 543 544 545
    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
546
      created = TestMailer.different_reply_to @recipient
547 548
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
549 550 551 552
    
    expected.message_id = '<123@456>'
    created.message_id = '<123@456>'
    
553 554 555
    assert_equal expected.encoded, created.encoded

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

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

568
  def test_iso_charset
569 570
    TestMailer.delivery_method = :test

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

589 590 591
    assert_equal expected.encoded, created.encoded

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

M
Mikel Lindsaar 已提交
595 596 597 598 599 600 601
    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
602 603 604
  end

  def test_unencoded_subject
605
    TestMailer.delivery_method = :test
606 607 608 609 610 611 612 613 614 615 616
    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
617
      created = TestMailer.unencoded_subject @recipient
618 619
    end
    assert_not_nil created
M
Mikel Lindsaar 已提交
620 621 622 623

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

624 625 626
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
627
      TestMailer.unencoded_subject(@recipient).deliver
628 629
    end

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

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

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

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

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

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

736 737 738 739
  def test_extended_headers
    @recipient = "Grytøyr <test@localhost>"

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

    created = nil
    assert_nothing_raised do
750
      created = TestMailer.extended_headers @recipient
751 752 753
    end

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

757 758 759
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
760
      TestMailer.extended_headers(@recipient).deliver
761 762
    end

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

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

783
    created = TestMailer.utf8_body @recipient
784
    assert_match(/åœö blah/, created.decoded)
785 786 787
  end

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

798
    created = TestMailer.utf8_body @recipient
799 800 801 802 803
    from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=')
    assert_match(/#{from_regexp}/m, created.encoded)

    to_regexp   = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>")
    assert_match(/#{to_regexp}/m, 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 869 870 871
    regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=')
    assert_match(/#{regex}/, mail.encoded)
    string = "Foo áëô îü"
    string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
    assert_match(string, mail.subject.decoded)
872
  end
873

874
  def test_implicitly_multipart_with_utf8
875
    mail = TestMailer.implicitly_multipart_with_utf8
876 877 878 879
    regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=')
    assert_match(/#{regex}/, mail.encoded)
    string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
    assert_match(string, mail.subject.decoded)
880 881
  end

882
  def test_explicitly_multipart_messages
883
    mail = TestMailer.explicitly_multipart_example(@recipient)
884
    assert_equal 3, mail.parts.length
885 886
    assert_equal 'multipart/mixed', mail.mime_type
    assert_equal "text/plain", mail.parts[0].mime_type
887

888
    assert_equal "text/html", mail.parts[1].mime_type
M
Mikel Lindsaar 已提交
889
    assert_equal "iso-8859-1", mail.parts[1].charset
890

891
    assert_equal "image/jpeg", mail.parts[2].mime_type
892
    
893 894 895
    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
896
    assert_nil mail.parts[2].charset
897 898
  end

899
  def test_explicitly_multipart_with_content_type
900
    mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
901
    assert_equal 3, mail.parts.length
902
    assert_equal "multipart/alternative", mail.mime_type
903 904 905
  end

  def test_explicitly_multipart_with_invalid_content_type
906
    mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
907
    assert_equal 3, mail.parts.length
908
    assert_equal 'multipart/mixed', mail.mime_type
909 910
  end

911
  def test_implicitly_multipart_messages
912 913
    assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"

914
    mail = TestMailer.implicitly_multipart_example(@recipient)
J
Jeremy Kemper 已提交
915
    assert_equal 3, mail.parts.length
916
    assert_equal "1.0", mail.mime_version.to_s
917 918
    assert_equal "multipart/alternative", mail.mime_type
    assert_equal "text/plain", mail.parts[0].mime_type
919
    assert_equal "UTF-8", mail.parts[0].charset
920
    assert_equal "text/html", mail.parts[1].mime_type
921
    assert_equal "UTF-8", mail.parts[1].charset
922
    assert_equal "application/x-yaml", mail.parts[2].mime_type
923
    assert_equal "UTF-8", mail.parts[2].charset
924 925 926
  end

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

929
    mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
J
Jeremy Kemper 已提交
930
    assert_equal 3, mail.parts.length
931 932 933
    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
934 935
  end

936
  def test_implicitly_multipart_messages_with_charset
937
    mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
938

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

941 942 943
    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]
944 945
  end

946
  def test_html_mail
947
    mail = TestMailer.html_mail(@recipient)
948
    assert_equal "text/html", mail.mime_type
949 950
  end

951
  def test_html_mail_with_underscores
952
    mail = TestMailer.html_mail_with_underscores(@recipient)
953
    assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
954 955
  end

956
  def test_various_newlines
957
    mail = TestMailer.various_newlines(@recipient)
958
    assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
959
                 "line #5\n\nline#6\n\nline #7", mail.body.to_s)
960 961
  end

962
  def test_various_newlines_multipart
963
    mail = TestMailer.various_newlines_multipart(@recipient)
964 965
    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 已提交
966 967
    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
968
  end
969

970
  def test_headers_removed_on_smtp_delivery
971
    TestMailer.delivery_method = :smtp
972
    TestMailer.cc_bcc(@recipient).deliver
973 974 975 976 977 978 979
    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
980

981
   def test_file_delivery_should_create_a_file
982 983
     TestMailer.delivery_method = :file
     tmp_location = TestMailer.file_settings[:location]
984

985
     result = TestMailer.cc_bcc(@recipient).deliver
986 987 988 989 990
     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'))
991 992
   end

993
  def test_recursive_multipart_processing
994
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email7")
995
    mail = Mail.new(fixture)
996 997
    assert_equal(2, mail.parts.length)
    assert_equal(4, mail.parts.first.parts.length)
998
    assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
999
    assert_equal("test.rb", mail.parts.first.parts.second.filename)
1000
    assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format])
1001
    assert_equal('smime.p7s', mail.parts.second.filename)
1002
  end
1003 1004

  def test_decode_encoded_attachment_filename
1005
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8")
1006
    mail = Mail.new(fixture)
1007
    attachment = mail.attachments.last
1008 1009

    expected = "01 Quien Te Dij\212at. Pitbull.mp3"
1010 1011
    
    if expected.respond_to?(:force_encoding)
1012
      result = attachment.filename.dup
1013 1014 1015 1016
      expected.force_encoding(Encoding::ASCII_8BIT)
      result.force_encoding(Encoding::ASCII_8BIT)
      assert_equal expected, result
    else
1017
      assert_equal expected, attachment.filename
1018
    end
1019
  end
1020

1021
  def test_decode_message_with_unknown_charset
1022
    fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10")
1023
    mail = Mail.new(fixture)
1024 1025
    assert_nothing_raised { mail.body }
  end
1026

1027
  def test_empty_header_values_omitted
1028
    result = TestMailer.unnamed_attachment(@recipient).encoded
1029 1030
    assert_match %r{Content-Type: application/octet-stream}, result
    assert_match %r{Content-Disposition: attachment}, result
1031
  end
1032 1033

  def test_headers_with_nonalpha_chars
1034
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
1035 1036 1037
    assert !mail.from_addrs.empty?
    assert !mail.cc_addrs.empty?
    assert !mail.bcc_addrs.empty?
1038 1039 1040
    assert_match(/:/, mail[:from].decoded)
    assert_match(/:/, mail[:cc].decoded)
    assert_match(/:/, mail[:bcc].decoded)
1041
  end
1042

1043
  def test_with_mail_object_deliver
1044
    TestMailer.delivery_method = :test
1045 1046
    mail = TestMailer.headers_with_nonalpha_chars(@recipient)
    assert_nothing_raised { mail.deliver }
1047 1048
    assert_equal 1, TestMailer.deliveries.length
  end
1049 1050

  def test_multipart_with_template_path_with_dots
1051
    mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
1052
    assert_equal 2, mail.parts.length
1053
    assert "text/plain", mail.parts[1].mime_type
1054
    assert "UTF-8", mail.parts[1].charset
1055
  end
1056 1057

  def test_custom_content_type_attributes
1058
    mail = TestMailer.custom_content_type_attributes
1059
    assert_match %r{format=flowed}, mail.content_type
1060
    assert_match %r{charset=UTF-8}, mail.content_type
1061
  end
1062 1063

  def test_return_path_with_create
1064
    mail = TestMailer.return_path
J
José Valim 已提交
1065
    assert_equal "another@somewhere.test", mail.return_path
1066 1067
  end

1068
  def test_return_path_with_deliver
1069
    TestMailer.delivery_method = :smtp
1070
    TestMailer.return_path.deliver
1071
    assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
1072
    assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
1073
  end
1074

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

  def test_starttls_is_disabled_if_not_supported
1084
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1085 1086
    MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
    MockSMTP.any_instance.expects(:enable_starttls_auto).never
1087
    TestMailer.delivery_method = :smtp
1088
    TestMailer.signed_up(@recipient).deliver
1089
  end
1090 1091

  def test_starttls_is_not_enabled
1092
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => false)
1093
    MockSMTP.any_instance.expects(:respond_to?).never
1094 1095
    TestMailer.delivery_method = :smtp
    TestMailer.signed_up(@recipient).deliver
1096
  ensure
1097
    TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
1098
  end
D
Initial  
David Heinemeier Hansson 已提交
1099
end
1100

1101
class InheritableTemplateRootTest < ActiveSupport::TestCase
1102
  def test_attr
1103
    expected = File.expand_path("#{File.dirname(__FILE__)}/../fixtures/path.with.dots")
1104
    assert_equal expected, FunkyPathMailer.template_root.to_s
1105 1106

    sub = Class.new(FunkyPathMailer)
1107 1108 1109
    assert_deprecated do
      sub.template_root = 'test/path'
    end
1110

1111
    assert_equal File.expand_path('test/path'), sub.template_root.to_s
1112
    assert_equal expected, FunkyPathMailer.template_root.to_s
1113 1114
  end
end
1115

1116
class MethodNamingTest < ActiveSupport::TestCase
1117 1118
  class TestMailer < ActionMailer::Base
    def send
1119
      body       'foo'
1120 1121 1122 1123
    end
  end

  def setup
1124
    set_delivery_method :test
1125
    ActionMailer::Base.perform_deliveries = true
1126
    ActionMailer::Base.deliveries.clear
1127 1128
  end

1129 1130 1131 1132
  def teardown
    restore_delivery_method
  end

1133 1134 1135
  def test_send_method
    assert_nothing_raised do
      assert_emails 1 do
1136 1137 1138
        assert_deprecated do
          TestMailer.deliver_send
        end
1139 1140 1141 1142
      end
    end
  end
end
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 1186 1187 1188 1189 1190 1191 1192
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
1193

1194 1195 1196 1197
  def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
    assert !RespondToMailer.respond_to?(:foo_deliver_template)
  end

1198
  def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
1199
    error = assert_raise NoMethodError do
1200 1201 1202
      RespondToMailer.not_a_method
    end

E
Evan Phoenix 已提交
1203
    assert_match(/method.*not_a_method/, error.message)
1204
  end
E
Evan Phoenix 已提交
1205
end