Skip to content

Commit 7f751fc

Browse files
committed
Add test coverage and changelog
1 parent be5fbf3 commit 7f751fc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Breaking changes:
77
Features:
88

99
Fixes:
10+
- [#2288](https://github.com/rails-api/active_model_serializers/pull/2288). Fixes #2287. (@cintamani)
1011

1112
- [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated.
1213

test/cache_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class AuthorSerializer < ActiveModel::Serializer
5555
has_many :roles
5656
has_one :bio
5757
end
58+
class AuthorSerializerWithCache < ActiveModel::Serializer
59+
cache
60+
61+
attributes :name
62+
end
5863

5964
class Blog < ::Model
6065
attributes :name
@@ -146,6 +151,19 @@ class InheritedRoleSerializer < RoleSerializer
146151
@blog_serializer = BlogSerializer.new(@blog)
147152
end
148153

154+
def test_expire_of_cache
155+
ARModels::Author.cache_versioning = true
156+
author = ARModels::Author.create(name: 'Foo')
157+
author_json = AuthorSerializerWithCache.new(author).as_json
158+
159+
assert_equal 'Foo', author_json[:name]
160+
161+
author.update_attributes(name: 'Bar')
162+
author_json = AuthorSerializerWithCache.new(author).as_json
163+
164+
assert_equal 'Bar', author_json[:name]
165+
end
166+
149167
def test_explicit_cache_store
150168
default_store = Class.new(ActiveModel::Serializer) do
151169
cache

0 commit comments

Comments
 (0)