From 6407dbeadd675bb538b62469978f84ab4ebbe00d Mon Sep 17 00:00:00 2001 From: Paul Chobert Date: Fri, 6 Nov 2015 17:23:25 +0100 Subject: [PATCH] Add test and bugfix to include an array of string --- lib/active_model/serializer/include_tree.rb | 2 +- test/include_tree/include_args_to_hash_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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