vendor/rails/actionmailer/test/mail_service_test.rb in radiant-0.7.2 vs vendor/rails/actionmailer/test/mail_service_test.rb in radiant-0.8.0

- 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,21 +271,26 @@ 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) self.class.received_body = mail.body end end -uses_mocha 'ActionMailerTest' do - class ActionMailerTest < Test::Unit::TestCase include ActionMailer::Quoting def encode( text, charset="utf-8" ) quoted_printable( text, charset ) @@ -319,14 +324,15 @@ 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_nil created.parts.first.charset assert_equal "text/plain", created.parts.first.parts.first.content_type assert_equal "text/html", created.parts.first.parts[1].content_type assert_equal "application/octet-stream", created.parts[1].content_type end @@ -364,11 +370,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 +386,23 @@ assert_not_nil created assert_equal expected.encoded, created.encoded end def test_custom_templating_extension - # + assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered" + # 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 +425,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 +547,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 +667,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 +757,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 @@ -799,10 +798,12 @@ assert_equal 3, mail.parts.length assert_nil mail.content_type end def test_implicitly_multipart_messages + assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" + mail = TestMailer.create_implicitly_multipart_example(@recipient) assert_equal 3, mail.parts.length assert_equal "1.0", mail.mime_version assert_equal "multipart/alternative", mail.content_type assert_equal "text/yaml", mail.parts[0].content_type @@ -812,10 +813,12 @@ assert_equal "text/html", mail.parts[2].content_type assert_equal "utf-8", mail.parts[2].sub_header("content-type", "charset") end def test_implicitly_multipart_messages_with_custom_order + assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" + mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"]) assert_equal 3, mail.parts.length assert_equal "text/html", mail.parts[0].content_type assert_equal "text/plain", mail.parts[1].content_type assert_equal "text/yaml", mail.parts[2].content_type @@ -823,11 +826,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 +853,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") @@ -915,10 +918,12 @@ end def test_multipart_with_template_path_with_dots mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient) assert_equal 2, mail.parts.length + assert_equal 'text/plain', mail.parts[0].content_type + assert_equal 'utf-8', mail.parts[0].charset end def test_custom_content_type_attributes mail = TestMailer.create_custom_content_type_attributes assert_match %r{format=flowed}, mail['content-type'].to_s @@ -932,25 +937,55 @@ 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] + assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s end -end -end # uses_mocha + 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 + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + 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 + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + 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 + + def test_starttls_is_not_enabled + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = false + MockSMTP.any_instance.expects(:respond_to?).never + MockSMTP.any_instance.expects(:enable_starttls_auto).never + ActionMailer::Base.delivery_method = :smtp + TestMailer.deliver_signed_up(@recipient) + ensure + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + end +end + class InheritableTemplateRootTest < Test::Unit::TestCase def test_attr expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots" - assert_equal expected, FunkyPathMailer.template_root + assert_equal expected, FunkyPathMailer.template_root.to_s sub = Class.new(FunkyPathMailer) sub.template_root = 'test/path' - assert_equal 'test/path', sub.template_root - assert_equal expected, FunkyPathMailer.template_root + assert_equal 'test/path', sub.template_root.to_s + assert_equal expected, FunkyPathMailer.template_root.to_s end end class MethodNamingTest < Test::Unit::TestCase class TestMailer < ActionMailer::Base @@ -973,7 +1008,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_raise NoMethodError do + RespondToMailer.not_a_method + end + + assert_match /undefined method.*not_a_method/, error.message end end