Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5e47b9a9
Commit
5e47b9a9
authored
Sep 30, 2019
by
allison.browne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine InlineHash specs into fewer examples
parent
5335b855
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
76 deletions
+47
-76
spec/lib/gitlab/utils/inline_hash_spec.rb
spec/lib/gitlab/utils/inline_hash_spec.rb
+47
-76
No files found.
spec/lib/gitlab/utils/inline_hash_spec.rb
View file @
5e47b9a9
...
...
@@ -6,93 +6,64 @@ describe Gitlab::Utils::InlineHash do
describe
'.merge_keys'
do
subject
{
described_class
.
merge_keys
(
source
)
}
context
'with string keys'
do
let
(
:source
)
do
{
nested_param:
{
key:
'Value'
}
,
'root_param'
=>
'Root'
,
'very'
=>
{
'deep
'
=>
{
'nested
'
=>
{
'param'
=>
'Deep nested value'
}
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'
,
'very.deep.nested.param'
=>
'Deep nested value'
)
end
it
'retains key insertion order'
do
expect
(
subject
.
keys
)
.
to
eq
(
%w(nested_param.key root_param 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'
,
'very::deep::nested::param'
=>
'Deep nested value'
)
end
end
}
end
context
'with a starter prefix'
do
subject
{
described_class
.
merge_keys
(
source
,
prefix:
'options'
)
}
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
'prefixes all the keys'
do
is_expected
.
to
eq
(
'options.nested_param.key'
=>
'Value'
,
'options.root_param'
=>
'Root'
,
'options.very.deep.nested.param'
=>
'Deep nested value'
)
end
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 un-nested symbol or numeric keys'
do
let
(
:unested_symbol_key_source
)
do
{
unnested_symbol_key: :unnested_symbol_value
,
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
,
nested_symbol_key:
{
nested_symbol_key_2: :nested_symbol_value
}
}
'very::deep::nested::param'
=>
'Deep nested value'
)
end
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 a starter prefix'
do
subject
{
described_class
.
merge_keys
(
source
,
prefix:
'options'
)
}
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.12'
=>
22
,
'options.nested_symbol_key.nested_symbol_key_2'
=>
:nested_symbol_value
)
end
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment