Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enqueues Cron jobs with I18n default locale #698

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 12 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,17 @@ 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")
ensure
I18n.default_locale = :en
end

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