Sha256: a76e229f2629d7a10e78bb2114128f6e407016a86bf1ef9ea9aba798d1f28a2b

Contents?: true

Size: 1.47 KB

Versions: 27

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe Hieracles::Utils do
  include Hieracles::Utils

  it '.deep_sort' do
    hash = {
      b: '',
      a: { aa: 'aa' },
      d: 'd',
      c: [cb: %w(b a c), ca: { caa: 'caa' }]
    }
    expected = {
      a: { aa: 'aa' },
      b: '',
      c: [ca: { caa: 'caa' }, cb: %w(a b c)],
      d: 'd'
    }
    expect(deep_sort hash).to eq expected
  end

  describe '.to_deep_hash' do
    before :each do
      @shallow_hash = {
        'pressrelease.label.one' => 'Pressmeddelande',
        'pressrelease.label.other' => 'Pressmeddelanden',
        'article' => 'Artikel',
        'category' => ''
      }
      @deep_hash = {
        pressrelease: {
          label: {
            one: 'Pressmeddelande',
            other: 'Pressmeddelanden'
          }
        },
        article: 'Artikel',
        category: ''
      }
    end

    it 'convert shallow hash with dot separated keys to deep hash' do
      expect(to_deep_hash @shallow_hash).to eq @deep_hash
    end

    it 'converts a deep hash to a shallow one' do
      expect(to_shallow_hash @deep_hash).to eq @shallow_hash
    end
  end

  describe '.max_key_length' do
    let(:hash) { { 'key1' => nil, 'key22' => nil, 'key9chars' => nil } }
    it { expect(max_key_length hash).to eq 9 }
  end

  describe '.sym_keys' do
    let(:hash) { { 'key1' => '1', 'key22' => '2', 'key9chars' => 3 } }
    let(:expected) { { key1: '1', key22: '2', key9chars: 3 } }
    it { expect(sym_keys hash).to eq expected }
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
hieracles-0.4.2 spec/lib/utils_spec.rb
hieracles-0.4.1 spec/lib/utils_spec.rb
hieracles-0.4.0 spec/lib/utils_spec.rb
hieracles-0.3.6 spec/lib/utils_spec.rb
hieracles-0.3.5 spec/lib/utils_spec.rb
hieracles-0.3.4 spec/lib/utils_spec.rb
hieracles-0.3.3 spec/lib/utils_spec.rb
hieracles-0.3.2 spec/lib/utils_spec.rb
hieracles-0.3.1 spec/lib/utils_spec.rb
hieracles-0.3.0 spec/lib/utils_spec.rb
hieracles-0.2.2 spec/lib/utils_spec.rb
hieracles-0.2.1 spec/lib/utils_spec.rb
hieracles-0.2.0 spec/lib/utils_spec.rb
hieracles-0.1.7 spec/lib/utils_spec.rb
hieracles-0.1.6 spec/lib/utils_spec.rb
hieracles-0.1.5 spec/lib/utils_spec.rb
hieracles-0.1.4 spec/lib/utils_spec.rb
hieracles-0.1.3 spec/lib/utils_spec.rb
hieracles-0.1.2 spec/lib/utils_spec.rb
hieracles-0.1.1 spec/lib/utils_spec.rb