aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-05-06 12:35:08 -0300
committerJeremy Kemper <jeremy@bitsweat.net>2010-05-12 09:31:36 -0700
commitbea3c26833ad3e1e94f7331e0553a4e2164e7de5 (patch)
tree67feace8da33b390feff26618e7f42826437a7f9 /activeresource/test
parentf7862b2c34b5b298bf7b937c55f0637ebfe43a25 (diff)
downloadrails-bea3c26833ad3e1e94f7331e0553a4e2164e7de5.tar.gz
rails-bea3c26833ad3e1e94f7331e0553a4e2164e7de5.tar.bz2
rails-bea3c26833ad3e1e94f7331e0553a4e2164e7de5.zip
Make ActiveResource serialize XML correctly when element_name is set.
[#4529] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/cases/base_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index e5f556962b..5df1f411a4 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -1018,6 +1018,23 @@ class BaseTest < Test::Unit::TestCase
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'
+ encode = matz.encode
+ xml = matz.to_xml
+
+ assert encode, xml
+ 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
Person.include_root_in_json = true
Person.format = :json
@@ -1033,6 +1050,25 @@ class BaseTest < Test::Unit::TestCase
assert_match %r{\}\}\}$}, json
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'
+ encode = joe.encode
+ json = joe.to_json
+ Person.format = :xml
+
+ assert encode, json
+ 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
+ end
+
def test_to_param_quacks_like_active_record
new_person = Person.new
assert_nil new_person.to_param