-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathsend_event_job_spec.rb
103 lines (84 loc) · 2.46 KB
/
send_event_job_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "active_job"
require "spec_helper"
RSpec.describe "Sentry::SendEventJob" do
let(:event) do
Sentry.get_current_client.event_from_message("test message")
end
let(:transport) do
Sentry.get_current_client.transport
end
context "when ActiveJob is not loaded" do
before do
TempActiveJob = ActiveJob
Object.send(:remove_const, "ActiveJob")
reload_send_event_job
end
after do
ActiveJob = TempActiveJob
reload_send_event_job
end
it "gets defined as a blank class" do
expect(Sentry::SendEventJob.superclass).to eq(Object)
end
end
context "when ActiveJob is loaded" do
after do
reload_send_event_job
end
it "reports events to Sentry" do
make_basic_app
Sentry.configuration.before_send = lambda do |event, hint|
event.tags[:hint] = hint
event
end
Sentry::SendEventJob.perform_now(event, { foo: "bar" })
expect(transport.events.count).to eq(1)
event = transport.events.first
expect(event.message).to eq("test message")
expect(event.tags[:hint][:foo]).to eq("bar")
end
it "doesn't create a new transaction" do
make_basic_app do |config|
config.traces_sample_rate = 1.0
end
Sentry::SendEventJob.perform_now(event)
expect(transport.events.count).to eq(1)
event = transport.events.first
expect(event.type).to eq("event")
end
context "when ApplicationJob is not defined" do
before do
make_basic_app
end
it "uses ActiveJob::Base as the parent class" do
expect(Sentry::SendEventJob.superclass).to eq(ActiveJob::Base)
end
end
context "when ApplicationJob is defined" do
before do
class ApplicationJob < ActiveJob::Base; end
reload_send_event_job
make_basic_app
end
after do
Object.send(:remove_const, "ApplicationJob")
end
it "uses ApplicationJob as the parent class" do
expect(Sentry::SendEventJob.superclass).to eq(ApplicationJob)
end
end
context "when ApplicationJob is defined but it's something else" do
before do
class ApplicationJob; end
reload_send_event_job
make_basic_app
end
after do
Object.send(:remove_const, "ApplicationJob")
end
it "uses ActiveJob::Base as the parent class" do
expect(Sentry::SendEventJob.superclass).to eq(ActiveJob::Base)
end
end
end
end