From 400138d0c9708c2507e8b43c09c6cf5220bc88b5 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 6 Mar 2024 16:16:05 -0500 Subject: [PATCH] Fix rails 7 deprecation on ActiveRecord::Base.default_timezone Rails 7 added ActiveRecord.default_timezone and 7.1 will remove it from ActiveRecord::Base. Extract a memoized method to hide this logic. --- lib/inventory_refresh/save_collection/saver/base.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/inventory_refresh/save_collection/saver/base.rb b/lib/inventory_refresh/save_collection/saver/base.rb index a6395ab6..91665581 100644 --- a/lib/inventory_refresh/save_collection/saver/base.rb +++ b/lib/inventory_refresh/save_collection/saver/base.rb @@ -272,13 +272,18 @@ def assert_referential_integrity(hash) # @return [Time] A rails friendly time getting config from ActiveRecord::Base.default_timezone (can be :local # or :utc) def time_now - if ActiveRecord::Base.default_timezone == :utc + if default_timezone_utc? Time.now.utc else Time.zone.now end end + def default_timezone_utc? + # Rails 7 added ActiveRecord.default_timezone and 7.1 will remove it from ActiveRecord::Base + @default_timezone_utc ||= (ActiveRecord.respond_to?(:default_timezone) ? ActiveRecord.default_timezone : ActiveRecord::Base.default_timezone) == :utc + end + # Enriches data hash with timestamp columns # # @param hash [Hash] data hash