Permalink
Browse files

Solve SystemStackError when changing locale inside ActionMailer [#5329

…state:resolved]
  • Loading branch information...
josevalim committed Jan 19, 2011
1 parent b4bc49c commit 46b23f8a7a6aec5066f740de16e6419828db8be4
@@ -2,13 +2,12 @@
require 'action_controller'
class I18nTestMailer < ActionMailer::Base
-
configure do |c|
- c.assets_dir = '' # To get the tests to pass
+ c.assets_dir = ''
end
def mail_with_i18n_subject(recipient)
- @recipient = recipient
+ @recipient = recipient
I18n.locale = :de
mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}",
:from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
@@ -17,13 +16,12 @@ def mail_with_i18n_subject(recipient)
class TestController < ActionController::Base
def send_mail
- I18nTestMailer.mail_with_i18n_subject(@recipient).deliver
+ I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
render :text => 'Mail sent'
end
end
class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
-
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
match ':controller(/:action(/:id))'
@@ -35,12 +33,10 @@ def app
def setup
I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome')
- set_delivery_method :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries.clear
- ActiveSupport::Deprecation.silenced = false
+ end
- @recipient = 'test@localhost'
+ def teardown
+ I18n.locale = :en
end
def test_send_mail
@@ -14,14 +14,15 @@ def initialize(message = nil)
# it will trigger the lookup_context and consequently expire the cache.
# TODO Add some deprecation warnings to remove I18n.locale from controllers
class I18nProxy < ::I18n::Config #:nodoc:
- attr_reader :i18n_config, :lookup_context
+ attr_reader :original_config, :lookup_context
- def initialize(i18n_config, lookup_context)
- @i18n_config, @lookup_context = i18n_config, lookup_context
+ def initialize(original_config, lookup_context)
+ original_config = original_config.original_config if original_config.respond_to?(:original_config)
+ @original_config, @lookup_context = original_config, lookup_context
end
def locale
- @i18n_config.locale
+ @original_config.locale
end
def locale=(value)
@@ -167,11 +167,11 @@ def locale
end
# Overload locale= to also set the I18n.locale. If the current I18n.config object responds
- # to i18n_config, it means that it's has a copy of the original I18n configuration and it's
+ # to original_config, it means that it's has a copy of the original I18n configuration and it's
# acting as proxy, which we need to skip.
def locale=(value)
if value
- config = I18n.config.respond_to?(:i18n_config) ? I18n.config.i18n_config : I18n.config
+ config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
config.locale = value
end
@@ -226,4 +226,4 @@ def _set_detail(key, value)
include Details
include ViewPaths
end
-end
+end
@@ -73,7 +73,7 @@ def teardown
assert_equal :pt, I18n.locale
assert_equal :pt, @lookup_context.locale
ensure
- I18n.config = I18n.config.i18n_config
+ I18n.config = I18n.config.original_config
end
assert_equal :pt, I18n.locale
@@ -163,4 +163,4 @@ def teardown
template = @lookup_context.find("foo", "test", true)
assert_equal "Bar", template.source
end
-end
+end

0 comments on commit 46b23f8

Please sign in to comment.