2008-01-05 08:32:22 -05:00
|
|
|
require 'abstract_unit'
|
2006-08-25 02:48:15 -04:00
|
|
|
|
2009-11-29 19:28:45 -05:00
|
|
|
class WelcomeController < ActionController::Base
|
|
|
|
end
|
2009-10-18 11:39:21 -04:00
|
|
|
|
2009-11-29 19:28:45 -05:00
|
|
|
class TestMailer < ActionMailer::Base
|
2007-09-22 15:20:06 -04:00
|
|
|
default_url_options[:host] = 'www.basecamphq.com'
|
2009-10-18 11:39:21 -04:00
|
|
|
|
2006-08-25 02:48:15 -04:00
|
|
|
def signed_up_with_url(recipient)
|
|
|
|
@recipients = recipient
|
|
|
|
@subject = "[Signed up] Welcome #{recipient}"
|
|
|
|
@from = "system@loudthinking.com"
|
|
|
|
@sent_on = Time.local(2004, 12, 12)
|
|
|
|
|
|
|
|
@body["recipient"] = recipient
|
|
|
|
@body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
|
|
|
|
end
|
|
|
|
|
|
|
|
class <<self
|
|
|
|
attr_accessor :received_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def receive(mail)
|
|
|
|
self.class.received_body = mail.body
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-09-09 17:56:38 -04:00
|
|
|
class ActionMailerUrlTest < Test::Unit::TestCase
|
2006-08-25 02:48:15 -04:00
|
|
|
include ActionMailer::Quoting
|
|
|
|
|
|
|
|
def encode( text, charset="utf-8" )
|
|
|
|
quoted_printable( text, charset )
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_mail( charset="utf-8" )
|
|
|
|
mail = TMail::Mail.new
|
2006-09-09 17:56:38 -04:00
|
|
|
mail.mime_version = "1.0"
|
2006-08-25 02:48:15 -04:00
|
|
|
if charset
|
|
|
|
mail.set_content_type "text", "plain", { "charset" => charset }
|
|
|
|
end
|
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
2007-11-07 11:05:17 -05:00
|
|
|
set_delivery_method :test
|
2006-08-25 02:48:15 -04:00
|
|
|
ActionMailer::Base.perform_deliveries = true
|
|
|
|
ActionMailer::Base.deliveries = []
|
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
2007-11-07 11:05:17 -05:00
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
2006-08-25 02:48:15 -04:00
|
|
|
def test_signed_up_with_url
|
2009-11-29 19:28:45 -05:00
|
|
|
ActionController::Routing::Routes.draw do |map|
|
|
|
|
map.connect ':controller/:action/:id'
|
|
|
|
map.welcome 'welcome', :controller=>"foo", :action=>"bar"
|
2009-10-18 11:39:21 -04:00
|
|
|
end
|
2009-11-29 19:28:45 -05:00
|
|
|
|
|
|
|
expected = new_mail
|
|
|
|
expected.to = @recipient
|
|
|
|
expected.subject = "[Signed up] Welcome #{@recipient}"
|
|
|
|
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\" />"
|
|
|
|
expected.from = "system@loudthinking.com"
|
|
|
|
expected.date = Time.local(2004, 12, 12)
|
|
|
|
|
|
|
|
created = nil
|
|
|
|
assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) }
|
|
|
|
assert_not_nil created
|
|
|
|
assert_equal expected.encoded, created.encoded
|
|
|
|
|
|
|
|
assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) }
|
|
|
|
assert_not_nil ActionMailer::Base.deliveries.first
|
|
|
|
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
|
2006-08-25 02:48:15 -04:00
|
|
|
end
|
2008-01-05 08:32:22 -05:00
|
|
|
end
|