Froze rails gems
[depot.git] / vendor / rails / actionmailer / test / mail_render_test.rb
1 require 'abstract_unit'
2
3 class RenderMailer < ActionMailer::Base
4 def inline_template(recipient)
5 recipients recipient
6 subject "using helpers"
7 from "tester@example.com"
8 body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" })
9 end
10
11 def file_template(recipient)
12 recipients recipient
13 subject "using helpers"
14 from "tester@example.com"
15 body render(:file => "signed_up", :body => { :recipient => recipient })
16 end
17
18 def rxml_template(recipient)
19 recipients recipient
20 subject "rendering rxml template"
21 from "tester@example.com"
22 end
23
24 def included_subtemplate(recipient)
25 recipients recipient
26 subject "Including another template in the one being rendered"
27 from "tester@example.com"
28 end
29
30 def included_old_subtemplate(recipient)
31 recipients recipient
32 subject "Including another template in the one being rendered"
33 from "tester@example.com"
34 body render(:inline => "Hello, <%= render \"subtemplate\" %>", :body => { :world => "Earth" })
35 end
36
37 def initialize_defaults(method_name)
38 super
39 mailer_name "test_mailer"
40 end
41 end
42
43 class FirstMailer < ActionMailer::Base
44 def share(recipient)
45 recipients recipient
46 subject "using helpers"
47 from "tester@example.com"
48 end
49 end
50
51 class SecondMailer < ActionMailer::Base
52 def share(recipient)
53 recipients recipient
54 subject "using helpers"
55 from "tester@example.com"
56 end
57 end
58
59 class RenderHelperTest < Test::Unit::TestCase
60 def setup
61 set_delivery_method :test
62 ActionMailer::Base.perform_deliveries = true
63 ActionMailer::Base.deliveries = []
64
65 @recipient = 'test@localhost'
66 end
67
68 def teardown
69 restore_delivery_method
70 end
71
72 def test_inline_template
73 mail = RenderMailer.create_inline_template(@recipient)
74 assert_equal "Hello, Earth", mail.body.strip
75 end
76
77 def test_file_template
78 mail = RenderMailer.create_file_template(@recipient)
79 assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
80 end
81
82 def test_rxml_template
83 mail = RenderMailer.deliver_rxml_template(@recipient)
84 assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.strip
85 end
86
87 def test_included_subtemplate
88 mail = RenderMailer.deliver_included_subtemplate(@recipient)
89 assert_equal "Hey Ho, let's go!", mail.body.strip
90 end
91 end
92
93 class FirstSecondHelperTest < Test::Unit::TestCase
94 def setup
95 set_delivery_method :test
96 ActionMailer::Base.perform_deliveries = true
97 ActionMailer::Base.deliveries = []
98
99 @recipient = 'test@localhost'
100 end
101
102 def teardown
103 restore_delivery_method
104 end
105
106 def test_ordering
107 mail = FirstMailer.create_share(@recipient)
108 assert_equal "first mail", mail.body.strip
109 mail = SecondMailer.create_share(@recipient)
110 assert_equal "second mail", mail.body.strip
111 mail = FirstMailer.create_share(@recipient)
112 assert_equal "first mail", mail.body.strip
113 mail = SecondMailer.create_share(@recipient)
114 assert_equal "second mail", mail.body.strip
115 end
116 end