Skip to content

Commit

Permalink
Enqueues jobs with I18n default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
esasse committed Aug 12, 2022
1 parent 65dc794 commit 6b296bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/models/good_job/cron_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def enqueue(cron_at = nil)
current_thread.cron_at = cron_at

configured_job = job_class.constantize.set(set_value)
kwargs_value.present? ? configured_job.perform_later(*args_value, **kwargs_value) : configured_job.perform_later(*args_value)
I18n.with_locale(I18n.default_locale) do
kwargs_value.present? ? configured_job.perform_later(*args_value, **kwargs_value) : configured_job.perform_later(*args_value)
end
end
rescue ActiveRecord::RecordNotUnique
false
Expand Down
12 changes: 10 additions & 2 deletions spec/app/models/good_job/cron_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def perform(meaning, name:)
end

describe '#enqueue' do
include ActiveJob::TestHelper

before do
ActiveJob::Base.queue_adapter = :test
end
Expand All @@ -94,9 +96,15 @@ def perform(meaning, name:)
end.to have_enqueued_job(TestJob).with(42, name: 'Alice').on_queue('test_queue')
end

describe 'job execution' do
include ActiveJob::TestHelper
it 'enqueues a job with I18n default locale' do
I18n.default_locale = :nl

I18n.with_locale(:en) { entry.enqueue }

expect(enqueued_jobs.last["locale"]).to eq("nl")
end

describe 'job execution' do
it 'executes the job properly' do
perform_enqueued_jobs do
entry.enqueue
Expand Down

0 comments on commit 6b296bd

Please sign in to comment.