mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Adding Fragment Cache to AMS
It's an upgrade based on the new Cache implementation #693. It allows to use the Rails conventions to cache specific attributes or associations. It's based on the Cache Composition implementation.
This commit is contained in:
27
test/adapter/fragment_cache_test.rb
Normal file
27
test/adapter/fragment_cache_test.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
class FragmentCacheTest < Minitest::Test
|
||||
def setup
|
||||
@author = Author.new(name: 'Joao M. D. Moura')
|
||||
@role = Role.new(name: 'Great Author', description:nil)
|
||||
@role.author = [@author]
|
||||
@role_serializer = RoleSerializer.new(@role)
|
||||
@role_hash = FragmentCache.new(RoleSerializer.adapter.new(@role_serializer), @role_serializer, {}, nil)
|
||||
end
|
||||
|
||||
def test_fragment_fetch_with_virtual_attributes
|
||||
expected_result = {
|
||||
id: @role.id,
|
||||
description: @role.description,
|
||||
slug: "#{@role.name}-#{@role.id}",
|
||||
name: @role.name
|
||||
}
|
||||
assert_equal(@role_hash.fetch, expected_result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user