Skip to content

Commit

Permalink
Ensure begin-less and end-less ranges work too
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Feb 6, 2025
1 parent 3161cc7 commit 1bee091
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def sentry_context(job)
def sentry_serialize_arguments(argument)
case argument
when Range
if argument.first.is_a?(ActiveSupport::TimeWithZone)
if (argument.begin || argument.end).is_a?(ActiveSupport::TimeWithZone)
argument.to_s

Check warning on line 84 in sentry-rails/lib/sentry/rails/active_job.rb

View check run for this annotation

Codecov / codecov/patch

sentry-rails/lib/sentry/rails/active_job.rb#L83-L84

Added lines #L83 - L84 were not covered by tests
else
argument.map { |v| sentry_serialize_arguments(v) }

Check warning on line 86 in sentry-rails/lib/sentry/rails/active_job.rb

View check run for this annotation

Codecov / codecov/patch

sentry-rails/lib/sentry/rails/active_job.rb#L86

Added line #L86 was not covered by tests
Expand Down
27 changes: 27 additions & 0 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,34 @@ def post.to_global_id

it "serializes range arguments gracefully when Range consists of ActiveSupport::TimeWithZone" do
post = Post.create!

range = 5.days.ago...1.day.ago
range_no_beginning = (..1.day.ago)
range_no_end = (5.days.ago..)

expect do
JobWithArgument.perform_now("foo", { bar: Sentry },
integer: 1, post: post, range: range, range_no_beginning: range_no_beginning, range_no_end: range_no_end)
end.to raise_error(RuntimeError)

event = transport.events.last.to_json_compatible
expect(event.dig("extra", "arguments")).to eq(
[
"foo",
{ "bar" => "Sentry" },
{
"integer" => 1,
"post" => "gid://rails-test-app/Post/#{post.id}",
"range" => "#{range.first}...#{range.last}",
"range_no_beginning" => "..#{range_no_beginning.last}",
"range_no_end" => "#{range_no_end.first}.."
}
]
)
end

it "serializes range arguments gracefully when Range has no beginning" do
post = Post.create!

expect do
JobWithArgument.perform_now("foo", { bar: Sentry }, integer: 1, post: post, range: range)
Expand Down

0 comments on commit 1bee091

Please sign in to comment.