diff --git a/lib/active_model/serializer/include_tree.rb b/lib/active_model/serializer/include_tree.rb index 28bc2175..d5cbe464 100644 --- a/lib/active_model/serializer/include_tree.rb +++ b/lib/active_model/serializer/include_tree.rb @@ -52,7 +52,7 @@ module ActiveModel hash[key] = include_args_to_hash(value) end when Array - included.reduce({}) { |a, e| a.merge!(include_args_to_hash(e)) } + included.reduce({}) { |a, e| a.deep_merge!(include_args_to_hash(e)) } when String include_string_to_hash(included) else diff --git a/test/include_tree/include_args_to_hash_test.rb b/test/include_tree/include_args_to_hash_test.rb index cb5d5c35..0922f591 100644 --- a/test/include_tree/include_args_to_hash_test.rb +++ b/test/include_tree/include_args_to_hash_test.rb @@ -44,6 +44,19 @@ module ActiveModel assert_equal(expected, actual) end + + def test_array_of_string + expected = { + comments: { author: {}, attachment: {} } + } + input = [ + 'comments.author', + 'comments.attachment' + ] + actual = Parsing.include_args_to_hash(input) + + assert_equal(expected, actual) + end end end end