mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Breaking change: - Adapters now inherit Adapter::Base - 'Adapter' is now a module, no longer a class Why? - using a class as a namespace that you also inherit from is complicated and circular at time i.e. buggy (see https://github.com/rails-api/active_model_serializers/pull/1177) - The class methods on Adapter aren't necessarily related to the instance methods, they're more Adapter functions - named `Base` because it's a Rails-ism - It helps to isolate and highlight what the Adapter interface actually is
38 lines
1.3 KiB
Ruby
38 lines
1.3 KiB
Ruby
require 'test_helper'
|
|
module ActiveModel
|
|
class Serializer
|
|
module Adapter
|
|
class FragmentCacheTest < Minitest::Test
|
|
def setup
|
|
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
|
@author = Author.new(name: 'Joao M. D. Moura')
|
|
@role = Role.new(name: 'Great Author', description: nil)
|
|
@role.author = [@author]
|
|
@role_serializer = RoleSerializer.new(@role)
|
|
@spam_serializer = Spam::UnrelatedLinkSerializer.new(@spam)
|
|
@role_hash = FragmentCache.new(RoleSerializer.adapter.new(@role_serializer), @role_serializer, {})
|
|
@spam_hash = FragmentCache.new(Spam::UnrelatedLinkSerializer.adapter.new(@spam_serializer), @spam_serializer, {})
|
|
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
|
|
|
|
def test_fragment_fetch_with_namespaced_object
|
|
expected_result = {
|
|
id: @spam.id
|
|
}
|
|
assert_equal(@spam_hash.fetch, expected_result)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|