mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
573a8421e7
If i18n_with_controller_test.rb were to run first, the I18n.locale will be changed to :de, and the following tests in base_test.rb will fail: "subject gets default from I18n" “default subject can have interpolations” "translations are scoped properly" "implicit multipart with default locale"
54 lines
1.2 KiB
Ruby
54 lines
1.2 KiB
Ruby
require 'abstract_unit'
|
|
require 'action_view'
|
|
require 'action_controller'
|
|
|
|
class I18nTestMailer < ActionMailer::Base
|
|
configure do |c|
|
|
c.assets_dir = ''
|
|
end
|
|
|
|
def mail_with_i18n_subject(recipient)
|
|
@recipient = recipient
|
|
I18n.locale = :de
|
|
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
|
|
email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
|
|
render text: "Mail sent - Subject: #{email.subject}"
|
|
end
|
|
end
|
|
|
|
class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
|
|
Routes = ActionDispatch::Routing::RouteSet.new
|
|
Routes.draw do
|
|
get ':controller(/:action(/:id))'
|
|
end
|
|
|
|
def app
|
|
Routes
|
|
end
|
|
|
|
teardown do
|
|
I18n.locale = I18n.default_locale
|
|
end
|
|
|
|
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
|
|
|
|
protected
|
|
|
|
def with_translation(locale, data)
|
|
I18n.backend.store_translations(locale, data)
|
|
yield
|
|
ensure
|
|
I18n.backend.reload!
|
|
end
|
|
end
|