Skip to content

Commit 5456220

Browse files
BrentWheeldonnateberkopec
authored andcommitted
Prevent duplicated events when AJ adapter has a specific integration. (#815)
In rails 5, the job class’s `queue_adapter` property is not a class (such as `ActiveJob::QueueAdapters::SidekiqAdapter`) like it was in rails 4, but an instance (of a class such as `ActiveJob::QueueAdapters::SidekiqAdapter`). The specs were previously not testing the logic in `already_supported_by_specific_integration?` which is why there wasn’t a failing spec.
1 parent ebccacb commit 5456220

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/raven/integrations/rails/active_job.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def capture_and_reraise_with_sentry(job, block)
2828
end
2929

3030
def already_supported_by_specific_integration?(job)
31-
ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.to_s)
31+
if ::Rails.version.to_f < 5.0
32+
ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.to_s)
33+
else
34+
ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.class.to_s)
35+
end
3236
end
3337

3438
def raven_context(job)

spec/raven/integrations/rails/activejob_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
if defined? ActiveJob
44
class MyActiveJob < ActiveJob::Base
5-
self.queue_adapter = :inline
65
self.logger = nil
76

87
class TestError < RuntimeError
@@ -30,6 +29,7 @@ def rescue_callback(error)
3029

3130
before(:each) do
3231
Raven.client.transport.events = []
32+
MyActiveJob.queue_adapter = :inline
3333
end
3434

3535
it_should_behave_like "Raven default capture behavior" do
@@ -68,10 +68,8 @@ def rescue_callback(error)
6868

6969
context "when we are using an adapter which has a specific integration" do
7070
it "does not trigger sentry and re-raises" do
71+
MyActiveJob.queue_adapter = :sidekiq
7172
job = MyActiveJob.new
72-
def job.already_supported_by_specific_integration?(*)
73-
true
74-
end
7573

7674
expect { job.perform_now }.to raise_error(MyActiveJob::TestError)
7775

0 commit comments

Comments
 (0)