From 17fd89f0c1f2ff12f3a58642c5d4ada63cbf8aae Mon Sep 17 00:00:00 2001 From: Yuji Hanamura Date: Wed, 17 Aug 2022 00:36:20 +0900 Subject: [PATCH] Fix deprecation warning of `Time#to_s` ``` DEPRECATION WARNING: Time#to_s(:number) is deprecated. Please use Time#to_fs(:number) instead. ``` --- lib/active_hash/base.rb | 6 +++++- spec/active_hash/base_spec.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_hash/base.rb b/lib/active_hash/base.rb index 7f1321a5..a592601c 100644 --- a/lib/active_hash/base.rb +++ b/lib/active_hash/base.rb @@ -487,7 +487,11 @@ def cache_key when new_record? "#{self.class.cache_key}/new" when timestamp = self[:updated_at] - "#{self.class.cache_key}/#{id}-#{timestamp.to_s(:number)}" + if ActiveSupport::VERSION::MAJOR < 7 + "#{self.class.cache_key}/#{id}-#{timestamp.to_s(:number)}" + else + "#{self.class.cache_key}/#{id}-#{timestamp.to_fs(:number)}" + end else "#{self.class.cache_key}/#{id}" end diff --git a/spec/active_hash/base_spec.rb b/spec/active_hash/base_spec.rb index 41ae8d06..d81adf82 100644 --- a/spec/active_hash/base_spec.rb +++ b/spec/active_hash/base_spec.rb @@ -1314,7 +1314,7 @@ class Book < ActiveRecord::Base {:id => 1, :name => "foo", :updated_at => timestamp} ] - expect(Country.first.cache_key).to eq("countries/1-#{timestamp.to_s(:number)}") + expect(Country.first.cache_key).to eq("countries/1-#{timestamp.to_fs(:number)}") end it 'should use "new" instead of the id for a new record' do