Sha256: 66f5ac0858b2a39da6fbefd528cb19729f90c9071f6dac2aecd46bc5354ec9a0
Contents?: true
Size: 1.38 KB
Versions: 31
Compression:
Stored size: 1.38 KB
Contents
require 'spec_helper' describe '#flatten_keys_to_joined_string' do it 'flattens a deep hash into a shallow one' do deep = {'a' => {'b' => {'c' => {'d' => 'e'}}}} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a::b::c::d' => 'e'}) end it 'handles duplicate keys' do deep = {'a' => {'a' => {'a' => {'a' => 'a'}}}} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a::a::a::a' => 'a'}) end it 'creates keys for each grandchilds values' do deep = {'a' => {'b' => 'c', 'd' => 'e'}} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a::b' => 'c'}) expect(shallow).to include({'a::d' => 'e'}) end it 'does not change keys with ::' do deep = {'a::b' => {'c::d' => 'e'}} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a::b::c::d' => 'e'}) end it 'does not blow up on an empty hash' do deep = {} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({}) end it 'converts key symbols to strings' do deep = {:a => 'b'} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a' => 'b'}) end it 'converts nested key symbols to strings' do deep = {:a => {:b => 'c'}} shallow = flatten_keys_to_joined_string(deep) expect(shallow).to include({'a::b' => 'c'}) end end
Version data entries
31 entries across 31 versions & 1 rubygems