2008-01-05 13:32:22 +00:00
|
|
|
require 'abstract_unit'
|
2010-01-29 15:16:01 +00:00
|
|
|
require 'action_controller'
|
2006-08-25 06:48:15 +00:00
|
|
|
|
2009-11-30 00:28:45 +00:00
|
|
|
class WelcomeController < ActionController::Base
|
|
|
|
end
|
2009-10-18 15:39:21 +00:00
|
|
|
|
2010-02-25 00:21:21 +00:00
|
|
|
AppRoutes = ActionDispatch::Routing::RouteSet.new
|
|
|
|
|
2010-01-29 16:41:10 +00:00
|
|
|
class ActionMailer::Base
|
2010-02-26 23:00:33 +00:00
|
|
|
include AppRoutes.url_helpers
|
2010-01-29 16:41:10 +00:00
|
|
|
end
|
2010-01-29 15:16:01 +00:00
|
|
|
|
2010-03-18 05:27:34 +00:00
|
|
|
class UrlTestMailer < ActionMailer::Base
|
2007-09-22 19:20:06 +00:00
|
|
|
default_url_options[:host] = 'www.basecamphq.com'
|
2009-10-18 15:39:21 +00:00
|
|
|
|
2010-03-04 09:12:16 +00:00
|
|
|
configure do |c|
|
|
|
|
c.assets_dir = '' # To get the tests to pass
|
|
|
|
end
|
|
|
|
|
2006-08-25 06:48:15 +00:00
|
|
|
def signed_up_with_url(recipient)
|
2009-12-22 19:17:27 +00:00
|
|
|
@recipient = recipient
|
|
|
|
@welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
|
2010-08-29 23:42:09 +00:00
|
|
|
mail(:to => recipient, :subject => "[Signed up] Welcome #{recipient}",
|
|
|
|
:from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
|
2006-08-25 06:48:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-04 00:12:49 +00:00
|
|
|
class ActionMailerUrlTest < ActionMailer::TestCase
|
2006-08-25 06:48:15 +00:00
|
|
|
|
2010-04-08 02:47:17 +00:00
|
|
|
def encode( text, charset="UTF-8" )
|
2006-08-25 06:48:15 +00:00
|
|
|
quoted_printable( text, charset )
|
|
|
|
end
|
|
|
|
|
2010-04-08 02:47:17 +00:00
|
|
|
def new_mail( charset="UTF-8" )
|
2009-11-12 05:08:50 +00:00
|
|
|
mail = Mail.new
|
2006-09-09 21:56:38 +00:00
|
|
|
mail.mime_version = "1.0"
|
2006-08-25 06:48:15 +00:00
|
|
|
if charset
|
2009-11-20 03:10:57 +00:00
|
|
|
mail.content_type ["text", "plain", { "charset" => charset }]
|
2006-08-25 06:48:15 +00:00
|
|
|
end
|
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
2007-11-07 16:05:17 +00:00
|
|
|
set_delivery_method :test
|
2006-08-25 06:48:15 +00:00
|
|
|
ActionMailer::Base.perform_deliveries = true
|
2010-01-24 00:15:42 +00:00
|
|
|
ActionMailer::Base.deliveries.clear
|
2010-08-29 23:42:09 +00:00
|
|
|
ActiveSupport::Deprecation.silenced = false
|
2006-08-25 06:48:15 +00:00
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
2007-11-07 16:05:17 +00:00
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
2006-08-25 06:48:15 +00:00
|
|
|
def test_signed_up_with_url
|
2010-03-18 05:27:34 +00:00
|
|
|
UrlTestMailer.delivery_method = :test
|
2010-07-04 00:12:49 +00:00
|
|
|
|
2010-09-04 11:36:35 +00:00
|
|
|
AppRoutes.draw do
|
|
|
|
match ':controller(/:action(/:id))'
|
|
|
|
match '/welcome' => "foo#bar", :as => "welcome"
|
2009-10-18 15:39:21 +00:00
|
|
|
end
|
2009-11-30 00:28:45 +00:00
|
|
|
|
|
|
|
expected = new_mail
|
|
|
|
expected.to = @recipient
|
|
|
|
expected.subject = "[Signed up] Welcome #{@recipient}"
|
2010-08-14 08:58:34 +00:00
|
|
|
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\" />"
|
2009-11-30 00:28:45 +00:00
|
|
|
expected.from = "system@loudthinking.com"
|
|
|
|
expected.date = Time.local(2004, 12, 12)
|
2010-08-29 23:42:09 +00:00
|
|
|
expected.content_type = "text/html"
|
2009-11-30 00:28:45 +00:00
|
|
|
|
|
|
|
created = nil
|
2010-03-18 05:27:34 +00:00
|
|
|
assert_nothing_raised { created = UrlTestMailer.signed_up_with_url(@recipient) }
|
2009-11-30 00:28:45 +00:00
|
|
|
assert_not_nil created
|
2009-12-17 01:00:32 +00:00
|
|
|
|
|
|
|
expected.message_id = '<123@456>'
|
|
|
|
created.message_id = '<123@456>'
|
2009-11-30 00:28:45 +00:00
|
|
|
assert_equal expected.encoded, created.encoded
|
|
|
|
|
2010-03-18 05:27:34 +00:00
|
|
|
assert_nothing_raised { UrlTestMailer.signed_up_with_url(@recipient).deliver }
|
2009-11-30 00:28:45 +00:00
|
|
|
assert_not_nil ActionMailer::Base.deliveries.first
|
2009-12-17 01:00:32 +00:00
|
|
|
delivered = ActionMailer::Base.deliveries.first
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2009-12-17 01:00:32 +00:00
|
|
|
delivered.message_id = '<123@456>'
|
|
|
|
assert_equal expected.encoded, delivered.encoded
|
2006-08-25 06:48:15 +00:00
|
|
|
end
|
2008-01-05 13:32:22 +00:00
|
|
|
end
|