diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 88 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 10 | ||||
-rw-r--r-- | actionmailer/lib/rails/generators/mailer/templates/mailer.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_service_test.rb | 2 |
7 files changed, 62 insertions, 50 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 6e2c441e53..f0b9368874 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [beta 4] (June 8th, 2010)* +* subject is automatically looked up on I18n using mailer_name and action_name as scope as in t(".subject") [JK] + * Changed encoding behaviour of mail, so updated tests in actionmailer and bumped mail version to 2.2.1 [ML] * Added ability to pass Proc objects to the defaults hash [ML] diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f0b2604a66..fff44e50c1 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -209,7 +209,7 @@ module ActionMailer #:nodoc: # # <%= image_tag attachments['photo.png'].url -%> # - # As we are using ActionView's +image_tag+ method, you can pass in any other options you want: + # As we are using Action View's +image_tag+ method, you can pass in any other options you want: # # <h1>Please Don't Cringe</h1> # @@ -657,7 +657,7 @@ module ActionMailer #:nodoc: def default_i18n_subject #:nodoc: mailer_scope = self.class.mailer_name.gsub('/', '.') - I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize) + I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize) end def collect_responses_and_parts_order(headers) #:nodoc: @@ -739,7 +739,7 @@ module ActionMailer #:nodoc: end # This module will complain if the user tries to set default_url_options - # directly instead of through the config object. In ActionMailer's Railtie, + # directly instead of through the config object. In Action Mailer's Railtie, # we include the url_helpers of the router, which will override this module extend DeprecatedUrlOptions 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 diff --git a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb index 7343eb28b3..21e5918ecb 100644 --- a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb +++ b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb @@ -5,7 +5,7 @@ class <%= class_name %> < ActionMailer::Base # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # - # en.actionmailer.<%= file_name %>.<%= action %>.subject + # en.<%= file_name %>.<%= action %>.subject # def <%= action %> @greeting = "Hi" diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index b9226196fd..88e38a583b 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -325,7 +325,7 @@ class BaseTest < ActiveSupport::TestCase email = BaseMailer.welcome(:subject => nil) assert_equal "Welcome", email.subject - I18n.backend.store_translations('en', :actionmailer => {:base_mailer => {:welcome => {:subject => "New Subject!"}}}) + I18n.backend.store_translations('en', :base_mailer => {:welcome => {:subject => "New Subject!"}}) email = BaseMailer.welcome(:subject => nil) assert_equal "New Subject!", email.subject end diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index e8e8fcedc9..527b37218a 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -1113,6 +1113,8 @@ class InheritableTemplateRootTest < ActiveSupport::TestCase end class MethodNamingTest < ActiveSupport::TestCase + include ActionMailer::TestHelper + class TestMailer < ActionMailer::Base def send body 'foo' |