File: key_transform_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require "test_helper"

# Tests key transformation helpers
class KeyTransformTest < Minitest::Test
  cover "MultiXml*"
  include MultiXml::Helpers

  def test_undasherize_keys_with_array
    input = [{"first-name" => "John"}, {"last-name" => "Doe"}]

    assert_equal [{"first_name" => "John"}, {"last_name" => "Doe"}], undasherize_keys(input)
  end

  def test_undasherize_keys_with_nested_array
    assert_equal({"users" => [{"first_name" => "John"}]}, undasherize_keys({"users" => [{"first-name" => "John"}]}))
  end

  def test_undasherize_keys_with_plain_value
    assert_equal "plain string", undasherize_keys("plain string")
  end

  def test_symbolize_keys_with_array
    assert_equal [{name: "John"}, {name: "Jane"}], symbolize_keys([{"name" => "John"}, {"name" => "Jane"}])
  end
end