Sha256: ad3309d28c359069f1c74ffa1ec17ad130c10753fab7b467896cd98127a5211c

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

require 'spec_helper'

describe TwitterCldr::Utils do
  describe '#deep_symbolize_keys' do

    let(:hash) { { 'foo' => { 'bar' => { 'baz' => 'woot' }, :ar => [1, 2] }, 42 => { 'baz' => 'wat' } } }

    let(:symbolized_hash) { { :foo => { :bar => { :baz => 'woot' }, :ar => [1, 2] }, 42 => { :baz => 'wat' } } }

    it 'symbolizes string keys of a hash' do
      TwitterCldr::Utils.deep_symbolize_keys(hash).should == symbolized_hash
    end

    it 'deeply symbolizes elements of an array' do
      TwitterCldr::Utils.deep_symbolize_keys([1, hash, 'foo', :bar]).should == [1, symbolized_hash, 'foo', :bar]
    end

    it 'deeply symbolizes elements of an array nested in a hash' do
      TwitterCldr::Utils.deep_symbolize_keys({ 'foo' => [1, hash] }).should == { :foo => [1, symbolized_hash] }
    end

    it 'leaves arguments of other types alone' do
      ['foo', :bar, 42].each { |arg| TwitterCldr::Utils.deep_symbolize_keys(arg).should == arg }
    end

  end

  describe "#compute_cache_key" do
    it "returns a ruby hash of all the pieces concatenated with pipe characters" do
      TwitterCldr::Utils.compute_cache_key("space", "the", "final", "frontier").should == "space|the|final|frontier".hash
    end

    it "returns zero if no arguments are passed" do
      TwitterCldr::Utils.compute_cache_key.should == 0
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
twitter_cldr-1.5.0 spec/utils_spec.rb
twitter_cldr-1.4.1 spec/utils_spec.rb
twitter_cldr-1.4.0 spec/utils_spec.rb