1 require 'abstract_unit'
3 class TestMailer
< ActionMailer
::Base
5 default_url_options
[:host] = 'www.basecamphq.com'
7 def signed_up_with_url(recipient
)
8 @recipients = recipient
9 @subject = "[Signed up] Welcome #{recipient}"
10 @from = "system@loudthinking.com"
11 @sent_on = Time
.local(2004, 12, 12)
13 @body["recipient"] = recipient
14 @body["welcome_url"] = url_for
:host => "example.com", :controller => "welcome", :action => "greeting"
18 attr_accessor :received_body
22 self.class.received_body
= mail
.body
26 class ActionMailerUrlTest
< Test
::Unit::TestCase
27 include ActionMailer
::Quoting
29 def encode( text
, charset
="utf-8" )
30 quoted_printable( text
, charset
)
33 def new_mail( charset
="utf-8" )
34 mail
= TMail
::Mail.new
35 mail
.mime_version
= "1.0"
37 mail
.set_content_type
"text", "plain", { "charset" => charset
}
43 set_delivery_method
:test
44 ActionMailer
::Base.perform_deliveries
= true
45 ActionMailer
::Base.deliveries
= []
47 @recipient = 'test@localhost'
51 restore_delivery_method
54 def test_signed_up_with_url
55 ActionController
::Routing::Routes.draw
do |map
|
56 map
.connect
':controller/:action/:id'
57 map
.welcome
'welcome', :controller=>"foo", :action=>"bar"
61 expected
.to
= @recipient
62 expected
.subject
= "[Signed up] Welcome #{@recipient}"
63 expected
.body
= "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
64 expected
.from
= "system@loudthinking.com"
65 expected
.date
= Time
.local(2004, 12, 12)
68 assert_nothing_raised
{ created
= TestMailer
.create_signed_up_with_url(@recipient) }
69 assert_not_nil created
70 assert_equal expected
.encoded
, created
.encoded
72 assert_nothing_raised
{ TestMailer
.deliver_signed_up_with_url(@recipient) }
73 assert_not_nil ActionMailer
::Base.deliveries
.first
74 assert_equal expected
.encoded
, ActionMailer
::Base.deliveries
.first
.encoded