From 32ef7d3c5c5901dee4aeda99557e4416819428ce Mon Sep 17 00:00:00 2001 From: Zuhao Wan Date: Tue, 13 May 2014 11:43:26 +0800 Subject: Use with_translation helper to clean up I18n stored translations. --- actionmailer/test/i18n_with_controller_test.rb | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'actionmailer/test/i18n_with_controller_test.rb') diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb index 14a1b11b6d..d502d42ffd 100644 --- a/actionmailer/test/i18n_with_controller_test.rb +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -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') + def test_send_mail + with_translation 'de', email_subject: '[Anmeldung] Willkommen' do + get '/test/send_mail' + assert_equal "Mail sent - Subject: [Anmeldung] Willkommen", @response.body + end end - def teardown - I18n.locale = :en - end + protected - def test_send_mail - get '/test/send_mail' - assert_equal "Mail sent", @response.body + def with_translation(locale, data) + I18n.backend.store_translations(locale, data) + yield + ensure + I18n.backend.reload! end end -- cgit v1.2.3