mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
3860e6b2bf
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.
52 lines
1 KiB
Ruby
52 lines
1 KiB
Ruby
require 'active_support/concern'
|
|
require 'support/integration/jobs_manager'
|
|
|
|
module TestCaseHelpers
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
self.use_transactional_tests = false
|
|
|
|
setup do
|
|
clear_jobs
|
|
@id = "AJ-#{SecureRandom.uuid}"
|
|
end
|
|
|
|
teardown do
|
|
clear_jobs
|
|
end
|
|
end
|
|
|
|
protected
|
|
|
|
def jobs_manager
|
|
JobsManager.current_manager
|
|
end
|
|
|
|
def clear_jobs
|
|
jobs_manager.clear_jobs
|
|
end
|
|
|
|
def adapter_is?(*adapter_class_symbols)
|
|
adapter_class_symbols.map(&:to_s).include?(ActiveJob::Base.queue_adapter.class.name.split("::").last.gsub(/Adapter$/, '').underscore)
|
|
end
|
|
|
|
def wait_for_jobs_to_finish_for(seconds=60)
|
|
begin
|
|
Timeout.timeout(seconds) do
|
|
while !job_executed do
|
|
sleep 0.25
|
|
end
|
|
end
|
|
rescue Timeout::Error
|
|
end
|
|
end
|
|
|
|
def job_executed
|
|
Dummy::Application.root.join("tmp/#{@id}").exist?
|
|
end
|
|
|
|
def job_output
|
|
File.read Dummy::Application.root.join("tmp/#{@id}")
|
|
end
|
|
end
|