aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-26 02:21:21 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-26 02:21:21 +0000
commit2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab (patch)
tree3ad613f6c73cd9fef243f7586dfcf3b6f329105b /actionmailer/lib
parent2bfd6772a4f3f9e0ff395cfd415dafbc1c9dec80 (diff)
downloadrails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.tar.gz
rails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.tar.bz2
rails-2cc0cac3efce92bf9d0e8636f2889c37ca9f57ab.zip
Introduce TestCase subclasses for testing rails applications allowing tests to be DRY'd up a bit and to provide a path toward tidying up our monkeypatching of test/unit.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8022 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib')
-rw-r--r--actionmailer/lib/action_mailer/test_case.rb59
1 files changed, 59 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb
new file mode 100644
index 0000000000..5d0ddddce9
--- /dev/null
+++ b/actionmailer/lib/action_mailer/test_case.rb
@@ -0,0 +1,59 @@
+require 'active_support/test_case'
+
+module ActionMailer
+ class NonInferrableMailerError < ::StandardError
+ def initialize(name)
+ super "Unable to determine the mailer to test from #{name}. " +
+ "You'll need to specify it using tests YourMailer in your " +
+ "test case definition"
+ end
+ end
+ # New Test Super class for forward compatibility.
+ # To override
+ class TestCase < ActiveSupport::TestCase
+ include ActionMailer::Quoting
+
+ class << self
+ 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)
+ end
+ end
+
+ def determine_default_mailer(name)
+ name.sub(/Test$/, '').constantize
+ rescue NameError => e
+ raise NonInferrableMailerError.new(name)
+ end
+ end
+
+ def setup
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @expected = TMail::Mail.new
+ @expected.set_content_type "text", "plain", { "charset" => charset }
+ @expected.mime_version = '1.0'
+ end
+
+ private
+ def charset
+ "utf-8"
+ end
+
+ def encode(subject)
+ quoted_printable(subject, charset)
+ end
+
+ def read_fixture(action)
+ IO.readlines(File.join(RAILS_ROOT, 'test', 'fixtures', mailer_class.name.underscore, action))
+ end
+ end
+end