| 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 |
|
|---|
| 92 |
def test_deprecated_old_subtemplate |
|---|
| 93 |
assert_raises ActionView::ActionViewError do |
|---|
| 94 |
RenderMailer.deliver_included_old_subtemplate(@recipient) |
|---|
| 95 |
end |
|---|
| 96 |
end |
|---|
| 97 |
end |
|---|
| 98 |
|
|---|
| 99 |
class FirstSecondHelperTest < Test::Unit::TestCase |
|---|
| 100 |
def setup |
|---|
| 101 |
set_delivery_method :test |
|---|
| 102 |
ActionMailer::Base.perform_deliveries = true |
|---|
| 103 |
ActionMailer::Base.deliveries = [] |
|---|
| 104 |
|
|---|
| 105 |
@recipient = 'test@localhost' |
|---|
| 106 |
end |
|---|
| 107 |
|
|---|
| 108 |
def teardown |
|---|
| 109 |
restore_delivery_method |
|---|
| 110 |
end |
|---|
| 111 |
|
|---|
| 112 |
def test_ordering |
|---|
| 113 |
mail = FirstMailer.create_share(@recipient) |
|---|
| 114 |
assert_equal "first mail", mail.body.strip |
|---|
| 115 |
mail = SecondMailer.create_share(@recipient) |
|---|
| 116 |
assert_equal "second mail", mail.body.strip |
|---|
| 117 |
mail = FirstMailer.create_share(@recipient) |
|---|
| 118 |
assert_equal "first mail", mail.body.strip |
|---|
| 119 |
mail = SecondMailer.create_share(@recipient) |
|---|
| 120 |
assert_equal "second mail", mail.body.strip |
|---|
| 121 |
end |
|---|
| 122 |
end |
|---|