~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionmailer/test/test_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
class TestHelperMailer < ActionMailer::Base
 
4
  def test
 
5
    recipients "test@example.com"
 
6
    from       "tester@example.com"
 
7
    body       render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" })
 
8
  end
 
9
end
 
10
 
 
11
class TestHelperMailerTest < ActionMailer::TestCase
 
12
  def test_setup_sets_right_action_mailer_options
 
13
    assert_equal :test, ActionMailer::Base.delivery_method
 
14
    assert ActionMailer::Base.perform_deliveries
 
15
    assert_equal [], ActionMailer::Base.deliveries
 
16
  end
 
17
 
 
18
  def test_setup_creates_the_expected_mailer
 
19
    assert @expected.is_a?(TMail::Mail)
 
20
    assert_equal "1.0", @expected.mime_version
 
21
    assert_equal "text/plain", @expected.content_type
 
22
  end
 
23
 
 
24
  def test_mailer_class_is_correctly_inferred
 
25
    assert_equal TestHelperMailer, self.class.mailer_class
 
26
  end
 
27
 
 
28
  def test_determine_default_mailer_raises_correct_error
 
29
    assert_raise(ActionMailer::NonInferrableMailerError) do
 
30
      self.class.determine_default_mailer("NotAMailerTest")
 
31
    end
 
32
  end
 
33
  
 
34
  def test_charset_is_utf_8
 
35
    assert_equal "utf-8", charset
 
36
  end
 
37
 
 
38
  def test_encode
 
39
    assert_equal "=?utf-8?Q?=0Aasdf=0A?=", encode("\nasdf\n")
 
40
  end
 
41
 
 
42
  def test_assert_emails
 
43
    assert_nothing_raised do
 
44
      assert_emails 1 do
 
45
        TestHelperMailer.deliver_test
 
46
      end
 
47
    end
 
48
  end
 
49
  
 
50
  def test_repeated_assert_emails_calls
 
51
    assert_nothing_raised do
 
52
      assert_emails 1 do
 
53
        TestHelperMailer.deliver_test
 
54
      end
 
55
    end
 
56
    
 
57
    assert_nothing_raised do
 
58
      assert_emails 2 do
 
59
        TestHelperMailer.deliver_test
 
60
        TestHelperMailer.deliver_test
 
61
      end
 
62
    end
 
63
  end
 
64
  
 
65
  def test_assert_emails_with_no_block
 
66
    assert_nothing_raised do
 
67
      TestHelperMailer.deliver_test
 
68
      assert_emails 1
 
69
    end
 
70
    
 
71
    assert_nothing_raised do
 
72
      TestHelperMailer.deliver_test
 
73
      TestHelperMailer.deliver_test
 
74
      assert_emails 3
 
75
    end
 
76
  end
 
77
  
 
78
  def test_assert_no_emails
 
79
    assert_nothing_raised do
 
80
      assert_no_emails do
 
81
        TestHelperMailer.create_test
 
82
      end
 
83
    end
 
84
  end
 
85
  
 
86
  def test_assert_emails_too_few_sent
 
87
    error = assert_raise ActiveSupport::TestCase::Assertion do
 
88
      assert_emails 2 do
 
89
        TestHelperMailer.deliver_test
 
90
      end
 
91
    end
 
92
    
 
93
    assert_match /2 .* but 1/, error.message
 
94
  end
 
95
  
 
96
  def test_assert_emails_too_many_sent
 
97
    error = assert_raise ActiveSupport::TestCase::Assertion do
 
98
      assert_emails 1 do
 
99
        TestHelperMailer.deliver_test
 
100
        TestHelperMailer.deliver_test
 
101
      end
 
102
    end
 
103
    
 
104
    assert_match /1 .* but 2/, error.message
 
105
  end
 
106
  
 
107
  def test_assert_no_emails_failure
 
108
    error = assert_raise ActiveSupport::TestCase::Assertion do
 
109
      assert_no_emails do
 
110
        TestHelperMailer.deliver_test
 
111
      end
 
112
    end
 
113
    
 
114
    assert_match /0 .* but 1/, error.message
 
115
  end
 
116
end
 
117
 
 
118
class AnotherTestHelperMailerTest < ActionMailer::TestCase
 
119
  tests TestHelperMailer
 
120
 
 
121
  def setup
 
122
    @test_var = "a value"
 
123
  end
 
124
 
 
125
  def test_setup_shouldnt_conflict_with_mailer_setup
 
126
    assert @expected.is_a?(TMail::Mail)
 
127
    assert_equal 'a value', @test_var
 
128
  end
 
129
end