Sha256: 929544aae27049a77b7f98ab6743c4fa379b9dd4e8f8fbeda6b904f1127a100a
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
require 'spec_helper' describe 'key_conversion' do it 'should convert keys to lowercase by default' do { 'HELLO' => 'world' }.convert_keys.should eq 'hello' => 'world' end it 'should convert the key to a string if it is a symbol' do { hello: "world" }.convert_keys.should eq 'hello' => 'world' end it 'should accept any method you can call on a string to convert the key' do { hello: "world" }.convert_keys(:upcase).should eq 'HELLO' => 'world' end it 'should convert nested hashes with the same logic' do { 'HELLO' => { 'MR' => 'world' } }.convert_keys.should eq 'hello' => {'mr' => 'world'} end it 'should be both an instance and class method' do Hash.new.should respond_to(:convert_keys) Hash.should respond_to(:convert_keys) end it 'should convert an array of hashes with the same logic' do Hash.convert_keys([{ 'HELLO' => 'world' }, { 'FOO' => 'bar' }]).should eq [{ 'hello' => 'world' }, { 'foo' => 'bar' }] end it 'should convert arrays of hashes' do { 'HELLO' => [{ 'MR' => 'world' }] }.convert_keys.should eq 'hello' => [{'mr' => 'world'}] end it 'should not convert values other than arrays and hashes' do Hash.convert_keys("HELLO WORLD").should eq "HELLO WORLD" end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hash-pipe-0.1.1 | spec/hash-pipe/key_conversion_spec.rb |
hash-pipe-0.1.0 | spec/hash-pipe/key_conversion_spec.rb |
hash-pipe-0.0.2 | spec/hash-pipe/key_conversion_spec.rb |