Merge pull request #1185 from beauby/fix-attributes-include

Fix options passing in Json and Attributes adapters
This commit is contained in:
L. Preston Sego III 2015-09-21 00:48:16 -05:00
commit 94cee192a9
3 changed files with 12 additions and 2 deletions

View File

@ -10,7 +10,7 @@ module ActiveModel
def serializable_hash(options = nil)
options ||= {}
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
hash = {}

View File

@ -7,7 +7,7 @@ module ActiveModel
def serializable_hash(options = nil)
options ||= {}
{ root => Attributes.new(serializer).serializable_hash(options) }
{ root => Attributes.new(serializer, instance_options).serializable_hash(options) }
end
private

View File

@ -75,6 +75,16 @@ module ActiveModel
assert_equal 1, adapter.serializable_hash[:virtual_values].length
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