Skip to content

Commit

Permalink
Merge pull request #1185 from beauby/fix-attributes-include
Browse files Browse the repository at this point in the history
Fix options passing in Json and Attributes adapters
  • Loading branch information
NullVoxPopuli committed Sep 21, 2015
2 parents aaa60bf + 4976837 commit 94cee19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/active_model/serializer/adapter/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(serializer, options = {})
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 = {}

Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/adapter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Json < Base

def serializable_hash(options = nil)
options ||= {}
{ root => Attributes.new(serializer).serializable_hash(options) }
{ root => Attributes.new(serializer, instance_options).serializable_hash(options) }
end

private
Expand Down
10 changes: 10 additions & 0 deletions test/adapter/json/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def test_root_is_underscored

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
Expand Down

0 comments on commit 94cee19

Please sign in to comment.