Sha256: ca6149fbb3a35277bb8ffcaec1a3c32240e51f2f33d3a73982fa0bcd02ca8449

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::Utils do
  context '.sanitize_keys' do
    before do
      @subject = Hyperdrive::Utils.sanitize_keys([:keep], { keep: 'this', remove: 'that' })
    end

    it "removes keys that were specified from the given hash" do
      @subject.key?(:remove).must_equal false
    end

    it "keeps keys that were not specified from the given hash" do
      @subject.key?(:keep).must_equal true
    end
  end

  context '.symbolize_keys' do
    before do
      @hash = { :symbol => 'symbol', 'string' => 'cheese', 'collection' => [{'skylanders' => 155}], 'map' => { 'oceans' => 'blue' } }
      @subject = Hyperdrive::Utils.symbolize_keys(@hash)
    end

    it "can symbolize the keys of a hash" do
      @subject[:string].must_equal 'cheese'
    end

    it "doesn't symbolize keys that aren't a string" do
      @subject[:symbol].must_equal 'symbol'
    end

    it "can symbolize the keys of nested hashes" do
      @subject[:map][:oceans].must_equal 'blue'
    end

    it "can symbolize the keys of arrays of hashes" do
      @subject[:collection].first[:skylanders].must_equal 155
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyperdrive-0.0.21 spec/hyperdrive/utils_spec.rb
hyperdrive-0.0.20 spec/hyperdrive/utils_spec.rb
hyperdrive-0.0.19 spec/hyperdrive/utils_spec.rb
hyperdrive-0.0.18 spec/hyperdrive/utils_spec.rb
hyperdrive-0.0.17 spec/hyperdrive/utils_spec.rb
hyperdrive-0.0.16 spec/hyperdrive/utils_spec.rb