diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 0147c8fd4d..e9c6884c7d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Base#to_xml supports the nil="true" attribute like Hash#to_xml. #8268 [Catfish]
+
* Change plings to the more conventional quotes in the documentation. Closes #10104 [danger]
* Fix HasManyThrough Association so it uses :conditions on the HasMany Association. Closes #9729 [danger]
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index 28e9b3ddc6..693060f06e 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -271,6 +271,10 @@ module ActiveRecord #:nodoc:
decorations[:type] = type
end
+ if value.nil?
+ decorations[:nil] = true
+ end
+
decorations
end
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index e17b2a1b57..ee34d201b8 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1555,7 +1555,7 @@ class BasicsTest < Test::Unit::TestCase
assert xml.include?(%(#{written_on_in_current_timezone}))
assert xml.include?(%(--- Have a nice day\n))
assert xml.include?(%(david@loudthinking.com))
- assert xml.match(%())
+ assert xml.include?(%())
if current_adapter?(:SybaseAdapter, :SQLServerAdapter, :OracleAdapter)
assert xml.include?(%(#{last_read_in_current_timezone}))
else
diff --git a/activerecord/test/xml_serialization_test.rb b/activerecord/test/xml_serialization_test.rb
index a5da55cd8d..011f27ad14 100644
--- a/activerecord/test/xml_serialization_test.rb
+++ b/activerecord/test/xml_serialization_test.rb
@@ -78,29 +78,43 @@ class NilXmlSerializationTest < Test::Unit::TestCase
end
def test_should_serialize_string
- assert_match %r{}, @xml
+ assert_match %r{}, @xml
end
def test_should_serialize_integer
- assert_match %r{}, @xml
+ assert %r{}.match(@xml)
+ attributes = $1
+ assert_match %r{nil="true"}, attributes
+ assert_match %r{type="integer"}, attributes
end
def test_should_serialize_binary
- assert_match %r{>}, @xml
- assert_match %r{}.match(@xml)
+ attributes = $1
+ assert_match %r{type="binary"}, attributes
+ assert_match %r{encoding="base64"}, attributes
+ assert_match %r{nil="true"}, attributes
end
def test_should_serialize_datetime
- assert_match %r{}, @xml
+ assert %r{}.match(@xml)
+ attributes = $1
+ assert_match %r{nil="true"}, attributes
+ assert_match %r{type="datetime"}, attributes
end
def test_should_serialize_boolean
- assert_match %r{}, @xml
+ assert %r{}.match(@xml)
+ attributes = $1
+ assert_match %r{type="boolean"}, attributes
+ assert_match %r{nil="true"}, attributes
end
def test_should_serialize_yaml
- assert_match %r{}, @xml
+ assert %r{}.match(@xml)
+ attributes = $1
+ assert_match %r{type="yaml"}, attributes
+ assert_match %r{nil="true"}, attributes
end
end