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

Version Path
beaker-answers-1.0.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.29.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.28.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.27.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.26.3 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.26.2 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.26.1 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.26.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.25.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.24.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.23.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.22.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.21.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.20.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.19.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.18.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.17.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.16.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.15.0 spec/beaker-answers/helpers_spec.rb
beaker-answers-0.14.0 spec/beaker-answers/helpers_spec.rb