mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
[FIX] Fetch json key from item serializer if empty collection is passed to collection serializer and each_searializer is specified.
This commit is contained in:
committed by
Benjamin Fleischer
parent
33a0f9c806
commit
2dd0c33461
@@ -84,6 +84,12 @@ module ActiveModel
|
||||
assert_nil serializer.json_key
|
||||
end
|
||||
|
||||
def test_json_key_with_empty_resources_with_serializer
|
||||
resource = []
|
||||
serializer = collection_serializer.new(resource, serializer: MessagesSerializer)
|
||||
assert_equal 'messages', serializer.json_key
|
||||
end
|
||||
|
||||
def test_json_key_with_root
|
||||
expected = 'custom_root'
|
||||
serializer = collection_serializer.new(@resource, root: expected)
|
||||
|
||||
6
test/fixtures/poro.rb
vendored
6
test/fixtures/poro.rb
vendored
@@ -183,6 +183,12 @@ PaginatedSerializer = Class.new(ActiveModel::Serializer::CollectionSerializer) d
|
||||
end
|
||||
end
|
||||
|
||||
MessagesSerializer = Class.new(ActiveModel::Serializer) do
|
||||
def json_key
|
||||
'messages'
|
||||
end
|
||||
end
|
||||
|
||||
AlternateBlogSerializer = Class.new(ActiveModel::Serializer) do
|
||||
attribute :id
|
||||
attribute :name, key: :title
|
||||
|
||||
Reference in New Issue
Block a user