Skip to content

Commit

Permalink
Made arrays of ActiveRecords, and any classes, with namespaces conver…
Browse files Browse the repository at this point in the history
…t to valid xml. [#3824 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
fosrias authored and josevalim committed Apr 10, 2010
1 parent dc97430 commit 5850edf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion activerecord/test/cases/xml_serialization_test.rb
Expand Up @@ -130,10 +130,20 @@ def test_should_serialize_yaml
end

class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
fixtures :authors, :posts
fixtures :authors, :posts, :projects

# to_xml used to mess with the hash the user provided which
# caused the builder to be reused. This meant the document kept
# getting appended to.

def test_modules
projects = MyApplication::Business::Project.all
xml = projects.to_xml
root = projects.first.class.to_s.underscore.pluralize.tr('/','_').dasherize
assert_match "<#{root} type=\"array\">", xml
assert_match "</#{root}>", xml
end

def test_passing_hash_shouldnt_reuse_builder
options = {:include=>:posts}
david = authors(:david)
Expand Down
Expand Up @@ -131,7 +131,7 @@ def to_xml(options = {})
require 'builder' unless defined?(Builder)

options = options.dup
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.name)) : "records"
options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.name)).tr('/', '_') : "records"
options[:children] ||= options[:root].singularize
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
Expand Down

0 comments on commit 5850edf

Please sign in to comment.