aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/mail_helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/test/mail_helper_test.rb')
-rw-r--r--actionmailer/test/mail_helper_test.rb98
1 files changed, 28 insertions, 70 deletions
diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb
index 2d3565d159..7cc0804323 100644
--- a/actionmailer/test/mail_helper_test.rb
+++ b/actionmailer/test/mail_helper_test.rb
@@ -1,96 +1,54 @@
require 'abstract_unit'
-module MailerHelper
- def person_name
- "Mr. Joe Person"
- end
-end
-
class HelperMailer < ActionMailer::Base
- helper MailerHelper
- helper :example
-
- def use_helper(recipient)
- recipients recipient
- subject "using helpers"
- from "tester@example.com"
- end
-
- def use_example_helper(recipient)
- recipients recipient
- subject "using helpers"
- from "tester@example.com"
-
- @text = "emphasize me!"
- end
-
- def use_mail_helper(recipient)
- recipients recipient
- subject "using mailing helpers"
- from "tester@example.com"
-
+ def use_mail_helper
@text = "But soft! What light through yonder window breaks? It is the east, " +
"and Juliet is the sun. Arise, fair sun, and kill the envious moon, " +
"which is sick and pale with grief that thou, her maid, art far more " +
"fair than she. Be not her maid, for she is envious! Her vestal " +
"livery is but sick and green, and none but fools do wear it. Cast " +
"it off!"
- end
- def use_helper_method(recipient)
- recipients recipient
- subject "using helpers"
- from "tester@example.com"
-
- @text = "emphasize me!"
+ mail_with_defaults do |format|
+ format.html { render(:inline => "<%= block_format @text %>") }
+ end
end
- private
-
- def name_of_the_mailer_class
- self.class.name
+ def use_mailer
+ mail_with_defaults do |format|
+ format.html { render(:inline => "<%= mailer.message.subject %>") }
end
- helper_method :name_of_the_mailer_class
-end
+ end
-class MailerHelperTest < Test::Unit::TestCase
- def new_mail( charset="utf-8" )
- mail = Mail.new
- mail.set_content_type "text", "plain", { "charset" => charset } if charset
- mail
+ def use_message
+ mail_with_defaults do |format|
+ format.html { render(:inline => "<%= message.subject %>") }
+ end
end
- def setup
- set_delivery_method :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries = []
+ protected
- @recipient = 'test@localhost'
- end
-
- def teardown
- restore_delivery_method
- end
-
- def test_use_helper
- mail = HelperMailer.create_use_helper(@recipient)
- assert_match %r{Mr. Joe Person}, mail.encoded
+ def mail_with_defaults(&block)
+ mail(:to => "test@localhost", :from => "tester@example.com",
+ :subject => "using helpers", &block)
end
+end
- def test_use_example_helper
- mail = HelperMailer.create_use_example_helper(@recipient)
- assert_match %r{<em><strong><small>emphasize me!}, mail.encoded
+class MailerHelperTest < ActionMailer::TestCase
+ def test_use_mail_helper
+ mail = HelperMailer.use_mail_helper
+ assert_match %r{ But soft!}, mail.body.encoded
+ assert_match %r{east, and\r\n Juliet}, mail.body.encoded
end
- def test_use_helper_method
- mail = HelperMailer.create_use_helper_method(@recipient)
- assert_match %r{HelperMailer}, mail.encoded
+ def test_use_mailer
+ mail = HelperMailer.use_mailer
+ assert_match "using helpers", mail.body.encoded
end
- def test_use_mail_helper
- mail = HelperMailer.create_use_mail_helper(@recipient)
- assert_match %r{ But soft!}, mail.encoded
- assert_match %r{east, and\r\n Juliet}, mail.encoded
+ def test_use_message
+ mail = HelperMailer.use_message
+ assert_match "using helpers", mail.body.encoded
end
end