Sha256: 3cf308b8893d8b645bf70e976f64e1d1ceb642a5d33623ed8dad2f9a7596cdcf

Contents?: true

Size: 1.91 KB

Versions: 9

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..','test_helper'))
require 'new_relic/agent/hash_extensions'

class HashExtensionsTest < Minitest::Test

  def test_stringify_keys_in_object_with_nested_hash
    hash = {:foo => {:bar => [{:baz => "qux"}, "quux"]}}
    expected = {"foo" => {"bar" => [{"baz" => "qux"}, "quux"]}}

    actual = NewRelic::Agent::HashExtensions.stringify_keys_in_object(hash)

    assert_equal expected, actual
  end

  def test_stringify_keys_in_object_with_array
    array = ["foo", {:bar => [{:baz => "qux"}, "quux"]}]
    expected = ["foo", {"bar" => [{"baz" => "qux"}, "quux"]}]

    actual = NewRelic::Agent::HashExtensions.stringify_keys_in_object(array)

    assert_equal expected, actual
  end

  def test_stringify_keys_in_object_does_not_mutate_argument
    arg = {:foo => "bar"}
    result = NewRelic::Agent::HashExtensions.stringify_keys_in_object(arg)
    refute_same arg, result
    assert_includes arg.keys, :foo
  end

  def test_symbolize_keys_in_object_with_nested_hash
    hash = {"foo" => {"bar" => [{"baz" => "qux"}, "quux"]}}
    expected = {:foo => {:bar => [{:baz => "qux"}, "quux"]}}

    actual = NewRelic::Agent::HashExtensions.symbolize_keys_in_object(hash)

    assert_equal expected, actual
  end

  def test_symbolize_keys_in_object_with_array
    array = ["foo", {"bar" => [{"baz" => "qux"}, "quux"]}]
    expected = ["foo", {:bar => [{:baz => "qux"}, "quux"]}]

    actual = NewRelic::Agent::HashExtensions.symbolize_keys_in_object(array)

    assert_equal expected, actual
  end

  def test_symbolize_keys_in_object_does_not_mutate_argument
    arg = {"foo" => "bar"}
    result = NewRelic::Agent::HashExtensions.symbolize_keys_in_object(arg)
    refute_same arg, result
    assert_includes arg.keys, "foo"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
newrelic_rpm-3.18.1.330 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.18.0.329 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.17.2.327 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.17.1.326 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.17.0.325 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.16.3.323 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.16.2.321 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.16.1.320 test/new_relic/agent/hash_extensions_test.rb
newrelic_rpm-3.16.0.318 test/new_relic/agent/hash_extensions_test.rb