aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/old_base/mail_render_test.rb
blob: 3a1d3184f4baef787046f79efd42265b5a8d8deb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
require 'abstract_unit'

class RenderMailer < ActionMailer::Base
  def inline_template
    recipients 'test@localhost'
    subject    "using helpers"
    from       "tester@example.com"

    @world = "Earth"
    body       render(:inline => "Hello, <%= @world %>")
  end

  def file_template
    recipients 'test@localhost'
    subject    "using helpers"
    from       "tester@example.com"

    @recipient = 'test@localhost'
    body       render(:file => "templates/signed_up")
  end

  def no_instance_variable
    recipients 'test@localhost'
    subject    "No Instance Variable"
    from       "tester@example.com"

    silence_warnings do
      body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!")
    end
  end

  def multipart_alternative
    recipients 'test@localhost'
    subject    'multipart/alternative'
    from       'tester@example.com'

    build_multipart_message(:foo => "bar")
  end

  private
    def build_multipart_message(assigns = {})
      content_type "multipart/alternative"

      part "text/plain" do |p|
        p.body = build_body_part('plain', assigns, :layout => false)
      end

      part "text/html" do |p|
        p.body = build_body_part('html', assigns)
      end
    end

    def build_body_part(content_type, assigns, options = {})
      ActiveSupport::Deprecation.silence do
        render "#{template}.#{content_type}", :body => assigns
      end
    end
end

class FirstMailer < ActionMailer::Base
  def share
    recipients 'test@localhost'
    subject    "using helpers"
    from       "tester@example.com"
  end
end

class SecondMailer < ActionMailer::Base
  def share
    recipients 'test@localhost'
    subject    "using helpers"
    from       "tester@example.com"
  end
end

# CHANGED: Those tests were changed because body returns an object now
# Instead of mail.body.strip, we should mail.body.to_s.strip
class RenderHelperTest < Test::Unit::TestCase
  def setup
    set_delivery_method :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries.clear
    ActiveSupport::Deprecation.silenced = true

    @recipient = 'test@localhost'
  end

  def teardown
    ActiveSupport::Deprecation.silenced = false
    restore_delivery_method
  end

  def test_inline_template
    mail = RenderMailer.inline_template
    assert_equal "Hello, Earth", mail.body.to_s.strip
  end

  def test_file_template
    mail = RenderMailer.file_template
    assert_equal "Hello there,\n\nMr. test@localhost", mail.body.to_s.strip
  end

  def test_no_instance_variable
    mail = RenderMailer.no_instance_variable.deliver
    assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
  end
end

class FirstSecondHelperTest < Test::Unit::TestCase
  def setup
    set_delivery_method :test
    ActiveSupport::Deprecation.silenced = true
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries.clear

    @recipient = 'test@localhost'
  end

  def teardown
    ActiveSupport::Deprecation.silenced = false
    restore_delivery_method
  end

  def test_ordering
    mail = FirstMailer.share
    assert_equal "first mail", mail.body.to_s.strip
    mail = SecondMailer.share
    assert_equal "second mail", mail.body.to_s.strip
    mail = FirstMailer.share
    assert_equal "first mail", mail.body.to_s.strip
    mail = SecondMailer.share
    assert_equal "second mail", mail.body.to_s.strip
  end
end