mail_service_test.rb 38.5 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
    TestMailer.delivery_method = :test

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

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

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

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

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

    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 已提交
419
  end
420

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

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

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

448 449
    # Stub the render method so no alternative renderers need be present.
    ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
450

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

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

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

475
    assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
D
Initial  
David Heinemeier Hansson 已提交
476
    assert_not_nil ActionMailer::Base.deliveries.first
477 478 479 480 481
    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 已提交
482
  end
483

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

    assert_nothing_raised do
504
      TestMailer.cc_bcc(@recipient).deliver
505 506 507
    end

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

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

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

523
    assert_equal 'system@loudthinking.com', from.to_s
524 525 526
  end

  def test_from_with_name_for_smtp
527
    TestMailer.delivery_method = :smtp
528
    TestMailer.from_with_name.deliver
529 530 531 532 533

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

534
    assert_equal 'system@loudthinking.com', from
535 536
  end

537
  def test_reply_to
538 539
    TestMailer.delivery_method = :test

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

    assert_nothing_raised do
561
      TestMailer.different_reply_to(@recipient).deliver
562 563
    end

M
Mikel Lindsaar 已提交
564 565 566 567 568 569 570
    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
571 572
  end

573
  def test_iso_charset
574 575
    TestMailer.delivery_method = :test

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

594 595 596
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
597
      TestMailer.iso_charset(@recipient).deliver
598 599
    end

M
Mikel Lindsaar 已提交
600 601 602 603 604 605 606
    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
607 608 609
  end

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

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

629 630 631
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
632
      TestMailer.unencoded_subject(@recipient).deliver
633 634
    end

M
Mikel Lindsaar 已提交
635 636 637 638 639 640 641
    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
642 643
  end

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

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

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

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

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

741 742 743 744
  def test_extended_headers
    @recipient = "Grytøyr <test@localhost>"

    expected = new_mail "iso-8859-1"
745
    expected.to      = quote_address_if_necessary @recipient, "iso-8859-1"
746 747
    expected.subject = "testing extended headers"
    expected.body    = "Nothing to see here."
748 749 750
    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"
751 752 753 754
    expected.date    = Time.local 2004, 12, 12

    created = nil
    assert_nothing_raised do
755
      created = TestMailer.extended_headers @recipient
756 757 758
    end

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

762 763 764
    assert_equal expected.encoded, created.encoded

    assert_nothing_raised do
765
      TestMailer.extended_headers(@recipient).deliver
766 767
    end

M
Mikel Lindsaar 已提交
768 769 770 771 772 773 774
    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
775
  end
776

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

788
    created = TestMailer.utf8_body @recipient
789
    assert_match(/åœö blah/, created.encoded)
790 791 792
  end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

886
    assert_equal "image/jpeg", mail.parts[2].mime_type
887
    
888 889 890
    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
891
    assert_nil mail.parts[2].charset
892 893
  end

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

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

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

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

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

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

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

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

936 937 938
    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]
939 940
  end

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

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

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

957
  def test_various_newlines_multipart
958
    mail = TestMailer.various_newlines_multipart(@recipient)
959 960
    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 已提交
961 962
    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
963
  end
964

965
  def test_headers_removed_on_smtp_delivery
966
    TestMailer.delivery_method = :smtp
967
    TestMailer.cc_bcc(@recipient).deliver
968 969 970 971 972 973 974
    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
975

976
   def test_file_delivery_should_create_a_file
977 978
     TestMailer.delivery_method = :file
     tmp_location = TestMailer.file_settings[:location]
979

980
     result = TestMailer.cc_bcc(@recipient).deliver
981 982 983 984 985
     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'))
986 987
   end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1111
class MethodNamingTest < ActiveSupport::TestCase
1112 1113
  class TestMailer < ActionMailer::Base
    def send
1114
      render :text => 'foo'
1115 1116 1117 1118
    end
  end

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

1124 1125 1126 1127
  def teardown
    restore_delivery_method
  end

1128 1129 1130
  def test_send_method
    assert_nothing_raised do
      assert_emails 1 do
1131 1132 1133
        assert_deprecated do
          TestMailer.deliver_send
        end
1134 1135 1136 1137
      end
    end
  end
end
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 1186 1187
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
1188

1189 1190 1191 1192
  def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
    assert !RespondToMailer.respond_to?(:foo_deliver_template)
  end

1193
  def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
1194
    error = assert_raise NoMethodError do
1195 1196 1197
      RespondToMailer.not_a_method
    end

1198
    assert_match(/undefined method.*not_a_method/, error.message)
1199
  end
1200
end