aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/CHANGELOG3
-rw-r--r--actionmailer/lib/action_mailer/base.rb1
-rw-r--r--actionmailer/test/fixtures/test_mailer/signed_up_with_url.rhtml3
-rw-r--r--actionmailer/test/url_test.rb88
4 files changed, 95 insertions, 0 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 01bcc9a2d7..267a6265f5 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Automatically included ActionController::UrlWriter, such that URL generation can happen within ActionMailer controllers. [DHH]
+
* Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar]
* Mailer template root applies to a class and its subclasses rather than acting globally. #5555 [somekool@gmail.com]
@@ -14,6 +16,7 @@
* Correct spurious documentation example code which results in a SyntaxError. [Marcel Molina Jr.]
+
*1.2.1* (April 6th, 2006)
* Be part of Rails 1.1.1
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 873eb3c9c9..6143121519 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -184,6 +184,7 @@ module ActionMailer #:nodoc:
# <tt>@implicit_parts_order</tt>.
class Base
include AdvAttrAccessor, PartContainer
+ include ActionController::UrlWriter
# Action Mailer subclasses should be reloaded by the dispatcher in Rails
# when Dependencies.mechanism = :load.
diff --git a/actionmailer/test/fixtures/test_mailer/signed_up_with_url.rhtml b/actionmailer/test/fixtures/test_mailer/signed_up_with_url.rhtml
new file mode 100644
index 0000000000..e8fb65d4d2
--- /dev/null
+++ b/actionmailer/test/fixtures/test_mailer/signed_up_with_url.rhtml
@@ -0,0 +1,3 @@
+Hello there,
+
+Mr. <%= @recipient %>. Please see our greeting at <%= @welcome_url %> \ No newline at end of file
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
new file mode 100644
index 0000000000..b953154515
--- /dev/null
+++ b/actionmailer/test/url_test.rb
@@ -0,0 +1,88 @@
+require "#{File.dirname(__FILE__)}/abstract_unit"
+
+class MockSMTP
+ def self.deliveries
+ @@deliveries
+ end
+
+ def initialize
+ @@deliveries = []
+ end
+
+ def sendmail(mail, from, to)
+ @@deliveries << [mail, from, to]
+ end
+end
+
+class Net::SMTP
+ def self.start(*args)
+ yield MockSMTP.new
+ end
+end
+
+class TestMailer < ActionMailer::Base
+ 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
+
+class ActionMailerTest < Test::Unit::TestCase
+ include ActionMailer::Quoting
+
+ def encode( text, charset="utf-8" )
+ quoted_printable( text, charset )
+ end
+
+ def new_mail( charset="utf-8" )
+ mail = TMail::Mail.new
+ if charset
+ mail.set_content_type "text", "plain", { "charset" => charset }
+ end
+ mail
+ end
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @recipient = 'test@localhost'
+ end
+
+ def test_signed_up_with_url
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ 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"
+ expected.from = "system@loudthinking.com"
+ expected.date = Time.local(2004, 12, 12)
+ expected.mime_version = nil
+
+ 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
+ end
+end \ No newline at end of file