提交 99f8d4fe 编写于 作者: D Dmitry Polushkin

add test coverage for the action mailer

上级 a8e1538b
......@@ -26,27 +26,9 @@
FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__))
ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
class MockSMTP
def self.deliveries
@@deliveries
end
def initialize
@@deliveries = []
end
def sendmail(mail, from, to)
@@deliveries << [mail, from, to]
end
def start(*args)
yield self
end
end
class Net::SMTP
def self.new(*args)
MockSMTP.new
class Rails
def self.root
File.expand_path('../', File.dirname(__FILE__))
end
end
......
......@@ -31,25 +31,10 @@ def test_asset_host_as_string
def test_asset_host_as_one_argument_proc
AssetHostMailer.config.asset_host = Proc.new { |source|
if source.starts_with?('/images')
"http://images.example.com"
else
"http://assets.example.com"
'http://images.example.com'
end
}
mail = AssetHostMailer.email_with_asset
assert_equal %Q{<img alt="Somelogo" src="http://images.example.com/images/somelogo.png" />}, mail.body.to_s.strip
end
def test_asset_host_as_two_argument_proc
ActionController::Base.config.asset_host = Proc.new {|source,request|
if request && request.ssl?
"https://www.example.com"
else
"http://www.example.com"
end
}
mail = nil
assert_nothing_raised { mail = AssetHostMailer.email_with_asset }
assert_equal %Q{<img alt="Somelogo" src="http://www.example.com/images/somelogo.png" />}, mail.body.to_s.strip
end
end
......@@ -108,6 +108,7 @@ def welcome(hash={})
end
test "delivery method can be customized per instance" do
Mail::SMTP.any_instance.expects(:deliver!)
email = DeliveryMailer.welcome.deliver
assert_instance_of Mail::SMTP, email.delivery_method
email = DeliveryMailer.welcome(delivery_method: :test).deliver
......@@ -117,7 +118,6 @@ def welcome(hash={})
test "delivery method can be customized in subclasses not changing the parent" do
DeliveryMailer.delivery_method = :test
assert_equal :smtp, ActionMailer::Base.delivery_method
$BREAK = true
email = DeliveryMailer.welcome.deliver
assert_instance_of Mail::TestMailer, email.delivery_method
end
......
......@@ -37,6 +37,7 @@ def app
end
def test_send_mail
Mail::SMTP.any_instance.expects(:deliver!)
with_translation 'de', email_subject: '[Anmeldung] Willkommen' do
get '/test/send_mail'
assert_equal "Mail sent - Subject: [Anmeldung] Willkommen", @response.body
......
# encoding: utf-8
require 'abstract_unit'
class TestHelperMailer < ActionMailer::Base
......@@ -36,6 +37,14 @@ def test_charset_is_utf_8
assert_equal "UTF-8", charset
end
def test_encode
assert_equal '=?UTF-8?Q?This_is_=E3=81=82_string?=', encode('This is あ string')
end
def test_read_fixture
assert_equal ['Welcome!'], read_fixture('welcome')
end
def test_assert_emails
assert_nothing_raised do
assert_emails 1 do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册