Skip to content

Commit

Permalink
Clarify intent in the cache expansion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markiz committed Aug 13, 2016
1 parent 4ce7dc0 commit 7b6302a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fixes:

Misc:

- [#1878](https://github.com/rails-api/active_model_serializers/pull/1878) Cache key generation for serializers now uses `ActiveSupport::Cache.expand_cache_key` instead of `Enumerable#join` by default and is also overridable. This change should be backward-compatible. (@markiz)
- [#1878](https://github.com/rails-api/active_model_serializers/pull/1878) Cache key generation for serializers now uses `ActiveSupport::Cache.expand_cache_key` instead of `Array#join` by default and is also overridable. This change should be backward-compatible. (@markiz)

### [v0.10.2 (2016-07-05)](https://github.com/rails-api/active_model_serializers/compare/v0.10.1...v0.10.2)

Expand Down
13 changes: 8 additions & 5 deletions test/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

module ActiveModelSerializers
class CacheTest < ActiveSupport::TestCase
class AuthorWithCustomCacheKey < Author
class AuthorWithExpandableCacheElements < Author
# simply returns object's method as the cache key
class DerivedCacheKey
def initialize(object, method)
@object = object
Expand All @@ -16,6 +17,8 @@ def cache_key
end
end

# instead of a primitive cache key returns a list of objects
# that require to be expanded themselves
def cache_key
[
DerivedCacheKey.new(self, :name),
Expand Down Expand Up @@ -126,10 +129,10 @@ def test_cache_key_interpolation_with_updated_at_when_cache_key_is_not_defined_o
assert_equal(uncached_author_serializer.attributes.to_json, cache_store.fetch(key).to_json)
end

def test_cache_key_with_non_primitive_values
author = AuthorWithCustomCacheKey.new(id: 10, name: 'hello')
same_author = AuthorWithCustomCacheKey.new(id: 10, name: 'hello')
diff_author = AuthorWithCustomCacheKey.new(id: 11, name: 'hello')
def test_cache_key_expansion
author = AuthorWithExpandableCacheElements.new(id: 10, name: 'hello')
same_author = AuthorWithExpandableCacheElements.new(id: 10, name: 'hello')
diff_author = AuthorWithExpandableCacheElements.new(id: 11, name: 'hello')

author_serializer = AuthorSerializer.new(author)
same_author_serializer = AuthorSerializer.new(same_author)
Expand Down

0 comments on commit 7b6302a

Please sign in to comment.