aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/cache_key_test.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2018-10-15 15:31:12 -0500
committerschneems <richard.schneeman+foo@gmail.com>2018-10-17 11:05:05 -0500
commit2f99da00c7b311af0bc5969985eee97937790e4f (patch)
tree971997f10298c1a6ea27d53dde9f1688d5a150f4 /activerecord/test/cases/cache_key_test.rb
parent04454839a1a07cacac58cdf756a6b8e3adde0ef5 (diff)
downloadrails-2f99da00c7b311af0bc5969985eee97937790e4f.tar.gz
rails-2f99da00c7b311af0bc5969985eee97937790e4f.tar.bz2
rails-2f99da00c7b311af0bc5969985eee97937790e4f.zip
Do not silently fail to generate a cache_version
When an `updated_at` column exists on the model, but is not available on the instance (likely due to a select), we should raise an error rather than silently not generating a cache_version. Without this behavior it's likely that cache entries will not be able to be invalidated and this will happen without notice. This behavior was reported and described by @lsylvester in https://github.com/rails/rails/pull/34197#issuecomment-429668759.
Diffstat (limited to 'activerecord/test/cases/cache_key_test.rb')
-rw-r--r--activerecord/test/cases/cache_key_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/cache_key_test.rb b/activerecord/test/cases/cache_key_test.rb
index 535511d1cb..3a06b1c795 100644
--- a/activerecord/test/cases/cache_key_test.rb
+++ b/activerecord/test/cases/cache_key_test.rb
@@ -119,5 +119,13 @@ module ActiveRecord
record_from_db.cache_version
end
end
+
+ test "updated_at on class but not on instance raises an error" do
+ record = CacheMeWithVersion.create
+ record_from_db = CacheMeWithVersion.where(id: record.id).select(:id).first
+ assert_raises(ActiveModel::MissingAttributeError) do
+ record_from_db.cache_version
+ end
+ end
end
end