diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 11:31:16 +0000 |
commit | 905c1110b08f93a19661cf42a276c7ea90d0a0ff (patch) | |
tree | 756d138db422392c00471ab06acdff92c5a9b69c /spec/lib/gitlab/utils/inline_hash_spec.rb | |
parent | 50d93f8d1686950fc58dda4823c4835fd0d8c14b (diff) | |
download | gitlab-ce-905c1110b08f93a19661cf42a276c7ea90d0a0ff.tar.gz |
Add latest changes from gitlab-org/gitlab@12-4-stable-ee
Diffstat (limited to 'spec/lib/gitlab/utils/inline_hash_spec.rb')
-rw-r--r-- | spec/lib/gitlab/utils/inline_hash_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils/inline_hash_spec.rb b/spec/lib/gitlab/utils/inline_hash_spec.rb new file mode 100644 index 00000000000..867db0b92a5 --- /dev/null +++ b/spec/lib/gitlab/utils/inline_hash_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +describe Gitlab::Utils::InlineHash do + describe '.merge_keys' do + subject { described_class.merge_keys(source) } + + let(:source) do + { + nested_param: { + key: :Value + }, + 'root_param' => 'Root', + unnested_symbol_key: :unnested_symbol_value, + 12 => 22, + 'very' => { + 'deep' => { + 'nested' => { + 'param' => 'Deep nested value' + } + } + } + } + end + + it 'transforms a nested hash into a one-level hash' do + is_expected.to eq( + 'nested_param.key' => :Value, + 'root_param' => 'Root', + :unnested_symbol_key => :unnested_symbol_value, + 12 => 22, + 'very.deep.nested.param' => 'Deep nested value' + ) + end + + it 'retains key insertion order' do + expect(subject.keys) + .to eq(['nested_param.key', 'root_param', :unnested_symbol_key, 12, 'very.deep.nested.param']) + end + + context 'with a custom connector' do + subject { described_class.merge_keys(source, connector: '::') } + + it 'uses the connector to merge keys' do + is_expected.to eq( + 'nested_param::key' => :Value, + 'root_param' => 'Root', + :unnested_symbol_key => :unnested_symbol_value, + 12 => 22, + 'very::deep::nested::param' => 'Deep nested value' + ) + end + end + + context 'with a starter prefix' do + subject { described_class.merge_keys(source, prefix: 'options') } + + it 'prefixes all the keys' do + is_expected.to eq( + 'options.nested_param.key' => :Value, + 'options.root_param' => 'Root', + 'options.unnested_symbol_key' => :unnested_symbol_value, + 'options.12' => 22, + 'options.very.deep.nested.param' => 'Deep nested value' + ) + end + end + end +end |