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