1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #15083 from zuhao/refactor_actionmailer_i18n_with_controller_test

Use with_translation helper to clean up I18n stored translations.
This commit is contained in:
Yves Senn 2014-05-13 10:43:50 +02:00
commit fd6d6dc602

View file

@ -10,15 +10,15 @@ class I18nTestMailer < ActionMailer::Base
def mail_with_i18n_subject(recipient)
@recipient = recipient
I18n.locale = :de
mail(to: recipient, subject: "#{I18n.t :email_subject} #{recipient}",
mail(to: recipient, subject: I18n.t(:email_subject),
from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end
end
class TestController < ActionController::Base
def send_mail
I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
render text: 'Mail sent'
email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
render text: "Mail sent - Subject: #{email.subject}"
end
end
@ -32,16 +32,19 @@ class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
Routes
end
def setup
I18n.backend.store_translations('de', email_subject: '[Signed up] Welcome')
end
def teardown
I18n.locale = :en
end
def test_send_mail
get '/test/send_mail'
assert_equal "Mail sent", @response.body
with_translation 'de', email_subject: '[Anmeldung] Willkommen' do
get '/test/send_mail'
assert_equal "Mail sent - Subject: [Anmeldung] Willkommen", @response.body
end
end
protected
def with_translation(locale, data)
I18n.backend.store_translations(locale, data)
yield
ensure
I18n.backend.reload!
end
end