diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 16:56:42 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-04 22:49:42 +0200 |
commit | 06e00913f505268e0a45f4f1516a93a84600c242 (patch) | |
tree | caa989d5a3a299cd1c1a1e6a13f90239ad1aed84 /spec/lib/gitlab/utils | |
parent | 08383fd2e32b88bba1429cf9b03b493dfc6b9b3e (diff) | |
download | gitlab-ce-06e00913f505268e0a45f4f1516a93a84600c242.tar.gz |
Move merging of Hashes out of the `GroupDescendant` concern
Since it can technically merge any hash with objects that respond to `==`
Diffstat (limited to 'spec/lib/gitlab/utils')
-rw-r--r-- | spec/lib/gitlab/utils/merge_hash_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils/merge_hash_spec.rb b/spec/lib/gitlab/utils/merge_hash_spec.rb new file mode 100644 index 00000000000..4fa7bb31301 --- /dev/null +++ b/spec/lib/gitlab/utils/merge_hash_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +describe Gitlab::Utils::MergeHash do + describe '.crush' do + it 'can flatten a hash to each element' do + input = { hello: "world", this: { crushes: ["an entire", "hash"] } } + expected_result = [:hello, "world", :this, :crushes, "an entire", "hash"] + + expect(described_class.crush(input)).to eq(expected_result) + end + end + + describe '.elements' do + it 'deep merges an array of elements' do + input = [{ hello: ["world"] }, + { hello: "Everyone" }, + { hello: { greetings: ['Bonjour', 'Hello', 'Hallo', 'Dzień dobry'] } }, + "Goodbye", "Hallo"] + expected_output = [ + { + hello: + [ + "world", + "Everyone", + { greetings: ['Bonjour', 'Hello', 'Hallo', 'Dzień dobry'] } + ] + }, + "Goodbye" + ] + + expect(described_class.merge(input)).to eq(expected_output) + end + end +end |