test/mail_service_test.rb in actionmailer-2.1.2 vs test/mail_service_test.rb in actionmailer-2.2.2
- old
+ new
@@ -217,11 +217,11 @@
p.part :content_type => "text/plain", :body => "test text\nline #2"
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
end
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
end
-
+
def nested_multipart_with_body(recipient)
recipients recipient
subject "nested multipart with body"
from "test@example.com"
content_type "multipart/mixed"
@@ -271,10 +271,17 @@
from "some.one@somewhere.test"
body "testing"
headers "return-path" => "another@somewhere.test"
end
+ def body_ivar(recipient)
+ recipients recipient
+ subject "Body as a local variable"
+ from "test@example.com"
+ body :body => "foo", :bar => "baz"
+ end
+
class <<self
attr_accessor :received_body
end
def receive(mail)
@@ -319,11 +326,11 @@
def test_nested_parts
created = nil
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
assert_equal 2,created.parts.size
assert_equal 2,created.parts.first.parts.size
-
+
assert_equal "multipart/mixed", created.content_type
assert_equal "multipart/alternative", created.parts.first.content_type
assert_equal "bar", created.parts.first.header['foo'].to_s
assert_equal "text/plain", created.parts.first.parts.first.content_type
assert_equal "text/html", created.parts.first.parts[1].content_type
@@ -364,11 +371,11 @@
assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_custom_template
expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
expected.body = "Hello there, \n\nMr. #{@recipient}"
@@ -380,30 +387,21 @@
assert_not_nil created
assert_equal expected.encoded, created.encoded
end
def test_custom_templating_extension
- #
# N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
expected.body = "Hello there, \n\nMr. #{@recipient}"
expected.from = "system@loudthinking.com"
expected.date = Time.local(2004, 12, 12)
-
+
# Stub the render method so no alternative renderers need be present.
ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
-
- # If the template is not registered, there should be no parts.
- created = nil
- assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
- assert_not_nil created
- assert_equal 0, created.parts.length
-
- ActionMailer::Base.register_template_extension('haml')
-
+
# Now that the template is registered, there should be one part. The text/plain part.
created = nil
assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
assert_not_nil created
assert_equal 2, created.parts.length
@@ -426,11 +424,11 @@
assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) }
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_cc_bcc
expected = new_mail
expected.to = @recipient
expected.subject = "testing bcc/cc"
expected.body = "Nothing to see here."
@@ -548,11 +546,11 @@
assert_equal 0, ActionMailer::Base.deliveries.size
ActionMailer::Base.perform_deliveries = true
TestMailer.deliver_signed_up(@recipient)
assert_equal 1, ActionMailer::Base.deliveries.size
end
-
+
def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
ActionMailer::Base.raise_delivery_errors = false
TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception)
assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) }
end
@@ -668,11 +666,11 @@
end
assert_not_nil ActionMailer::Base.deliveries.first
assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
-
+
def test_utf8_body_is_not_quoted
@recipient = "Foo áëô îü <extended@example.net>"
expected = new_mail "utf-8"
expected.to = quote_address_if_necessary @recipient, "utf-8"
expected.subject = "testing utf-8 body"
@@ -758,11 +756,11 @@
def test_multipart_with_mime_version
mail = TestMailer.create_multipart_with_mime_version(@recipient)
assert_equal "1.1", mail.mime_version
end
-
+
def test_multipart_with_utf8_subject
mail = TestMailer.create_multipart_with_utf8_subject(@recipient)
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
end
@@ -823,11 +821,11 @@
def test_implicitly_multipart_messages_with_charset
mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
assert_equal "multipart/alternative", mail.header['content-type'].body
-
+
assert_equal 'iso-8859-1', mail.parts[0].sub_header("content-type", "charset")
assert_equal 'iso-8859-1', mail.parts[1].sub_header("content-type", "charset")
assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset")
end
@@ -850,11 +848,11 @@
def test_various_newlines_multipart
mail = TestMailer.create_various_newlines_multipart(@recipient)
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body
assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body
end
-
+
def test_headers_removed_on_smtp_delivery
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_cc_bcc(@recipient)
assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
@@ -933,10 +931,29 @@
def test_return_path_with_deliver
ActionMailer::Base.delivery_method = :smtp
TestMailer.deliver_return_path
assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
end
+
+ def test_body_is_stored_as_an_ivar
+ mail = TestMailer.create_body_ivar(@recipient)
+ assert_equal "body: foo\nbar: baz", mail.body
+ end
+
+ def test_starttls_is_enabled_if_supported
+ MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
+ MockSMTP.any_instance.expects(:enable_starttls_auto)
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_signed_up(@recipient)
+ end
+
+ def test_starttls_is_disabled_if_not_supported
+ MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
+ MockSMTP.any_instance.expects(:enable_starttls_auto).never
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_signed_up(@recipient)
+ end
end
end # uses_mocha
class InheritableTemplateRootTest < Test::Unit::TestCase
@@ -973,7 +990,71 @@
assert_nothing_raised do
assert_emails 1 do
TestMailer.deliver_send
end
end
+ end
+end
+
+class RespondToTest < Test::Unit::TestCase
+ class RespondToMailer < ActionMailer::Base; end
+
+ def setup
+ set_delivery_method :test
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_respond_to_new
+ assert RespondToMailer.respond_to?(:new)
+ end
+
+ def test_should_respond_to_create_with_template_suffix
+ assert RespondToMailer.respond_to?(:create_any_old_template)
+ end
+
+ def test_should_respond_to_deliver_with_template_suffix
+ assert RespondToMailer.respond_to?(:deliver_any_old_template)
+ end
+
+ def test_should_not_respond_to_new_with_template_suffix
+ assert !RespondToMailer.respond_to?(:new_any_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
+ assert !RespondToMailer.respond_to?(:createany_old_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
+ assert !RespondToMailer.respond_to?(:deliverany_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
+ assert !RespondToMailer.respond_to?(:create_Any_old_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
+ assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
+ assert !RespondToMailer.respond_to?(:create_1_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
+ assert !RespondToMailer.respond_to?(:deliver_1_template)
+ end
+
+ def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
+ assert !RespondToMailer.respond_to?(:foo_deliver_template)
+ end
+
+ def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
+ error = assert_raises NoMethodError do
+ RespondToMailer.not_a_method
+ end
+
+ assert_match /undefined method.*not_a_method/, error.message
end
end