Skip to content

Commit

Permalink
Fix deprecation warning of Time#to_s
Browse files Browse the repository at this point in the history
```
DEPRECATION WARNING: Time#to_s(:number) is deprecated. Please use Time#to_fs(:number) instead.
```
  • Loading branch information
yujideveloper committed Aug 16, 2022
1 parent bb11159 commit 17fd89f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/active_hash/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/active_hash/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17fd89f

Please sign in to comment.