Skip to content

Commit

Permalink
add more tests surrounding camlize in xmlmini, refactor rename_key()
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 3, 2010
1 parent ea0faa2 commit 6362538
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 2 additions & 6 deletions activesupport/lib/active_support/xml_mini.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,10 @@ def to_tag(key, value, options)
end

def rename_key(key, options = {})
camelize = options.has_key?(:camelize) && options[:camelize]
camelize = options[:camelize]
dasherize = !options.has_key?(:dasherize) || options[:dasherize]
if camelize
if options[:camelize] == :lower
key = key.camelize(:lower)
else
key = key.camelize
end
key = true == camelize ? key.camelize : key.camelize(camelize)
end
key = _dasherize(key) if dasherize
key
Expand Down
12 changes: 12 additions & 0 deletions activesupport/test/test_xml_mini.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ 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
Expand All @@ -22,6 +30,10 @@ 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
Expand Down

0 comments on commit 6362538

Please sign in to comment.