Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache: warning if
expires_in
is given an incorrect value
In Rails 7, if you do `Rails.cache.write(key, value, expires_in: 1.minute.from_now)`, it will work. The actual expiration will be much more than a minute away, but it won't raise. (The correct code is `expires_in: 1.minute` or `expires_at: 1.minute.from_now`.) Since rails#45892 the same code will error with: ``` NoMethodError: undefined method `negative?' for 2008-04-24 00:01:00 -0600:Time /Users/alex/Code/rails/activesupport/lib/active_support/cache.rb:743:in `merged_options' /Users/alex/Code/rails/activesupport/lib/active_support/cache.rb:551:in `write' ``` To make it a bit easier to upgrade to Rails 7.1, this PR introduces a better error if you pass a `Time` object to `expires_in:` ``` ArgumentError: expires_in parameter should not be a Time. Did you mean to use expires_at? Got: 2023-04-07 14:47:45 -0600 /Users/alex/Code/rails/activesupport/lib/active_support/cache.rb:765:in `handle_invalid_expires_in' /Users/alex/Code/rails/activesupport/lib/active_support/cache.rb:745:in `merged_options' /Users/alex/Code/rails/activesupport/lib/active_support/cache.rb:551:in `write' ```
- Loading branch information