diff options
author | David Chelimsky <dchelimsky@gmail.com> | 2010-06-12 09:18:42 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-12 15:34:31 +0200 |
commit | d588bbd4311fc2060167bbaa021209a91641ba11 (patch) | |
tree | 6757aa361746705bbdcb84946cdd258394a952fa /actionmailer/lib/action_mailer | |
parent | 7508c0e9d3b126da1a443272550b80c6744e6f39 (diff) | |
download | rails-d588bbd4311fc2060167bbaa021209a91641ba11.tar.gz rails-d588bbd4311fc2060167bbaa021209a91641ba11.tar.bz2 rails-d588bbd4311fc2060167bbaa021209a91641ba11.zip |
Move ActionMailer::TC to AV::TC::Behavior
[#4843 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 88 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 10 |
2 files changed, 53 insertions, 45 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index d4874c6dbf..b91eed592a 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -8,55 +8,69 @@ module ActionMailer end class TestCase < ActiveSupport::TestCase - include TestHelper + module Behavior + extend ActiveSupport::Concern - setup :initialize_test_deliveries - setup :set_expected_mail + include TestHelper - class << self - def tests(mailer) - write_inheritable_attribute(:mailer_class, mailer) - end + module ClassMethods + def tests(mailer) + write_inheritable_attribute(:mailer_class, mailer) + end - def mailer_class - if mailer = read_inheritable_attribute(:mailer_class) - mailer - else - tests determine_default_mailer(name) + def mailer_class + if mailer = read_inheritable_attribute(:mailer_class) + mailer + else + tests determine_default_mailer(name) + end end - end - def determine_default_mailer(name) - name.sub(/Test$/, '').constantize - rescue NameError => e - raise NonInferrableMailerError.new(name) + def determine_default_mailer(name) + name.sub(/Test$/, '').constantize + rescue NameError => e + raise NonInferrableMailerError.new(name) + end end - end - protected - def initialize_test_deliveries - ActionMailer::Base.delivery_method = :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - end + module InstanceMethods - def set_expected_mail - @expected = Mail.new - @expected.content_type ["text", "plain", { "charset" => charset }] - @expected.mime_version = '1.0' - end + protected - private - def charset - "UTF-8" - end + def initialize_test_deliveries + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + 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) - Mail::Encodings.q_value_encode(subject, charset) + def read_fixture(action) + IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action)) + end end - def read_fixture(action) - IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action)) + included do + setup :initialize_test_deliveries + setup :set_expected_mail end + end + + include Behavior + end end diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 3a1612442f..5beab87ad2 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -1,5 +1,7 @@ module ActionMailer module TestHelper + extend ActiveSupport::Concern + # Asserts that the number of emails sent matches the given number. # # def test_emails @@ -57,11 +59,3 @@ module ActionMailer end end end - -module Test - module Unit - class TestCase - include ActionMailer::TestHelper - end - end -end |