Skip to content

Commit

Permalink
Allowing to_xml :camelize option to be set to :lower to enable lower-…
Browse files Browse the repository at this point in the history
…camelcase tags [#5903 state:resolved]
  • Loading branch information
awebneck authored and tenderlove committed Nov 3, 2010
1 parent 208fb29 commit ea0faa2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Expand Up @@ -70,6 +70,13 @@ def setup
assert_match %r{<CreatedAt}, @xml
end

test "should allow lower-camelized tags" do
@xml = @contact.to_xml :root => 'xml_contact', :camelize => :lower
assert_match %r{^<xmlContact>}, @xml
assert_match %r{</xmlContact>$}, @xml
assert_match %r{<createdAt}, @xml
end

test "should allow skipped types" do
@xml = @contact.to_xml :skip_types => true
assert_match %r{<age>25</age>}, @xml
Expand Down
8 changes: 7 additions & 1 deletion activesupport/lib/active_support/xml_mini.rb
Expand Up @@ -128,7 +128,13 @@ def to_tag(key, value, options)
def rename_key(key, options = {})
camelize = options.has_key?(:camelize) && options[:camelize]
dasherize = !options.has_key?(:dasherize) || options[:dasherize]
key = key.camelize if camelize
if camelize
if options[:camelize] == :lower
key = key.camelize(:lower)
else
key = key.camelize
end
end
key = _dasherize(key) if dasherize
key
end
Expand Down
9 changes: 8 additions & 1 deletion activesupport/test/core_ext/hash_ext_test.rb
Expand Up @@ -486,7 +486,7 @@ def test_to_param_hash
def test_to_param_hash_escapes_its_keys_and_values
assert_equal 'param+1=A+string+with+%2F+characters+%26+that+should+be+%3F+escaped', { 'param 1' => 'A string with / characters & that should be ? escaped' }.to_param
end

def test_to_param_orders_by_key_in_ascending_order
assert_equal 'a=2&b=1&c=0', ActiveSupport::OrderedHash[*%w(b 1 c 0 a 2)].to_param
end
Expand Down Expand Up @@ -525,6 +525,13 @@ def test_one_level_camelize_true
assert xml.include?(%(<Name>David</Name>))
end

def test_one_level_camelize_lower
xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:camelize => :lower))
assert_equal "<person>", xml.first(8)
assert xml.include?(%(<streetName>Paulina</streetName>))
assert xml.include?(%(<name>David</name>))
end

def test_one_level_with_types
xml = { :name => "David", :street => "Paulina", :age => 26, :age_in_millis => 820497600000, :moved_on => Date.new(2005, 11, 15), :resident => :yes }.to_xml(@xml_options)
assert_equal "<person>", xml.first(8)
Expand Down
4 changes: 2 additions & 2 deletions activesupport/test/test_xml_mini.rb
Expand Up @@ -18,8 +18,8 @@ def test_rename_key_camelizes_with_camelize_true
assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true)
end

def test_rename_key_camelizes_with_camelize_true
assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true)
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_does_not_dasherize_leading_underscores
Expand Down

0 comments on commit ea0faa2

Please sign in to comment.