Skip to content

Commit 61d07ba

Browse files
committed
fixes for deprecation warnings and rails 8
1 parent a12d75e commit 61d07ba

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ end
1313

1414
gem "rails", "~> #{ENV["RAILS_VERSION"] || "7.2.2.1"}", require: false
1515

16-
# Add these gems to silence Ruby 3.4 warnings
16+
# Add these gems to silence Ruby 3.4+ warnings
1717
gem "bigdecimal"
1818
gem "drb" # For ActiveSupport::TestCase
1919
gem "mutex_m"
20+
gem "ostruct" # For Ruby 3.5+ compatibility
2021

2122
# Sorbet is needed for development
2223
gem "sorbet", "~> 0.5"

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ DEPENDENCIES
428428
minitest (~> 5.20)
429429
minitest-reporters (~> 1.6)
430430
mutex_m
431+
ostruct
431432
rails (~> 7.2.2.1)
432433
redcarpet
433434
rollbar (~> 3.4)

lib/log_struct/formatter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def process_values(arg, recursion_depth: 0)
9090
when ActiveRecord::Base
9191
"#{arg.class}(##{arg.id})"
9292
else
93-
arg
93+
# For non-ActiveRecord objects that failed to_global_id, try to get a string representation
94+
# If this also fails, we want to catch it and return the error placeholder
95+
T.unsafe(arg).to_s
9496
end
9597
rescue => e
9698
LogStruct.handle_exception(e, source: Source::LogStruct)

test/log_struct/formatter_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ def test_handles_global_id_errors_gracefully
8282
def to_global_id
8383
raise StandardError, "Can't serialize"
8484
end
85+
86+
# In Rails 8.0+, ensure any fallback methods also raise to trigger error path
87+
def inspect
88+
raise StandardError, "Can't inspect"
89+
end
90+
91+
def to_s
92+
raise StandardError, "Can't stringify"
93+
end
8594
end
8695

8796
# Create an instance of it

test/log_struct/multi_error_reporter_test.rb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def setup
1717
@original_stdout = $stdout
1818
@stdout_buffer = StringIO.new
1919
$stdout = @stdout_buffer
20+
21+
# Define mock constants for error reporting services if they don't exist
22+
setup_mock_constants
2023
end
2124

2225
def teardown
@@ -206,5 +209,82 @@ def test_report_error_with_no_service
206209
end
207210
end
208211
end
212+
213+
private
214+
215+
def setup_mock_constants
216+
# Define mock constants for error reporting services if they don't exist
217+
unless defined?(::Sentry)
218+
sentry_class = Class.new do
219+
def self.capture_exception(*args)
220+
# Mock implementation
221+
end
222+
223+
def self.stub(method, &block)
224+
# Mock stub method for minitest
225+
original_method = singleton_method(method)
226+
define_singleton_method(method, &block)
227+
yield
228+
ensure
229+
define_singleton_method(method, original_method.to_proc) if original_method
230+
end
231+
end
232+
Object.const_set(:Sentry, sentry_class)
233+
end
234+
235+
unless defined?(::Bugsnag)
236+
bugsnag_class = Class.new do
237+
def self.notify(*args)
238+
# Mock implementation
239+
end
240+
241+
def self.stub(method, &block)
242+
# Mock stub method for minitest
243+
original_method = singleton_method(method)
244+
define_singleton_method(method, &block)
245+
yield
246+
ensure
247+
define_singleton_method(method, original_method.to_proc) if original_method
248+
end
249+
end
250+
Object.const_set(:Bugsnag, bugsnag_class)
251+
end
252+
253+
unless defined?(::Rollbar)
254+
rollbar_class = Class.new do
255+
def self.error(*args)
256+
# Mock implementation
257+
end
258+
259+
def self.stub(method, &block)
260+
# Mock stub method for minitest
261+
original_method = singleton_method(method)
262+
define_singleton_method(method, &block)
263+
yield
264+
ensure
265+
define_singleton_method(method, original_method.to_proc) if original_method
266+
end
267+
end
268+
Object.const_set(:Rollbar, rollbar_class)
269+
end
270+
271+
unless defined?(::Honeybadger)
272+
honeybadger_class = Class.new do
273+
def self.notify(*args)
274+
# Mock implementation
275+
end
276+
277+
def self.stub(method, &block)
278+
# Mock stub method for minitest
279+
original_method = singleton_method(method)
280+
define_singleton_method(method, &block)
281+
yield
282+
ensure
283+
define_singleton_method(method, original_method.to_proc) if original_method
284+
end
285+
end
286+
Object.const_set(:Honeybadger, honeybadger_class)
287+
end
288+
end
209289
end
210290
end

test/test_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def self.eager_load_frameworks
6868
[:password, :token, :secret, :key, :access, :auth, :credentials],
6969
T::Array[Symbol]
7070
)
71+
72+
# Fix Rails 8.1 deprecation warning for to_time timezone preservation
73+
config.active_support.to_time_preserves_timezone = :zone
7174
end
7275

7376
# Initialize the application

0 commit comments

Comments
 (0)