Skip to content

Commit f815d3e

Browse files
authored
Merge pull request #1 from wasifhossain/collection-cache-expiry
Test cache expiration in collection on update of a record
2 parents 141feeb + 3d0b5ac commit f815d3e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/cache_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,27 @@ def test_expiring_of_cache_at_update_of_record
173173
end
174174
end
175175

176+
def test_cache_expiration_in_collection_on_update_of_record
177+
if ARModels::Author.respond_to?(:cache_versioning)
178+
ARModels::Author.cache_versioning = true
179+
end
180+
181+
foo = 'Foo'
182+
foo2 = 'Foo2'
183+
author = ARModels::Author.create(name: foo)
184+
author2 = ARModels::Author.create(name: foo2)
185+
author_collection = [author, author, author2]
186+
187+
collection_json = render_object_with_cache(author_collection, each_serializer: AuthorSerializerWithCache)
188+
assert_equal [{ name: foo }, { name: foo }, { name: foo2 }], collection_json
189+
190+
bar = 'Bar'
191+
author.update_attributes(name: bar)
192+
193+
collection_json = render_object_with_cache(author_collection, each_serializer: AuthorSerializerWithCache)
194+
assert_equal [{ name: bar }, { name: bar }, { name: foo2 }], collection_json
195+
end
196+
176197
def test_explicit_cache_store
177198
default_store = Class.new(ActiveModel::Serializer) do
178199
cache

0 commit comments

Comments
 (0)