Skip to content

Commit

Permalink
Merge pull request #1 from wasifhossain/collection-cache-expiry
Browse files Browse the repository at this point in the history
Test cache expiration in collection on update of a record
  • Loading branch information
cintamani authored Feb 1, 2019
2 parents 141feeb + 3d0b5ac commit f815d3e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f815d3e

Please sign in to comment.