1 require 'active_support/test_case'
4 class NonInferrableMailerError
< ::StandardError
6 super "Unable to determine the mailer to test from #{name}. " +
7 "You'll need to specify it using tests YourMailer in your " +
12 class TestCase
< ActiveSupport
::TestCase
13 include Quoting
, TestHelper
15 setup
:initialize_test_deliveries
16 setup
:set_expected_mail
20 write_inheritable_attribute(:mailer_class, mailer
)
24 if mailer
= read_inheritable_attribute(:mailer_class)
27 tests
determine_default_mailer(name
)
31 def determine_default_mailer(name
)
32 name
.sub(/Test$/, '').constantize
34 raise NonInferrableMailerError
.new(name
)
39 def initialize_test_deliveries
40 ActionMailer
::Base.delivery_method
= :test
41 ActionMailer
::Base.perform_deliveries
= true
42 ActionMailer
::Base.deliveries
= []
46 @expected = TMail
::Mail.new
47 @expected.set_content_type
"text", "plain", { "charset" => charset
}
48 @expected.mime_version
= '1.0'
57 quoted_printable(subject
, charset
)
60 def read_fixture(action
)
61 IO
.readlines(File
.join(RAILS_ROOT
, 'test', 'fixtures', self.class.mailer_class
.name
.underscore
, action
))