Skip to content

Commit 78fb37a

Browse files
authored
Fix sidekiq-cron job patch return (#2176)
1 parent 62989c1 commit 78fb37a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def save
3131
slug: name,
3232
monitor_config: Sentry::Cron::MonitorConfig.from_crontab(cron))
3333
end
34+
35+
true
3436
end
3537
end
3638
end

sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,30 @@
1616
Sidekiq::Cron::Job.load_from_hash!(schedule)
1717
end
1818

19+
before do
20+
stub_const('Job', Class.new { def perform; end })
21+
end
22+
1923
it 'patches class' do
2024
expect(Sidekiq::Cron::Job.ancestors).to include(described_class)
2125
end
2226

27+
it 'preserves return value' do
28+
job = Sidekiq::Cron::Job.new(name: 'test', cron: '* * * * *', class: 'Job')
29+
expect(job.save).to eq(true)
30+
end
31+
32+
it 'preserves return value in invalid case' do
33+
job = Sidekiq::Cron::Job.new(name: 'test', cron: 'not a crontab', class: 'Job')
34+
expect(job.save).to eq(false)
35+
end
36+
37+
it 'does not raise error on invalid class' do
38+
expect do
39+
Sidekiq::Cron::Job.create(name: 'invalid_class', cron: '* * * * *', class: 'UndefinedClass')
40+
end.not_to raise_error
41+
end
42+
2343
it 'patches HappyWorker' do
2444
expect(HappyWorkerDup.ancestors).to include(Sentry::Cron::MonitorCheckIns)
2545
expect(HappyWorkerDup.sentry_monitor_slug).to eq('happy')
@@ -39,11 +59,4 @@
3959
it 'does not patch ReportingWorker because of invalid schedule' do
4060
expect(ReportingWorker.ancestors).not_to include(Sentry::Cron::MonitorSchedule)
4161
end
42-
43-
it 'does not raise error on invalid class' do
44-
expect do
45-
Sidekiq::Cron::Job.create(name: 'invalid_class', cron: '* * * * *', class: 'UndefinedClass')
46-
end.not_to raise_error
47-
end
48-
4962
end

0 commit comments

Comments
 (0)