From 747d56881a07d4636fbaceb1542579d5e02daddd Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 22 Nov 2009 23:20:57 +1100 Subject: [PATCH] 131 tests, 309 assertions, 0 failures, 0 errors --- actionmailer/CHANGELOG | 3 + actionmailer/lib/action_mailer.rb | 3 +- actionmailer/lib/action_mailer/base.rb | 7 +- actionmailer/lib/action_mailer/quoting.rb | 2 +- .../lib/action_mailer/vendor/tmail_compat.rb | 22 ------- actionmailer/test/mail_service_test.rb | 64 +++++++++++-------- actionmailer/test/test_helper_test.rb | 8 +-- actionmailer/test/tmail_test.rb | 11 ++-- 8 files changed, 56 insertions(+), 64 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/vendor/tmail_compat.rb diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 560ff3c426..0d16540661 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -20,6 +20,9 @@ * There is no idea of a "sub_head" in Mail. A part is just a Message with some extra functionality, so it just has a "header" like a normal mail message + +* When you want to add a nested part, you now need to use "add_part(params)" instead of "part(params)" This + creates a Mail gem Part object *2.3.2 [Final] (March 15, 2009)* diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 006e865cf1..9281008cd4 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -41,6 +41,7 @@ module ActionMailer autoload :TestCase, 'action_mailer/test_case' autoload :TestHelper, 'action_mailer/test_helper' autoload :Utils, 'action_mailer/utils' + end module Text @@ -53,5 +54,5 @@ end autoload :MailHelper, 'action_mailer/mail_helper' + require '/Users/mikel/ruby_programs/mail/lib/mail' -require 'action_mailer/vendor/tmail_compat' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d0924f714a..3d0ac49c34 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -384,8 +384,9 @@ module ActionMailer #:nodoc: # content-disposition set to "attachment". def attachment(params, &block) params = { :content_type => params } if String === params - params = { :disposition => "attachment", - :transfer_encoding => "base64" }.merge(params) + params = { :content_disposition => "attachment", + :content_transfer_encoding => "base64" }.merge(params) + params[:data] = params.delete(:body) if params[:body] part(params, &block) end @@ -623,7 +624,7 @@ module ActionMailer #:nodoc: m.body = normalize_new_lines(@parts.first.body) else @parts.each do |p| - m.parts << p + m.add_part(p) end if real_content_type =~ /multipart/ diff --git a/actionmailer/lib/action_mailer/quoting.rb b/actionmailer/lib/action_mailer/quoting.rb index 94fa042002..b30441f9de 100644 --- a/actionmailer/lib/action_mailer/quoting.rb +++ b/actionmailer/lib/action_mailer/quoting.rb @@ -43,7 +43,7 @@ module ActionMailer # "to", "from", "cc", "bcc" and "reply-to" headers. def quote_address_if_necessary(address, charset) if Array === address - address.map { |a| quote_address_if_necessary(a, charset) } + address.map { |a| quote_address_if_necessary(a, charset) }.join(", ") elsif address =~ /^(\S.*)\s+(<.*>)$/ address = $2 phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset) diff --git a/actionmailer/lib/action_mailer/vendor/tmail_compat.rb b/actionmailer/lib/action_mailer/vendor/tmail_compat.rb deleted file mode 100644 index 0e240eb478..0000000000 --- a/actionmailer/lib/action_mailer/vendor/tmail_compat.rb +++ /dev/null @@ -1,22 +0,0 @@ -# TMail Compatibility File -# Created in 1.2 of Mail. Will be deprecated -STDERR.puts("DEPRECATION WARNING, Mail running in TMail compatibility mode. This will be deprecated soon.") - -class Mail::Message - - def set_content_disposition(*args) - STDERR.puts("DEPRECATION WARNING, Message#set_content_disposition is deprecated, please use Message#content_disposition") - content_disposition(args) - end - - def encoding=(val) - STDERR.puts("DEPRECATION WARNING, Message#encoding= is deprecated, please use Message#content_transfer_encoding") - content_transfer_encoding(val) - end - - def quoted_body - STDERR.puts("DEPRECATION WARNING, Body#quoted_body is deprecated, please use Message => Body#encoded") - body.decoded - end - -end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 6ed7f20837..c4d664d7e5 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -232,7 +232,7 @@ class TestMailer < ActionMailer::Base p.part :content_type => "text/html", :body => "test HTML
\nline #2" end - attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz" + attachment :content_type => "application/octet-stream", :filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz" end def nested_multipart_with_body(recipient) @@ -346,36 +346,38 @@ class ActionMailerTest < Test::Unit::TestCase 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 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 + assert_equal "multipart/mixed", created.content_type.string + assert_equal "multipart/alternative", created.parts[0].content_type.string + assert_equal "bar", created.parts[0].header['foo'].decoded + assert_nil created.parts[0].charset + assert_equal "text/plain", created.parts[0].parts[0].content_type.string + assert_equal "text/html", created.parts[0].parts[1].content_type.string + assert_equal "application/octet-stream", created.parts[1].content_type.string + end def test_nested_parts_with_body created = nil TestMailer.create_nested_multipart_with_body(@recipient) assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)} + assert_equal 1,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 "Nothing to see here.", created.parts.first.parts.first.body - assert_equal "text/plain", created.parts.first.parts.first.content_type - assert_equal "text/html", created.parts.first.parts[1].content_type + assert_equal "multipart/mixed", created.content_type.string + assert_equal "multipart/alternative", created.parts.first.content_type.string + assert_equal "text/plain", created.parts.first.parts.first.content_type.string + assert_equal "Nothing to see here.", created.parts.first.parts.first.body.decoded + assert_equal "text/html", created.parts.first.parts.second.content_type.string + assert_equal "test HTML
", created.parts.first.parts.second.body.decoded end def test_attachment_with_custom_header created = nil assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) } - created.encoded assert created.parts.any? { |p| p.header['content-id'].to_s == "" } end @@ -817,7 +819,7 @@ EOF created = TestMailer.create_utf8_body @recipient assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= \r/, created.encoded) - assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= , Example Recipient , \r\n\tExample Recipient }, MockSMTP.deliveries[0][0] + assert_match %r{^Return-Path: another@somewhere.test}, MockSMTP.deliveries[0][0] assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 92527dcef9..8e4254411c 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -18,9 +18,9 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_setup_creates_the_expected_mailer - assert @expected.is_a?(Mail) - assert_equal "1.0", @expected.mime_version - assert_equal "text/plain", @expected.content_type + assert @expected.is_a?(Mail::Message) + assert_equal "1.0", @expected.mime_version.version + assert_equal "text/plain", @expected.content_type.string end def test_mailer_class_is_correctly_inferred @@ -125,7 +125,7 @@ class AnotherTestHelperMailerTest < ActionMailer::TestCase end def test_setup_shouldnt_conflict_with_mailer_setup - assert @expected.is_a?(Mail) + assert @expected.is_a?(Mail::Message) assert_equal 'a value', @test_var end end diff --git a/actionmailer/test/tmail_test.rb b/actionmailer/test/tmail_test.rb index 2a3f2a9e55..5d895f3790 100644 --- a/actionmailer/test/tmail_test.rb +++ b/actionmailer/test/tmail_test.rb @@ -4,10 +4,10 @@ class TMailMailTest < Test::Unit::TestCase def test_body m = Mail.new expected = 'something_with_underscores' - m.encoding = 'quoted-printable' + m.content_transfer_encoding = 'quoted-printable' quoted_body = [expected].pack('*M') m.body = quoted_body - assert_equal "something_with_underscores=\n", m.quoted_body + assert_equal "something_with_underscores=\r\n", m.body.encoded # CHANGED: body returns object, not string, Changed m.body to m.body.decoded assert_equal expected, m.body.decoded end @@ -16,8 +16,9 @@ class TMailMailTest < Test::Unit::TestCase fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment") mail = Mail.new(fixture) assert_equal 2, mail.attachments.length - assert_equal "image/png", mail.attachments.first.content_type - assert_equal 1902, mail.attachments.first.length - assert_equal "application/pkcs7-signature", mail.attachments.last.content_type + assert_equal "image/png", mail.attachments.first.mime_type + assert_equal 1902, mail.attachments.first.decoded.length + assert_equal "application/pkcs7-signature", mail.attachments.last.mime_type end + end