From 7f751fc1f7fbc5a16634f2530dddc5b1eb2d2c0b Mon Sep 17 00:00:00 2001 From: cintamani Date: Mon, 1 Oct 2018 14:37:09 +0100 Subject: [PATCH] Add test coverage and changelog --- CHANGELOG.md | 1 + test/cache_test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd55fa3e..05ad938f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Breaking changes: Features: Fixes: + - [#2288](https://github.com/rails-api/active_model_serializers/pull/2288). Fixes #2287. (@cintamani) - [#2307](https://github.com/rails-api/active_model_serializers/pull/2307) Falsey attribute values should not be reevaluated. diff --git a/test/cache_test.rb b/test/cache_test.rb index 7bf9ca85..ed844f4f 100644 --- a/test/cache_test.rb +++ b/test/cache_test.rb @@ -55,6 +55,11 @@ module ActiveModelSerializers has_many :roles has_one :bio end + class AuthorSerializerWithCache < ActiveModel::Serializer + cache + + attributes :name + end class Blog < ::Model attributes :name @@ -146,6 +151,19 @@ module ActiveModelSerializers @blog_serializer = BlogSerializer.new(@blog) end + def test_expire_of_cache + ARModels::Author.cache_versioning = true + author = ARModels::Author.create(name: 'Foo') + author_json = AuthorSerializerWithCache.new(author).as_json + + assert_equal 'Foo', author_json[:name] + + author.update_attributes(name: 'Bar') + author_json = AuthorSerializerWithCache.new(author).as_json + + assert_equal 'Bar', author_json[:name] + end + def test_explicit_cache_store default_store = Class.new(ActiveModel::Serializer) do cache