aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/test_xml_mini.rb
blob: 309fa234bfd48cd4e9528d37a207b489d55acfa8 (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'abstract_unit'
require 'active_support/xml_mini'

class XmlMiniTest < Test::Unit::TestCase
  def test_rename_key_dasherizes_by_default
    assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key")
  end

  def test_rename_key_does_nothing_with_dasherize_true
    assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true)
  end

  def test_rename_key_does_nothing_with_dasherize_false
    assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false)
  end

  def test_rename_key_camelizes_with_camelize_false
    assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => false)
  end

  def test_rename_key_camelizes_with_camelize_nil
    assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :camelize => nil)
  end

  def test_rename_key_camelizes_with_camelize_true
    assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true)
  end

  def test_rename_key_lower_camelizes_with_camelize_lower
    assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower)
  end

  def test_rename_key_lower_camelizes_with_camelize_upper
    assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper)
  end

  def test_rename_key_does_not_dasherize_leading_underscores
    assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id")
  end

  def test_rename_key_with_leading_underscore_dasherizes_interior_underscores
    assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key")
  end

  def test_rename_key_does_not_dasherize_trailing_underscores
    assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_")
  end

  def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores
    assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_")
  end

  def test_rename_key_does_not_dasherize_multiple_leading_underscores
    assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id")
  end

  def test_rename_key_does_not_dasherize_multiple_leading_underscores
    assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__")
  end

end