~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionmailer/test/mail_helper_test.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'abstract_unit'
 
2
 
 
3
module MailerHelper
 
4
  def person_name
 
5
    "Mr. Joe Person"
 
6
  end
 
7
end
 
8
 
 
9
class HelperMailer < ActionMailer::Base
 
10
  helper MailerHelper
 
11
  helper :example
 
12
 
 
13
  def use_helper(recipient)
 
14
    recipients recipient
 
15
    subject    "using helpers"
 
16
    from       "tester@example.com"
 
17
  end
 
18
 
 
19
  def use_example_helper(recipient)
 
20
    recipients recipient
 
21
    subject    "using helpers"
 
22
    from       "tester@example.com"
 
23
    self.body = { :text => "emphasize me!" }
 
24
  end
 
25
 
 
26
  def use_mail_helper(recipient)
 
27
    recipients recipient
 
28
    subject    "using mailing helpers"
 
29
    from       "tester@example.com"
 
30
    self.body = { :text => 
 
31
      "But soft! What light through yonder window breaks? It is the east, " +
 
32
      "and Juliet is the sun. Arise, fair sun, and kill the envious moon, " +
 
33
      "which is sick and pale with grief that thou, her maid, art far more " +
 
34
      "fair than she. Be not her maid, for she is envious! Her vestal " +
 
35
      "livery is but sick and green, and none but fools do wear it. Cast " +
 
36
      "it off!"
 
37
    }
 
38
  end
 
39
 
 
40
  def use_helper_method(recipient)
 
41
    recipients recipient
 
42
    subject    "using helpers"
 
43
    from       "tester@example.com"
 
44
    self.body = { :text => "emphasize me!" }
 
45
  end
 
46
 
 
47
  private
 
48
 
 
49
    def name_of_the_mailer_class
 
50
      self.class.name
 
51
    end
 
52
    helper_method :name_of_the_mailer_class
 
53
end
 
54
 
 
55
class MailerHelperTest < Test::Unit::TestCase
 
56
  def new_mail( charset="utf-8" )
 
57
    mail = TMail::Mail.new
 
58
    mail.set_content_type "text", "plain", { "charset" => charset } if charset
 
59
    mail
 
60
  end
 
61
 
 
62
  def setup
 
63
    set_delivery_method :test
 
64
    ActionMailer::Base.perform_deliveries = true
 
65
    ActionMailer::Base.deliveries = []
 
66
 
 
67
    @recipient = 'test@localhost'
 
68
  end
 
69
  
 
70
  def teardown
 
71
    restore_delivery_method
 
72
  end
 
73
  
 
74
  def test_use_helper
 
75
    mail = HelperMailer.create_use_helper(@recipient)
 
76
    assert_match %r{Mr. Joe Person}, mail.encoded
 
77
  end
 
78
 
 
79
  def test_use_example_helper
 
80
    mail = HelperMailer.create_use_example_helper(@recipient)
 
81
    assert_match %r{<em><strong><small>emphasize me!}, mail.encoded
 
82
  end
 
83
 
 
84
  def test_use_helper_method
 
85
    mail = HelperMailer.create_use_helper_method(@recipient)
 
86
    assert_match %r{HelperMailer}, mail.encoded
 
87
  end
 
88
 
 
89
  def test_use_mail_helper
 
90
    mail = HelperMailer.create_use_mail_helper(@recipient)
 
91
    assert_match %r{  But soft!}, mail.encoded
 
92
    assert_match %r{east, and\n  Juliet}, mail.encoded
 
93
  end
 
94
end
 
95