mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #810 from joaomdmoura/fragment-cache
Adding Fragment Cache to AMS
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
|
||||
|
||||
@@ -6,6 +6,7 @@ module ActiveModel
|
||||
class Json
|
||||
class HasManyTestTest < Minitest::Test
|
||||
def setup
|
||||
ActionController::Base.cache_store.clear
|
||||
@author = Author.new(id: 1, name: 'Steve K.')
|
||||
@post = Post.new(title: 'New Post', body: 'Body')
|
||||
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
||||
|
||||
@@ -41,6 +41,7 @@ module ActiveModel
|
||||
expected = [
|
||||
{
|
||||
id: "43",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content:"AMS Contributor",
|
||||
links: {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class Adapter
|
||||
@@ -104,8 +103,9 @@ module ActiveModel
|
||||
}
|
||||
}, {
|
||||
id: "1",
|
||||
content: "AMS Contributor",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content: "AMS Contributor",
|
||||
links: {
|
||||
author: { linkage: { type: "authors", id: "1" } }
|
||||
}
|
||||
@@ -120,8 +120,9 @@ module ActiveModel
|
||||
}
|
||||
}, {
|
||||
id: "2",
|
||||
content: "Rails Contributor",
|
||||
rating: nil,
|
||||
type: "bios",
|
||||
content: "Rails Contributor",
|
||||
links: {
|
||||
author: { linkage: { type: "authors", id: "2" } }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ module ActiveModel
|
||||
class Adapter
|
||||
class JsonTest < Minitest::Test
|
||||
def setup
|
||||
ActionController::Base.cache_store.clear
|
||||
@author = Author.new(id: 1, name: 'Steve K.')
|
||||
@post = Post.new(title: 'New Post', body: 'Body')
|
||||
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
|
||||
|
||||
Reference in New Issue
Block a user