提交 d588bbd4 编写于 作者: D David Chelimsky 提交者: José Valim

Move ActionMailer::TC to AV::TC::Behavior

[#4843 state:resolved]
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 7508c0e9
...@@ -8,55 +8,69 @@ def initialize(name) ...@@ -8,55 +8,69 @@ def initialize(name)
end end
class TestCase < ActiveSupport::TestCase class TestCase < ActiveSupport::TestCase
include TestHelper module Behavior
extend ActiveSupport::Concern
setup :initialize_test_deliveries include TestHelper
setup :set_expected_mail
class << self module ClassMethods
def tests(mailer) def tests(mailer)
write_inheritable_attribute(:mailer_class, mailer) write_inheritable_attribute(:mailer_class, mailer)
end end
def mailer_class def mailer_class
if mailer = read_inheritable_attribute(:mailer_class) if mailer = read_inheritable_attribute(:mailer_class)
mailer mailer
else else
tests determine_default_mailer(name) tests determine_default_mailer(name)
end
end end
end
def determine_default_mailer(name) def determine_default_mailer(name)
name.sub(/Test$/, '').constantize name.sub(/Test$/, '').constantize
rescue NameError => e rescue NameError => e
raise NonInferrableMailerError.new(name) raise NonInferrableMailerError.new(name)
end
end end
end
protected module InstanceMethods
def initialize_test_deliveries
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
end
def set_expected_mail protected
@expected = Mail.new
@expected.content_type ["text", "plain", { "charset" => charset }]
@expected.mime_version = '1.0'
end
private def initialize_test_deliveries
def charset ActionMailer::Base.delivery_method = :test
"UTF-8" ActionMailer::Base.perform_deliveries = true
end ActionMailer::Base.deliveries.clear
end
def set_expected_mail
@expected = Mail.new
@expected.content_type ["text", "plain", { "charset" => charset }]
@expected.mime_version = '1.0'
end
private
def charset
"UTF-8"
end
def encode(subject)
Mail::Encodings.q_value_encode(subject, charset)
end
def encode(subject) def read_fixture(action)
Mail::Encodings.q_value_encode(subject, charset) IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
end
end end
def read_fixture(action) included do
IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action)) setup :initialize_test_deliveries
setup :set_expected_mail
end end
end
include Behavior
end end
end end
module ActionMailer module ActionMailer
module TestHelper module TestHelper
extend ActiveSupport::Concern
# Asserts that the number of emails sent matches the given number. # Asserts that the number of emails sent matches the given number.
# #
# def test_emails # def test_emails
...@@ -57,11 +59,3 @@ def assert_no_emails(&block) ...@@ -57,11 +59,3 @@ def assert_no_emails(&block)
end end
end end
end end
module Test
module Unit
class TestCase
include ActionMailer::TestHelper
end
end
end
...@@ -1113,6 +1113,8 @@ def test_attr ...@@ -1113,6 +1113,8 @@ def test_attr
end end
class MethodNamingTest < ActiveSupport::TestCase class MethodNamingTest < ActiveSupport::TestCase
include ActionMailer::TestHelper
class TestMailer < ActionMailer::Base class TestMailer < ActionMailer::Base
def send def send
body 'foo' body 'foo'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册