mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding tests for attachments['blah.rb'] = {} et al
This commit is contained in:
parent
fbdbac2b88
commit
3829f9ecfd
5 changed files with 44 additions and 3 deletions
|
@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|||
s.homepage = "http://www.rubyonrails.org"
|
||||
|
||||
s.add_dependency('actionpack', '= 3.0.pre')
|
||||
s.add_dependency('mail', '~> 2.0.1')
|
||||
s.add_dependency('mail', '~> 2.0.2')
|
||||
|
||||
s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
|
||||
s.has_rdoc = true
|
||||
|
|
|
@ -19,6 +19,7 @@ module ActionMailer
|
|||
end
|
||||
|
||||
part = Mail::Part.new(params)
|
||||
|
||||
yield part if block_given?
|
||||
@parts << part
|
||||
end
|
||||
|
@ -29,7 +30,16 @@ module ActionMailer
|
|||
super # Run deprecation hooks
|
||||
|
||||
params = { :content_type => params } if String === params
|
||||
params = { :content_disposition => "attachment",
|
||||
|
||||
if filename = params.delete(:filename)
|
||||
content_disposition = "attachment; filename=\"#{File.basename(filename)}\""
|
||||
else
|
||||
content_disposition = "attachment"
|
||||
end
|
||||
|
||||
params[:content] = params.delete(:data) if params[:data]
|
||||
|
||||
params = { :content_disposition => content_disposition,
|
||||
:content_transfer_encoding => "base64" }.merge(params)
|
||||
|
||||
part(params, &block)
|
||||
|
|
|
@ -16,5 +16,10 @@ module Mail
|
|||
end
|
||||
end
|
||||
|
||||
def original_filename
|
||||
STDERR.puts("Message#original_filename is deprecated, please call Message#filename.\n#{caller}")
|
||||
filename
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -42,12 +42,18 @@ class BaseTest < Test::Unit::TestCase
|
|||
class TestMailer < ActionMailer::Base
|
||||
|
||||
def welcome(hash = {})
|
||||
headers['X-SPAM'] = "Not SPAM"
|
||||
hash = {:to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com',
|
||||
:subject => 'The first email on new API!'}.merge!(hash)
|
||||
mail(hash)
|
||||
end
|
||||
|
||||
def invoice(hash = {})
|
||||
attachments['invoice.pdf'] = 'This is test File content'
|
||||
hash = {:to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com',
|
||||
:subject => 'Your invoice is attached'}.merge!(hash)
|
||||
mail(hash)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_the_method_call_to_mail_does_not_raise_error
|
||||
|
@ -84,6 +90,25 @@ class BaseTest < Test::Unit::TestCase
|
|||
# assert_equal("Not SPAM", email['X-SPAM'])
|
||||
# end
|
||||
|
||||
def test_should_allow_you_to_send_an_attachment
|
||||
assert_nothing_raised { TestMailer.deliver_invoice }
|
||||
end
|
||||
|
||||
def test_should_allow_you_to_send_an_attachment
|
||||
email = TestMailer.deliver_invoice
|
||||
assert_equal(1, email.attachments.length)
|
||||
end
|
||||
|
||||
def test_should_allow_you_to_send_an_attachment
|
||||
email = TestMailer.deliver_invoice
|
||||
assert_equal('invoice.pdf', email.attachments[0].filename)
|
||||
end
|
||||
|
||||
def test_should_allow_you_to_send_an_attachment
|
||||
email = TestMailer.deliver_invoice
|
||||
assert_equal('This is test File content', email.attachments['invoice.pdf'].decoded)
|
||||
end
|
||||
|
||||
def test_should_use_class_defaults
|
||||
|
||||
end
|
||||
|
|
|
@ -898,6 +898,7 @@ EOF
|
|||
assert_equal "iso-8859-1", mail.parts[1].charset
|
||||
|
||||
assert_equal "image/jpeg", mail.parts[2].mime_type
|
||||
|
||||
assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type
|
||||
assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename
|
||||
assert_equal "foo.jpg", mail.parts[2][:content_type].filename
|
||||
|
|
Loading…
Reference in a new issue