Skip to content

Commit

Permalink
Merge pull request #15083 from zuhao/refactor_actionmailer_i18n_with_…
Browse files Browse the repository at this point in the history
…controller_test

Use with_translation helper to clean up I18n stored translations.
  • Loading branch information
senny committed May 13, 2014
2 parents 9392d16 + 32ef7d3 commit fd6d6dc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions actionmailer/test/i18n_with_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -32,16 +32,19 @@ def app
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

0 comments on commit fd6d6dc

Please sign in to comment.