From 3860e6b2bf486d8b27d433daab358dbc68ae3448 Mon Sep 17 00:00:00 2001 From: Johannes Opper Date: Tue, 7 Jul 2015 21:52:28 +0200 Subject: 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. --- activejob/test/support/integration/dummy_app_template.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activejob/test/support/integration/dummy_app_template.rb') diff --git a/activejob/test/support/integration/dummy_app_template.rb b/activejob/test/support/integration/dummy_app_template.rb index 09a68738ad..4ffdb8cffa 100644 --- a/activejob/test/support/integration/dummy_app_template.rb +++ b/activejob/test/support/integration/dummy_app_template.rb @@ -8,13 +8,17 @@ require "#{File.expand_path("../jobs_manager.rb", __FILE__)}" JobsManager.current_manager.setup CODE +initializer 'i18n.rb', <<-CODE +I18n.available_locales = [:en, :de] +CODE + file 'app/jobs/test_job.rb', <<-CODE class TestJob < ActiveJob::Base queue_as :integration_tests def perform(x) File.open(Rails.root.join("tmp/\#{x}"), "w+") do |f| - f.write x + f.write I18n.locale end end end -- cgit v1.2.3