mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
131 tests, 309 assertions, 0 failures, 0 errors
This commit is contained in:
parent
f6f70540bb
commit
747d56881a
8 changed files with 56 additions and 64 deletions
|
@ -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
|
* 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
|
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)*
|
*2.3.2 [Final] (March 15, 2009)*
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ module ActionMailer
|
||||||
autoload :TestCase, 'action_mailer/test_case'
|
autoload :TestCase, 'action_mailer/test_case'
|
||||||
autoload :TestHelper, 'action_mailer/test_helper'
|
autoload :TestHelper, 'action_mailer/test_helper'
|
||||||
autoload :Utils, 'action_mailer/utils'
|
autoload :Utils, 'action_mailer/utils'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Text
|
module Text
|
||||||
|
@ -53,5 +54,5 @@ end
|
||||||
|
|
||||||
autoload :MailHelper, 'action_mailer/mail_helper'
|
autoload :MailHelper, 'action_mailer/mail_helper'
|
||||||
|
|
||||||
|
|
||||||
require '/Users/mikel/ruby_programs/mail/lib/mail'
|
require '/Users/mikel/ruby_programs/mail/lib/mail'
|
||||||
require 'action_mailer/vendor/tmail_compat'
|
|
||||||
|
|
|
@ -384,8 +384,9 @@ module ActionMailer #:nodoc:
|
||||||
# content-disposition set to "attachment".
|
# content-disposition set to "attachment".
|
||||||
def attachment(params, &block)
|
def attachment(params, &block)
|
||||||
params = { :content_type => params } if String === params
|
params = { :content_type => params } if String === params
|
||||||
params = { :disposition => "attachment",
|
params = { :content_disposition => "attachment",
|
||||||
:transfer_encoding => "base64" }.merge(params)
|
:content_transfer_encoding => "base64" }.merge(params)
|
||||||
|
params[:data] = params.delete(:body) if params[:body]
|
||||||
part(params, &block)
|
part(params, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -623,7 +624,7 @@ module ActionMailer #:nodoc:
|
||||||
m.body = normalize_new_lines(@parts.first.body)
|
m.body = normalize_new_lines(@parts.first.body)
|
||||||
else
|
else
|
||||||
@parts.each do |p|
|
@parts.each do |p|
|
||||||
m.parts << p
|
m.add_part(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
if real_content_type =~ /multipart/
|
if real_content_type =~ /multipart/
|
||||||
|
|
|
@ -43,7 +43,7 @@ module ActionMailer
|
||||||
# "to", "from", "cc", "bcc" and "reply-to" headers.
|
# "to", "from", "cc", "bcc" and "reply-to" headers.
|
||||||
def quote_address_if_necessary(address, charset)
|
def quote_address_if_necessary(address, charset)
|
||||||
if Array === address
|
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+(<.*>)$/
|
elsif address =~ /^(\S.*)\s+(<.*>)$/
|
||||||
address = $2
|
address = $2
|
||||||
phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
|
phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
|
||||||
|
|
|
@ -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
|
|
|
@ -232,7 +232,7 @@ class TestMailer < ActionMailer::Base
|
||||||
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
|
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def nested_multipart_with_body(recipient)
|
def nested_multipart_with_body(recipient)
|
||||||
|
@ -346,36 +346,38 @@ class ActionMailerTest < Test::Unit::TestCase
|
||||||
def test_nested_parts
|
def test_nested_parts
|
||||||
created = nil
|
created = nil
|
||||||
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
|
assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
|
||||||
assert_equal 2,created.parts.size
|
assert_equal 2, created.parts.size
|
||||||
assert_equal 2,created.parts.first.parts.size
|
assert_equal 2, created.parts.first.parts.size
|
||||||
|
|
||||||
assert_equal "multipart/mixed", created.content_type
|
assert_equal "multipart/mixed", created.content_type.string
|
||||||
assert_equal "multipart/alternative", created.parts.first.content_type
|
assert_equal "multipart/alternative", created.parts[0].content_type.string
|
||||||
assert_equal "bar", created.parts.first.header['foo'].to_s
|
assert_equal "bar", created.parts[0].header['foo'].decoded
|
||||||
assert_nil created.parts.first.charset
|
assert_nil created.parts[0].charset
|
||||||
assert_equal "text/plain", created.parts.first.parts.first.content_type
|
assert_equal "text/plain", created.parts[0].parts[0].content_type.string
|
||||||
assert_equal "text/html", created.parts.first.parts[1].content_type
|
assert_equal "text/html", created.parts[0].parts[1].content_type.string
|
||||||
assert_equal "application/octet-stream", created.parts[1].content_type
|
assert_equal "application/octet-stream", created.parts[1].content_type.string
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_parts_with_body
|
def test_nested_parts_with_body
|
||||||
created = nil
|
created = nil
|
||||||
TestMailer.create_nested_multipart_with_body(@recipient)
|
TestMailer.create_nested_multipart_with_body(@recipient)
|
||||||
assert_nothing_raised { created = 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 1,created.parts.size
|
||||||
assert_equal 2,created.parts.first.parts.size
|
assert_equal 2,created.parts.first.parts.size
|
||||||
|
|
||||||
assert_equal "multipart/mixed", created.content_type
|
assert_equal "multipart/mixed", created.content_type.string
|
||||||
assert_equal "multipart/alternative", created.parts.first.content_type
|
assert_equal "multipart/alternative", created.parts.first.content_type.string
|
||||||
assert_equal "Nothing to see here.", created.parts.first.parts.first.body
|
assert_equal "text/plain", created.parts.first.parts.first.content_type.string
|
||||||
assert_equal "text/plain", created.parts.first.parts.first.content_type
|
assert_equal "Nothing to see here.", created.parts.first.parts.first.body.decoded
|
||||||
assert_equal "text/html", created.parts.first.parts[1].content_type
|
assert_equal "text/html", created.parts.first.parts.second.content_type.string
|
||||||
|
assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.decoded
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_attachment_with_custom_header
|
def test_attachment_with_custom_header
|
||||||
created = nil
|
created = nil
|
||||||
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
|
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) }
|
||||||
created.encoded
|
|
||||||
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -817,7 +819,7 @@ EOF
|
||||||
|
|
||||||
created = TestMailer.create_utf8_body @recipient
|
created = TestMailer.create_utf8_body @recipient
|
||||||
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
|
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
|
||||||
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
|
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_receive_decodes_base64_encoded_mail
|
def test_receive_decodes_base64_encoded_mail
|
||||||
|
@ -892,18 +894,19 @@ EOF
|
||||||
def test_explicitly_multipart_messages
|
def test_explicitly_multipart_messages
|
||||||
mail = TestMailer.create_explicitly_multipart_example(@recipient)
|
mail = TestMailer.create_explicitly_multipart_example(@recipient)
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_nil mail.content_type
|
assert_equal 'multipart/mixed', mail.content_type.string
|
||||||
|
|
||||||
assert_equal "text/plain", mail.parts[0].content_type.string
|
assert_equal "text/plain", mail.parts[0].content_type.string
|
||||||
|
|
||||||
assert_equal "text/html", mail.parts[1].content_type.string
|
assert_equal "text/html", mail.parts[1].content_type.string
|
||||||
assert_equal "iso-8859-1", mail.parts[1].charset
|
assert_equal "iso-8859-1", mail.parts[1].charset
|
||||||
assert_equal "inline", mail.parts[1].content_disposition
|
|
||||||
|
|
||||||
assert_equal "image/jpeg", mail.parts[2].content_type.string
|
assert_equal "image/jpeg", mail.parts[2].content_type.string
|
||||||
assert_equal "attachment", mail.parts[2].content_disposition
|
assert_equal "attachment", mail.parts[2].content_disposition.disposition_type
|
||||||
assert_equal "foo.jpg", mail.parts[2].sub_header("content-disposition", "filename")
|
|
||||||
assert_equal "foo.jpg", mail.parts[2].sub_header("content-type", "name")
|
assert_equal "foo.jpg", mail.parts[2].content_disposition.filename
|
||||||
assert_nil mail.parts[2].sub_header("content-type", "charset")
|
assert_equal "foo.jpg", mail.parts[2].content_type.filename
|
||||||
|
assert_nil mail.parts[2].charset
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_explicitly_multipart_with_content_type
|
def test_explicitly_multipart_with_content_type
|
||||||
|
@ -915,7 +918,7 @@ EOF
|
||||||
def test_explicitly_multipart_with_invalid_content_type
|
def test_explicitly_multipart_with_invalid_content_type
|
||||||
mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
|
mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
|
||||||
assert_equal 3, mail.parts.length
|
assert_equal 3, mail.parts.length
|
||||||
assert_nil mail.content_type
|
assert_equal 'multipart/mixed', mail.content_type.string
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_implicitly_multipart_messages
|
def test_implicitly_multipart_messages
|
||||||
|
@ -1003,7 +1006,12 @@ EOF
|
||||||
def test_recursive_multipart_processing
|
def test_recursive_multipart_processing
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
||||||
mail = Mail.new(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_equal "This is the first part.\n\nAttachment: test.rb\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body.decoded
|
assert_equal(2, mail.parts.length)
|
||||||
|
assert_equal(4, mail.parts.first.parts.length)
|
||||||
|
assert_equal("This is the first part.", mail.parts.first.parts.first.body.decoded)
|
||||||
|
assert_equal("test.rb", mail.parts.first.parts.second.filename)
|
||||||
|
assert_equal("flowed", mail.parts.first.parts.fourth.content_type.parameters[:format])
|
||||||
|
assert_equal('smime.p7s', mail.parts.second.filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode_encoded_attachment_filename
|
def test_decode_encoded_attachment_filename
|
||||||
|
@ -1025,7 +1033,7 @@ EOF
|
||||||
|
|
||||||
def test_empty_header_values_omitted
|
def test_empty_header_values_omitted
|
||||||
result = TestMailer.create_unnamed_attachment(@recipient).encoded
|
result = TestMailer.create_unnamed_attachment(@recipient).encoded
|
||||||
assert_match %r{Content-Type: application/octet-stream[^;]}, result
|
assert_match %r{Content-Type: application/octet-stream;}, result
|
||||||
assert_match %r{Content-Disposition: attachment[^;]}, result
|
assert_match %r{Content-Disposition: attachment[^;]}, result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1049,7 +1057,7 @@ EOF
|
||||||
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
|
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient)
|
||||||
assert_equal 2, mail.parts.length
|
assert_equal 2, mail.parts.length
|
||||||
assert "text/plain", mail.parts[1].content_type.string
|
assert "text/plain", mail.parts[1].content_type.string
|
||||||
assert "utf-8", mail.parts[1].content_type['charset']
|
assert "utf-8", mail.parts[1].charset
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_custom_content_type_attributes
|
def test_custom_content_type_attributes
|
||||||
|
@ -1066,7 +1074,7 @@ EOF
|
||||||
def test_return_path_with_deliver
|
def test_return_path_with_deliver
|
||||||
ActionMailer::Base.delivery_method = :smtp
|
ActionMailer::Base.delivery_method = :smtp
|
||||||
TestMailer.deliver_return_path
|
TestMailer.deliver_return_path
|
||||||
assert_match %r{^Return-Path: <another@somewhere.test>}, 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
|
assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ class TestHelperMailerTest < ActionMailer::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_setup_creates_the_expected_mailer
|
def test_setup_creates_the_expected_mailer
|
||||||
assert @expected.is_a?(Mail)
|
assert @expected.is_a?(Mail::Message)
|
||||||
assert_equal "1.0", @expected.mime_version
|
assert_equal "1.0", @expected.mime_version.version
|
||||||
assert_equal "text/plain", @expected.content_type
|
assert_equal "text/plain", @expected.content_type.string
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mailer_class_is_correctly_inferred
|
def test_mailer_class_is_correctly_inferred
|
||||||
|
@ -125,7 +125,7 @@ class AnotherTestHelperMailerTest < ActionMailer::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_setup_shouldnt_conflict_with_mailer_setup
|
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
|
assert_equal 'a value', @test_var
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,10 +4,10 @@ class TMailMailTest < Test::Unit::TestCase
|
||||||
def test_body
|
def test_body
|
||||||
m = Mail.new
|
m = Mail.new
|
||||||
expected = 'something_with_underscores'
|
expected = 'something_with_underscores'
|
||||||
m.encoding = 'quoted-printable'
|
m.content_transfer_encoding = 'quoted-printable'
|
||||||
quoted_body = [expected].pack('*M')
|
quoted_body = [expected].pack('*M')
|
||||||
m.body = quoted_body
|
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
|
# CHANGED: body returns object, not string, Changed m.body to m.body.decoded
|
||||||
assert_equal expected, m.body.decoded
|
assert_equal expected, m.body.decoded
|
||||||
end
|
end
|
||||||
|
@ -16,8 +16,9 @@ class TMailMailTest < Test::Unit::TestCase
|
||||||
fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
|
fixture = File.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_nested_attachment")
|
||||||
mail = Mail.new(fixture)
|
mail = Mail.new(fixture)
|
||||||
assert_equal 2, mail.attachments.length
|
assert_equal 2, mail.attachments.length
|
||||||
assert_equal "image/png", mail.attachments.first.content_type
|
assert_equal "image/png", mail.attachments.first.mime_type
|
||||||
assert_equal 1902, mail.attachments.first.length
|
assert_equal 1902, mail.attachments.first.decoded.length
|
||||||
assert_equal "application/pkcs7-signature", mail.attachments.last.content_type
|
assert_equal "application/pkcs7-signature", mail.attachments.last.mime_type
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue