aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/xml_serialization.rb9
-rw-r--r--activerecord/test/xml_serialization_test.rb8
3 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 7d2e21cd83..c9d08632ae 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add a :namespace option to AR::Base#to_xml [Koz]
+
* Deprecation tests. Remove warnings for dynamic finders and for the foo_count method if it's also an attribute. [Jeremy Kemper]
* Mock Time.now for more accurate Touch mixin tests. #6213 [Dan Peterson]
diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb
index 8d1dda5875..54d024fc89 100644
--- a/activerecord/lib/active_record/xml_serialization.rb
+++ b/activerecord/lib/active_record/xml_serialization.rb
@@ -222,12 +222,17 @@ module ActiveRecord #:nodoc:
end
def serialize
- builder.tag!(root) do
+ args = [root]
+ if options[:namespace]
+ args << {:xmlns=>options[:namespace]}
+ end
+
+ builder.tag!(*args) do
add_attributes
add_includes
add_procs
end
- end
+ end
alias_method :to_s, :serialize
diff --git a/activerecord/test/xml_serialization_test.rb b/activerecord/test/xml_serialization_test.rb
index 216d582970..2fd9006821 100644
--- a/activerecord/test/xml_serialization_test.rb
+++ b/activerecord/test/xml_serialization_test.rb
@@ -20,7 +20,13 @@ class XmlSerializationTest < Test::Unit::TestCase
assert_match %r{^<contact>}, @xml
assert_match %r{</contact>$}, @xml
end
-
+
+ def test_should_serialize_default_root_with_namespace
+ @xml = Contact.new.to_xml :namespace=>"http://xml.rubyonrails.org/contact"
+ assert_match %r{^<contact xmlns="http://xml.rubyonrails.org/contact">}, @xml
+ assert_match %r{</contact>$}, @xml
+ end
+
def test_should_serialize_custom_root
@xml = Contact.new.to_xml :root => 'xml_contact'
assert_match %r{^<xml-contact>}, @xml