From 3d0b5acc37e5270af1f697ca270f6f5c24c7306b Mon Sep 17 00:00:00 2001 From: Wasif Hossain Date: Fri, 1 Feb 2019 10:04:49 +0600 Subject: [PATCH] Test cache expiration in collection on update of a record --- test/cache_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/cache_test.rb b/test/cache_test.rb index 8e68ee397..181d78163 100644 --- a/test/cache_test.rb +++ b/test/cache_test.rb @@ -173,6 +173,27 @@ def test_expiring_of_cache_at_update_of_record end end + def test_cache_expiration_in_collection_on_update_of_record + if ARModels::Author.respond_to?(:cache_versioning) + ARModels::Author.cache_versioning = true + end + + foo = 'Foo' + foo2 = 'Foo2' + author = ARModels::Author.create(name: foo) + author2 = ARModels::Author.create(name: foo2) + author_collection = [author, author, author2] + + collection_json = render_object_with_cache(author_collection, each_serializer: AuthorSerializerWithCache) + assert_equal [{ name: foo }, { name: foo }, { name: foo2 }], collection_json + + bar = 'Bar' + author.update_attributes(name: bar) + + collection_json = render_object_with_cache(author_collection, each_serializer: AuthorSerializerWithCache) + assert_equal [{ name: bar }, { name: bar }, { name: foo2 }], collection_json + end + def test_explicit_cache_store default_store = Class.new(ActiveModel::Serializer) do cache