-
-
Notifications
You must be signed in to change notification settings - Fork 537
Expand file tree
/
Copy pathargument_serialization.rb
More file actions
96 lines (74 loc) · 2.56 KB
/
argument_serialization.rb
File metadata and controls
96 lines (74 loc) · 2.56 KB
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
# frozen_string_literal: true
RSpec.shared_examples "an ActiveJob backend that serializes complex arguments" do
let(:failing_job) do
job_fixture do
def perform(*_args, **_kwargs)
raise "boom from argument_serialization spec"
end
end
end
def event_arguments
last_sentry_event.extra[:arguments]
end
it "serializes ActiveRecord arguments via global id" do
post = Post.create!
expect do
failing_job.perform_later(post)
drain
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
expect(event_arguments).to eq([post.to_global_id.to_s])
end
it "recursively serializes nested hashes containing global ids" do
post = Post.create!
expect do
failing_job.perform_later(wrapper: { post: post })
drain
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
expect(event_arguments).to eq([{ wrapper: { post: post.to_global_id.to_s } }])
end
it "expands integer ranges into arrays", skip: RAILS_VERSION < 7.0 do
expect do
failing_job.perform_later(1..3)
drain
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
expect(event_arguments).to eq([[1, 2, 3]])
end
it "stringifies ActiveSupport::TimeWithZone ranges preserving the boundary operator", skip: RAILS_VERSION < 7.0 do
range = 1.day.ago...Time.zone.now
expect do
failing_job.perform_later(range)
drain
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
serialized = event_arguments.first
expect(serialized).to be_a(String)
expect(serialized).to eq("#{range.first}...#{range.last}")
end
it "falls back to the original argument when to_global_id raises" do
post = Post.create!
problematic_job = job_fixture do
def perform(passed_post)
def passed_post.to_global_id
raise "intentional"
end
raise "boom from argument_serialization spec"
end
end
expect do
problematic_job.perform_later(post)
drain
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
expect(event_arguments).to eq([post])
end
it "passes through objects that do not respond to to_global_id unchanged" do
mod = Module.new
module_job = job_fixture do
def perform(_mod)
raise "boom from argument_serialization spec"
end
end
expect do
module_job.perform_now(mod)
end.to raise_error(RuntimeError, /boom from argument_serialization spec/)
expect(event_arguments).to eq([mod])
end
end