Commit 5e47b9a9 authored by allison.browne's avatar allison.browne

Combine InlineHash specs into fewer examples

parent 5335b855
...@@ -6,13 +6,14 @@ describe Gitlab::Utils::InlineHash do ...@@ -6,13 +6,14 @@ describe Gitlab::Utils::InlineHash do
describe '.merge_keys' do describe '.merge_keys' do
subject { described_class.merge_keys(source) } subject { described_class.merge_keys(source) }
context 'with string keys' do
let(:source) do let(:source) do
{ {
nested_param: { nested_param: {
key: 'Value' key: :Value
}, },
'root_param' => 'Root', 'root_param' => 'Root',
unnested_symbol_key: :unnested_symbol_value,
12 => 22,
'very' => { 'very' => {
'deep' => { 'deep' => {
'nested' => { 'nested' => {
...@@ -25,15 +26,17 @@ describe Gitlab::Utils::InlineHash do ...@@ -25,15 +26,17 @@ describe Gitlab::Utils::InlineHash do
it 'transforms a nested hash into a one-level hash' do it 'transforms a nested hash into a one-level hash' do
is_expected.to eq( is_expected.to eq(
'nested_param.key' => 'Value', 'nested_param.key' => :Value,
'root_param' => 'Root', 'root_param' => 'Root',
:unnested_symbol_key => :unnested_symbol_value,
12 => 22,
'very.deep.nested.param' => 'Deep nested value' 'very.deep.nested.param' => 'Deep nested value'
) )
end end
it 'retains key insertion order' do it 'retains key insertion order' do
expect(subject.keys) expect(subject.keys)
.to eq(%w(nested_param.key root_param very.deep.nested.param)) .to eq(['nested_param.key', 'root_param', :unnested_symbol_key, 12, 'very.deep.nested.param'])
end end
context 'with a custom connector' do context 'with a custom connector' do
...@@ -41,8 +44,10 @@ describe Gitlab::Utils::InlineHash do ...@@ -41,8 +44,10 @@ describe Gitlab::Utils::InlineHash do
it 'uses the connector to merge keys' do it 'uses the connector to merge keys' do
is_expected.to eq( is_expected.to eq(
'nested_param::key' => 'Value', 'nested_param::key' => :Value,
'root_param' => 'Root', 'root_param' => 'Root',
:unnested_symbol_key => :unnested_symbol_value,
12 => 22,
'very::deep::nested::param' => 'Deep nested value' 'very::deep::nested::param' => 'Deep nested value'
) )
end end
...@@ -53,47 +58,13 @@ describe Gitlab::Utils::InlineHash do ...@@ -53,47 +58,13 @@ describe Gitlab::Utils::InlineHash do
it 'prefixes all the keys' do it 'prefixes all the keys' do
is_expected.to eq( is_expected.to eq(
'options.nested_param.key' => 'Value', 'options.nested_param.key' => :Value,
'options.root_param' => 'Root', 'options.root_param' => 'Root',
'options.very.deep.nested.param' => 'Deep nested value'
)
end
end
end
context 'with un-nested symbol or numeric keys' do
let(:unested_symbol_key_source) do
{
unnested_symbol_key: :unnested_symbol_value,
12 => 22,
nested_symbol_key: {
nested_symbol_key_2: :nested_symbol_value
}
}
end
context 'without prefix' do
subject { described_class.merge_keys(unested_symbol_key_source) }
it 'converts only nested keys to inline strings' do
is_expected.to eq(
:unnested_symbol_key => :unnested_symbol_value,
12 => 22,
'nested_symbol_key.nested_symbol_key_2' => :nested_symbol_value
)
end
end
context 'with prefix' do
subject { described_class.merge_keys(unested_symbol_key_source, prefix: 'options') }
it 'converts prefixed keys to inline strings' do
is_expected.to eq(
'options.unnested_symbol_key' => :unnested_symbol_value, 'options.unnested_symbol_key' => :unnested_symbol_value,
'options.12' => 22, 'options.12' => 22,
'options.nested_symbol_key.nested_symbol_key_2' => :nested_symbol_value 'options.very.deep.nested.param' => 'Deep nested value'
) )
end end
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment