Skip to content

Commit

Permalink
Fix label modifications on job instance polluting labels on job class (
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed May 23, 2024
1 parent db58c20 commit 4f2dae4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/good_job/active_job_extensions/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Labels
module Prepends
def initialize(*arguments)
super
self.good_job_labels = Array(self.class.good_job_labels)
self.good_job_labels = Array(self.class.good_job_labels.dup)
end

def enqueue(options = {})
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/good_job/active_job_extensions/labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def perform
expect(active_job.good_job_labels).to eq []
end

it 'the instance value does not modify the class label value' do
TestJob.good_job_labels = ["buffalo"]
TestJob.before_enqueue { |job| job.good_job_labels << "gopher" }

job = TestJob.perform_later
expect(job.good_job_labels).to eq %w[buffalo gopher]
expect(TestJob.good_job_labels).to eq ["buffalo"]

job = TestJob.perform_later
expect(job.good_job_labels).to eq %w[buffalo gopher]
end

it 'is unique' do
TestJob.good_job_labels = %w[buffalo gopher gopher]
TestJob.perform_later
Expand Down

0 comments on commit 4f2dae4

Please sign in to comment.