Skip to content

Commit e6d1d6b

Browse files
committed
Merge pull request #1320 from barodeur/include-array-of-string
Add test and bugfix to include an array of string
2 parents 0200d89 + 6407dbe commit e6d1d6b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/active_model/serializer/include_tree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def include_args_to_hash(included)
5252
hash[key] = include_args_to_hash(value)
5353
end
5454
when Array
55-
included.reduce({}) { |a, e| a.merge!(include_args_to_hash(e)) }
55+
included.reduce({}) { |a, e| a.deep_merge!(include_args_to_hash(e)) }
5656
when String
5757
include_string_to_hash(included)
5858
else

test/include_tree/include_args_to_hash_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ def test_include_args_to_hash_from_array_of_hashes
4444

4545
assert_equal(expected, actual)
4646
end
47+
48+
def test_array_of_string
49+
expected = {
50+
comments: { author: {}, attachment: {} }
51+
}
52+
input = [
53+
'comments.author',
54+
'comments.attachment'
55+
]
56+
actual = Parsing.include_args_to_hash(input)
57+
58+
assert_equal(expected, actual)
59+
end
4760
end
4861
end
4962
end

0 commit comments

Comments
 (0)