Skip to content

Commit 94cee19

Browse files
committed
Merge pull request #1185 from beauby/fix-attributes-include
Fix options passing in Json and Attributes adapters
2 parents aaa60bf + 4976837 commit 94cee19

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/active_model/serializer/adapter/attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(serializer, options = {})
1010
def serializable_hash(options = nil)
1111
options ||= {}
1212
if serializer.respond_to?(:each)
13-
result = serializer.map { |s| Attributes.new(s).serializable_hash(options) }
13+
result = serializer.map { |s| Attributes.new(s, instance_options).serializable_hash(options) }
1414
else
1515
hash = {}
1616

lib/active_model/serializer/adapter/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Json < Base
77

88
def serializable_hash(options = nil)
99
options ||= {}
10-
{ root => Attributes.new(serializer).serializable_hash(options) }
10+
{ root => Attributes.new(serializer, instance_options).serializable_hash(options) }
1111
end
1212

1313
private

test/adapter/json/collection_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ def test_root_is_underscored
7575

7676
assert_equal 1, adapter.serializable_hash[:virtual_values].length
7777
end
78+
79+
def test_include_option
80+
serializer = ArraySerializer.new([@first_post, @second_post])
81+
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, include: '')
82+
actual = adapter.serializable_hash
83+
expected = { posts: [{ id: 1, title: 'Hello!!', body: 'Hello, world!!' },
84+
{ id: 2, title: 'New Post', body: 'Body' }] }
85+
86+
assert_equal(expected, actual)
87+
end
7888
end
7989
end
8090
end

0 commit comments

Comments
 (0)