2010-01-20 07:46:59 -05:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'abstract_unit'
|
|
|
|
|
2010-01-20 06:25:09 -05:00
|
|
|
# class Notifier < ActionMailer::Base
|
|
|
|
# delivers_from 'notifications@example.com'
|
|
|
|
#
|
|
|
|
# def welcome(user)
|
|
|
|
# @user = user # available to the view
|
|
|
|
# mail(:subject => 'Welcome!', :to => user.email_address)
|
|
|
|
# # auto renders both welcome.text.erb and welcome.html.erb
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def goodbye(user)
|
2010-01-20 08:10:22 -05:00
|
|
|
# headers["X-SPAM"] = 'Not-SPAM'
|
2010-01-20 06:25:09 -05:00
|
|
|
# mail(:subject => 'Goodbye', :to => user.email_address) do |format|
|
|
|
|
# format.html { render "shared_template "}
|
|
|
|
# format.text # goodbye.text.erb
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def surprise(user, gift)
|
|
|
|
# attachments[gift.name] = File.read(gift.path)
|
|
|
|
# mail(:subject => 'Surprise!', :to => user.email_address) do |format|
|
|
|
|
# format.html(:charset => "ascii") # surprise.html.erb
|
|
|
|
# format.text(:transfer_encoding => "base64") # surprise.text.erb
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def special_surprise(user, gift)
|
|
|
|
# attachments[gift.name] = { :content_type => "application/x-gzip", :content => File.read(gift.path) }
|
|
|
|
# mail(:to => 'special@example.com') # subject not required
|
|
|
|
# # auto renders both special_surprise.text.erb and special_surprise.html.erb
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2010-01-20 07:46:59 -05:00
|
|
|
# mail = Notifier.welcome(user) # => returns a Mail object
|
|
|
|
# mail.deliver
|
|
|
|
#
|
2010-01-20 06:25:09 -05:00
|
|
|
# Notifier.welcome(user).deliver # => creates and sends the Mail in one step
|
2010-01-20 07:46:59 -05:00
|
|
|
class BaseTest < Test::Unit::TestCase
|
2010-01-20 06:25:09 -05:00
|
|
|
|
2010-01-20 07:46:59 -05:00
|
|
|
class TestMailer < ActionMailer::Base
|
2010-01-20 08:10:22 -05:00
|
|
|
|
2010-01-20 07:46:59 -05:00
|
|
|
def welcome(hash = {})
|
|
|
|
hash = {:to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com',
|
|
|
|
:subject => 'The first email on new API!'}.merge!(hash)
|
|
|
|
mail(hash)
|
|
|
|
end
|
2010-01-20 08:10:22 -05:00
|
|
|
|
2010-01-21 04:03:55 -05:00
|
|
|
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
|
|
|
|
|
2010-01-20 07:46:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_the_method_call_to_mail_does_not_raise_error
|
|
|
|
assert_nothing_raised { TestMailer.deliver_welcome }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_set_the_headers_of_the_mail_message
|
|
|
|
email = TestMailer.deliver_welcome
|
|
|
|
assert_equal(email.to, ['mikel@test.lindsaar.net'])
|
|
|
|
assert_equal(email.from, ['jose@test.plataformatec.com'])
|
|
|
|
assert_equal(email.subject, 'The first email on new API!')
|
|
|
|
end
|
2010-01-20 08:10:22 -05:00
|
|
|
|
|
|
|
def test_should_allow_all_headers_set
|
|
|
|
@time = Time.now
|
|
|
|
email = TestMailer.deliver_welcome(:bcc => 'bcc@test.lindsaar.net',
|
|
|
|
:cc => 'cc@test.lindsaar.net',
|
|
|
|
:content_type => 'multipart/mixed',
|
|
|
|
:charset => 'iso-8559-1',
|
|
|
|
:mime_version => '2.0',
|
|
|
|
:reply_to => 'reply-to@test.lindsaar.net',
|
|
|
|
:date => @time)
|
|
|
|
assert_equal(email.bcc, ['bcc@test.lindsaar.net'])
|
|
|
|
assert_equal(email.cc, ['cc@test.lindsaar.net'])
|
|
|
|
assert_equal(email.content_type, 'multipart/mixed')
|
|
|
|
assert_equal(email.charset, 'iso-8559-1')
|
|
|
|
assert_equal(email.mime_version, '2.0')
|
|
|
|
assert_equal(email.reply_to, ['reply-to@test.lindsaar.net'])
|
|
|
|
assert_equal(email.date, @time)
|
2010-01-20 07:46:59 -05:00
|
|
|
end
|
|
|
|
|
2010-01-20 08:10:22 -05:00
|
|
|
# def test_should_allow_custom_headers_to_be_set
|
|
|
|
# email = TestMailer.deliver_welcome
|
|
|
|
# assert_equal("Not SPAM", email['X-SPAM'])
|
|
|
|
# end
|
|
|
|
|
2010-01-21 04:03:55 -05:00
|
|
|
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
|
|
|
|
|
2010-01-20 08:10:22 -05:00
|
|
|
def test_should_use_class_defaults
|
2010-01-20 07:46:59 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# def test_that_class_defaults_are_set_on_instantiation
|
|
|
|
# pending
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def test_should_set_the_subject_from_i18n
|
|
|
|
# pending
|
|
|
|
# end
|
2010-01-20 06:25:09 -05:00
|
|
|
|
2010-01-20 07:46:59 -05:00
|
|
|
end
|