mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Merge branch 'CheckMateIO-bugfix/fagment-caching-breaks-type-setting'
Squashed commits that were done in other PR Follow up needs: - Changelog
This commit is contained in:
commit
a40998273d
@ -94,6 +94,10 @@ module ActiveModel
|
|||||||
|
|
||||||
cached.constantize.cache(klass._cache_options)
|
cached.constantize.cache(klass._cache_options)
|
||||||
|
|
||||||
|
# Preserve the type setting in the cached/non-cached serializer classes
|
||||||
|
cached.constantize.type(klass._type)
|
||||||
|
non_cached.constantize.type(klass._type)
|
||||||
|
|
||||||
cached.constantize.fragmented(serializer)
|
cached.constantize.fragmented(serializer)
|
||||||
non_cached.constantize.fragmented(serializer)
|
non_cached.constantize.fragmented(serializer)
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,14 @@ module ActiveModel
|
|||||||
class Serializer
|
class Serializer
|
||||||
module Adapter
|
module Adapter
|
||||||
class FragmentCacheTest < ActiveSupport::TestCase
|
class FragmentCacheTest < ActiveSupport::TestCase
|
||||||
|
TypedRoleSerializer = Class.new(ActiveModel::Serializer) do
|
||||||
|
type 'my-roles'
|
||||||
|
cache only: [:name], skip_digest: true
|
||||||
|
attributes :id, :name, :description
|
||||||
|
|
||||||
|
belongs_to :author
|
||||||
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
||||||
@ -31,8 +39,12 @@ module ActiveModel
|
|||||||
}
|
}
|
||||||
assert_equal(@spam_hash.fetch, expected_result)
|
assert_equal(@spam_hash.fetch, expected_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fragment_fetch_with_type_override
|
||||||
|
serialization = serializable(Role.new(name: 'Another Author'), serializer: TypedRoleSerializer, adapter: :json_api).serializable_hash
|
||||||
|
assert_equal(TypedRoleSerializer._type, serialization.fetch(:data).fetch(:type))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user