Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (22 sloc) 1.066 kb
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
# 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
end
Something went wrong with that request. Please try again.