Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

to_json and to_xml tests added to ActiveResource

[#4529 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit c4ef7bb2a0a2e2351f5ed2b1f98c9b40c441591e 1 parent 7cbc546
Santiago Pastorino spastorino authored jeremy committed
Showing with 34 additions and 0 deletions.
  1. +34 −0 activeresource/test/base_test.rb
34 activeresource/test/base_test.rb
View
@@ -1008,6 +1008,21 @@ def test_to_xml
assert xml.include?('<id type="integer">1</id>')
end
+ def test_to_xml_with_element_name
+ old_elem_name = Person.element_name
+ matz = Person.find(1)
+ Person.element_name = 'ruby_creator'
+ xml = matz.encode
+
+ assert xml.include?('<?xml version="1.0" encoding="UTF-8"?>')
+ assert xml.include?('<ruby-creator>')
+ assert xml.include?('<name>Matz</name>')
+ assert xml.include?('<id type="integer">1</id>')
+ assert xml.include?('</ruby-creator>')
+ ensure
+ Person.element_name = old_elem_name
+ end
+
def test_to_json_including_root
Person.include_root_in_json = true
Person.format = :json
@@ -1018,6 +1033,25 @@ def test_to_json_including_root
assert_match '"id":6', json
ensure
Person.format = :xml
+ Person.include_root_in_json = false
+ end
+
+ def test_to_json_with_element_name
+ old_elem_name = Person.element_name
+ Person.include_root_in_json = true
+ Person.format = :json
+ joe = Person.find(6)
+ Person.element_name = 'ruby_creator'
+ json = joe.encode
+ Person.format = :xml
+
+ assert_match %r{^\{"ruby_creator":\{"person":\{}, json
+ assert_match %r{"id":6}, json
+ assert_match %r{"name":"Joe"}, json
+ assert_match %r{\}\}\}$}, json
+ ensure
+ Person.element_name = old_elem_name
+ Person.include_root_in_json = false
end
def test_to_param_quacks_like_active_record
Please sign in to comment.
Something went wrong with that request. Please try again.