Sha256: 83207b5f38501e4dfb393d9fd1ca8b392fed49314536b62f71567f1ad524334c

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

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

module Paid
  class UtilTest < ::Test::Unit::TestCase
    context '#symbolize_keys' do
      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
    end

    context '#sorta_deep_clone' do
      # Super hand wavy test.. but it works for now so whatever.
      should 'clone well enough that we dont accidentally alter json' do
        start = { :a => "abc", :b => [ { :c => "c-1" }, { :c => "c-2" } ] }
        cloned = Util.sorta_deep_clone(start)

        cloned[:a] = "123"
        cloned[:b] << { :c => "c-3" }
        cloned[:b][0][:c] = "c-one"

        assert_equal({ :a => "abc", :b => [ { :c => "c-1" }, { :c => "c-2" } ] }, start)
      end
    end

    context '#constantize' do
      should 'convert :APIResource to the class object' do
        assert_equal(APIResource, Util.constantize(:APIResource))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paid-1.0.5 test/paid/util_test.rb
paid-1.0.3 test/paid/util_test.rb
paid-1.0.2 test/paid/util_test.rb