aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/old_base/url_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-26 01:56:52 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-26 01:56:52 +0100
commitabad097016bf5243e9812f6a031f421a986b09f7 (patch)
treef526a520a87db9c68ddd3436ce4bdb6f8c3182d1 /actionmailer/test/old_base/url_test.rb
parent8974dac92e05dcab8ee552a5f40108c6ac25dc36 (diff)
parentc02391f8f97182e818d22a0f0ec4a5589d2fff15 (diff)
downloadrails-abad097016bf5243e9812f6a031f421a986b09f7.tar.gz
rails-abad097016bf5243e9812f6a031f421a986b09f7.tar.bz2
rails-abad097016bf5243e9812f6a031f421a986b09f7.zip
Merge remote branch 'mikel/master'
Diffstat (limited to 'actionmailer/test/old_base/url_test.rb')
-rw-r--r--actionmailer/test/old_base/url_test.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/old_base/url_test.rb
new file mode 100644
index 0000000000..5affb47997
--- /dev/null
+++ b/actionmailer/test/old_base/url_test.rb
@@ -0,0 +1,86 @@
+require 'abstract_unit'
+
+class WelcomeController < ActionController::Base
+end
+
+class TestMailer < ActionMailer::Base
+ default_url_options[:host] = 'www.basecamphq.com'
+
+ def signed_up_with_url(recipient)
+ @recipients = recipient
+ @subject = "[Signed up] Welcome #{recipient}"
+ @from = "system@loudthinking.com"
+ @sent_on = Time.local(2004, 12, 12)
+
+ @recipient = recipient
+ @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
+
+class ActionMailerUrlTest < Test::Unit::TestCase
+ include ActionMailer::Quoting
+
+ def encode( text, charset="utf-8" )
+ quoted_printable( text, charset )
+ end
+
+ def new_mail( charset="utf-8" )
+ mail = Mail.new
+ mail.mime_version = "1.0"
+ if charset
+ mail.content_type ["text", "plain", { "charset" => charset }]
+ end
+ mail
+ end
+
+ def setup
+ set_delivery_method :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries.clear
+
+ @recipient = 'test@localhost'
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_signed_up_with_url
+ TestMailer.delivery_method = :test
+
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ map.welcome 'welcome', :controller=>"foo", :action=>"bar"
+ end
+
+ 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.signed_up_with_url(@recipient) }
+ assert_not_nil created
+
+ expected.message_id = '<123@456>'
+ created.message_id = '<123@456>'
+ assert_equal expected.encoded, created.encoded
+
+ assert_nothing_raised { TestMailer.signed_up_with_url(@recipient).deliver }
+ assert_not_nil ActionMailer::Base.deliveries.first
+ delivered = ActionMailer::Base.deliveries.first
+
+ delivered.message_id = '<123@456>'
+ assert_equal expected.encoded, delivered.encoded
+ end
+end