mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Merge pull request #1185 from beauby/fix-attributes-include
Fix options passing in Json and Attributes adapters
This commit is contained in:
commit
94cee192a9
@ -10,7 +10,7 @@ module ActiveModel
|
|||||||
def serializable_hash(options = nil)
|
def serializable_hash(options = nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
result = serializer.map { |s| Attributes.new(s).serializable_hash(options) }
|
result = serializer.map { |s| Attributes.new(s, instance_options).serializable_hash(options) }
|
||||||
else
|
else
|
||||||
hash = {}
|
hash = {}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ module ActiveModel
|
|||||||
|
|
||||||
def serializable_hash(options = nil)
|
def serializable_hash(options = nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
{ root => Attributes.new(serializer).serializable_hash(options) }
|
{ root => Attributes.new(serializer, instance_options).serializable_hash(options) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -75,6 +75,16 @@ module ActiveModel
|
|||||||
|
|
||||||
assert_equal 1, adapter.serializable_hash[:virtual_values].length
|
assert_equal 1, adapter.serializable_hash[:virtual_values].length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_include_option
|
||||||
|
serializer = ArraySerializer.new([@first_post, @second_post])
|
||||||
|
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, include: '')
|
||||||
|
actual = adapter.serializable_hash
|
||||||
|
expected = { posts: [{ id: 1, title: 'Hello!!', body: 'Hello, world!!' },
|
||||||
|
{ id: 2, title: 'New Post', body: 'Body' }] }
|
||||||
|
|
||||||
|
assert_equal(expected, actual)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user