aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/integration
diff options
context:
space:
mode:
authorJohannes Opper <johannes.opper@gmail.com>2015-07-07 21:52:28 +0200
committerJohannes Opper <johannes.opper@gmail.com>2015-08-04 00:38:18 +0200
commit3860e6b2bf486d8b27d433daab358dbc68ae3448 (patch)
tree136f0b6e7cfeac3ef48ea1c41c37332083dba8d2 /activejob/test/integration
parente598967548114da4f8d85070584460108a7305ff (diff)
downloadrails-3860e6b2bf486d8b27d433daab358dbc68ae3448.tar.gz
rails-3860e6b2bf486d8b27d433daab358dbc68ae3448.tar.bz2
rails-3860e6b2bf486d8b27d433daab358dbc68ae3448.zip
Fixes #20799
When `#perform_later` is called the locale isn't stored on the queue, which results in a locale reset when the job is performed. An example of the problem: I18n.locale = 'de' HelloJob.perform_now # german message, correct but I18n.locale = 'de' HelloJob.perform_later # english message, incorrect This PR attaches the current I18n.locale to every job during the serialization process. It is then restored during deserialization and used to perform the job with the correct locale. It falls back to the default locale if no serialized locale is found in order to provide backward compatibility with previously stored jobs. It is not necessary to clear the queue for the update.
Diffstat (limited to 'activejob/test/integration')
-rw-r--r--activejob/test/integration/queuing_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb
index d345092dee..e1634972d1 100644
--- a/activejob/test/integration/queuing_test.rb
+++ b/activejob/test/integration/queuing_test.rb
@@ -68,4 +68,21 @@ class QueuingTest < ActiveSupport::TestCase
refute delayed_test_job.provider_job_id.nil?,
'Provider job id should by set for delayed jobs by provider'
end
+
+ test 'current locale is kept while running perform_later' do
+ skip if adapter_is?(:inline)
+
+ begin
+ I18n.available_locales = [:en, :de]
+ I18n.locale = :de
+
+ TestJob.perform_later @id
+ wait_for_jobs_to_finish_for(5.seconds)
+ assert job_executed
+ assert_equal 'de', job_output
+ ensure
+ I18n.available_locales = [:en]
+ I18n.locale = :en
+ end
+ end
end