Sha256: 7933fb3c983d2edb351c3185f26ab93a241d812043691c6b80f845c81238a575

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

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

module Paid
  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 = Paid::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, Paid::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, Paid::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, Paid::Util.query_array(start))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paid-1.0.1 test/paid/util_test.rb
paid-1.0.0 test/paid/util_test.rb