Skip to content

Commit abe1b43

Browse files
authored
Merge pull request #9 from Kaligo/fix/nil-method-owner
Fix crash when worker does not define #perform method
2 parents 69c6393 + 9e718af commit abe1b43

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Change Log
2+
3+
## 2.4.1
4+
- Fix crash when worker does not define #perform method
5+
26
## 2.4.0
37
- Switch rspec to test for mutiple sidekiq version
48
- Support both sidekiq 8 and 7

lib/sidekiq_adhoc_job/utils/class_inspector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def has_rest_parameter?(method_name)
4848
end
4949

5050
def klass_method(method)
51-
return method if method.owner == klass_name
51+
return method if method.owner == klass_name || !method.super_method
5252

5353
klass_method(method.super_method)
5454
end

lib/sidekiq_adhoc_job/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SidekiqAdhocJob
4-
VERSION = '2.4.0'
4+
VERSION = '2.4.1'
55
end

spec/sidekiq_adhoc_job/utils/class_inspector_spec.rb

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
describe '#parameters' do
1111
it do
12-
expect(inspector.parameters(:perform)).to eq({
13-
key: [:dryrun],
14-
keyreq: [:type],
15-
opt: %i[retry_job retries interval name options],
16-
req: %i[id overwrite]
17-
})
12+
expect(inspector.parameters(:perform)).to eq(
13+
key: [:dryrun],
14+
keyreq: [:type],
15+
opt: %i[retry_job retries interval name options],
16+
req: %i[id overwrite]
17+
)
1818
end
1919
end
2020

@@ -23,10 +23,10 @@
2323

2424
describe '#parameters' do
2525
it 'returns the parameters of the original method' do
26-
expect(inspector.parameters(:perform)).to eq({
27-
opt: %i[retry_job retries interval],
28-
req: %i[id overwrite]
29-
})
26+
expect(inspector.parameters(:perform)).to eq(
27+
opt: %i[retry_job retries interval],
28+
req: %i[id overwrite]
29+
)
3030
end
3131
end
3232
end
@@ -36,10 +36,29 @@
3636

3737
describe '#parameters' do
3838
it 'returns the parameters of the method on the target class' do
39-
expect(inspector.parameters(:perform)).to eq({
40-
opt: %i[retry_job retries interval],
41-
req: %i[id overwrite]
42-
})
39+
expect(inspector.parameters(:perform)).to eq(
40+
opt: %i[retry_job retries interval],
41+
req: %i[id overwrite]
42+
)
43+
end
44+
end
45+
end
46+
47+
context "with an inherited class without redefining method" do
48+
before do
49+
stub_const("TempWorker", Class.new(SidekiqAdhocJob::Test::DummyWorker))
50+
end
51+
52+
let(:klass) { TempWorker }
53+
54+
describe "#parameters" do
55+
it "returns the parameters of the parent method" do
56+
expect(inspector.parameters(:perform)).to eq(
57+
key: [:dryrun],
58+
keyreq: [:type],
59+
opt: [:retry_job, :retries, :interval, :name, :options],
60+
req: [:id, :overwrite]
61+
)
4362
end
4463
end
4564
end

0 commit comments

Comments
 (0)