aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorOlek Janiszewski <olek.janiszewski@gmail.com>2013-01-23 19:22:39 +0100
committerOlek Janiszewski <olek.janiszewski@gmail.com>2013-01-24 15:29:24 +0100
commit57bfbc249e2af753163788d07ac7a658b4f5484a (patch)
treed3ee35a6083d7b3cd393dd8ff2e818031799f792 /actionmailer/test
parent1b75b94de6d474d56a6c47e74bdbd985ec14087b (diff)
downloadrails-57bfbc249e2af753163788d07ac7a658b4f5484a.tar.gz
rails-57bfbc249e2af753163788d07ac7a658b4f5484a.tar.bz2
rails-57bfbc249e2af753163788d07ac7a658b4f5484a.zip
Allow passing interpolations to `#default_i18n_subject`, e.g.:
# config/locales/en.yml en: user_mailer: welcome: subject: 'Hello, %{username}' # app/mailers/user_mailer.rb class UserMailer < ActionMailer::Base def welcome(user) mail(subject: default_i18n_subject(username: user.name)) end end
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/base_test.rb6
-rw-r--r--actionmailer/test/mailers/base_mailer.rb4
2 files changed, 10 insertions, 0 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index b06c465380..b9c56c540d 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -209,6 +209,12 @@ class BaseTest < ActiveSupport::TestCase
assert_equal "New Subject!", email.subject
end
+ test 'default subject can have interpolations' do
+ I18n.backend.store_translations('en', base_mailer: {with_subject_interpolations: {subject: 'Will the real %{rapper_or_impersonator} please stand up?'}})
+ email = BaseMailer.with_subject_interpolations
+ assert_equal 'Will the real Slim Shady please stand up?', email.subject
+ end
+
test "translations are scoped properly" do
I18n.backend.store_translations('en', base_mailer: {email_with_translations: {greet_user: "Hello %{name}!"}})
email = BaseMailer.email_with_translations
diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb
index 8fca6177bd..504ca36483 100644
--- a/actionmailer/test/mailers/base_mailer.rb
+++ b/actionmailer/test/mailers/base_mailer.rb
@@ -123,4 +123,8 @@ class BaseMailer < ActionMailer::Base
mail(:template_name => "welcome")
nil
end
+
+ def with_subject_interpolations
+ mail(subject: default_i18n_subject(rapper_or_impersonator: 'Slim Shady'), body: '')
+ end
end