Sha256: 754d69baeeb8be3b87d6954934a974e42416b75dd830d83856a1c70e093b2335

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

module Checkr
  class UtilTest < Test::Unit::TestCase
    should "symbolize_keys should convert keys to symbols" do
      start = {
        'foo' => 'bar',
        'array' => [{ 'foo' => 'bar' }],
        'nested' => {
          1 => 2,
          :symbol => 9,
          'string' => nil
        }
      }
      finish = {
        :foo => 'bar',
        :array => [{ :foo => 'bar' }],
        :nested => {
          1 => 2,
          :symbol => 9,
          :string => nil
        }
      }

      symbolized = Util.symbolize_keys(start)
      assert_equal(finish, symbolized)
    end

    should 'query_array should convert { :a => "value" } to []' do
      start = { :a => "value" }
      finish = ["a=value"]

      assert_equal(finish, Util.query_array(start))
    end

    should 'query_array should convert { :a => { :b => { :c => "cvalue" } } } to ["a[b][c]=cvalue"]' do
      start = { :a => { :b => { :c => "cvalue" } } }
      finish = ["a[b][c]=cvalue"]

      assert_equal(finish, Util.query_array(start))
    end

    should 'query_array should convert { :a => [1, 2] } to ["a[]=1", "a[]=2"]' do
      start = { :a => [1, 2] }
      finish = ["a[]=1", "a[]=2"]

      assert_equal(finish, Util.query_array(start))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
checkr-official-1.0.2 test/checkr/util_test.rb
checkr-official-1.0.1 test/checkr/util_test.rb
checkr-official-1.0.0 test/checkr/util_test.rb