/
hash_utils_spec.rb
35 lines (26 loc) · 1 KB
/
hash_utils_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true
RSpec.describe Surrealist::HashUtils do
describe '#camelize_hash' do
subject(:camelized_hash) { described_class.camelize_hash(hash) }
context 'not nested hash' do
let(:hash) { { snake_key: 'some value' } }
it { expect(camelized_hash.keys.first).to eq(:snakeKey) }
end
context 'nested hash' do
let(:hash) { { snake_key: { nested_key: { one_more_level: true } } } }
it 'camelizes hash recursively' do
expect(camelized_hash).to eq(snakeKey: { nestedKey: { oneMoreLevel: true } })
end
end
context 'mixed symbols and string' do
let(:hash) { { snake_key: { 'nested_key' => { 'one_more_level': true } } } }
it 'camelizes hash recursively' do
expect(camelized_hash).to eq(snakeKey: { 'nestedKey' => { 'oneMoreLevel': true } })
end
end
context 'array as hash key' do
let(:hash) { { ['some_key'] => 'value' } }
it { expect(camelized_hash.keys.first).to eq(['some_key']) }
end
end
end