I looked through 39 tickets looking for this to be reported already, but saw no mention of this defect for this particular edge case.
The following edge case breaks ActiveRecord::Base#to_xml.
Assume:
- The model Legacy::Contact is defined. It is namespaced within the Ruby module, Legacy.
Reproduce issue with following code:
class Legacy::Contact < ActiveRecord::Base
# stuff
end
# in ./script/console
contacts = Legacy::Contact.find :first #=> some Legacy::Contact instance
contacts.to_xml #=> <?xml version=\"1.0\" encoding=\"UTF-8\"?><legacy/contact>\n <age type=\"integer\">25</age>\n <avatar encoding=\"base64\" type=\"binary\">YmluYXJ5ZGF0YQ==\n</avatar>\n <awesome type=\"boolean\">false</awesome>\n <created-at type=\"datetime\">2006-08-01T00:00:00Z</created-at>\n <name>aaron stack</name>\n <preferences type=\"yaml\">--- \n:gem: ruby\n</preferences>\n</legacy/contact>\n
I originally saw this in 1.2.3, then verified in trunk to ensure this is still an issue in trunk (and it is).
I realize there is a workaround for this, but I was hoping the more correct behavior of outputting the following for the last line would be on the cards soon-ish:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<legacy:contact>\n <age type=\"integer\">25</age>\n <avatar encoding=\"base64\" type=\"binary\">YmluYXJ5ZGF0YQ==\n</avatar>\n <awesome type=\"boolean\">false</awesome>\n <created-at type=\"datetime\">2006-08-01T00:00:00Z</created-at>\n <name>aaron stack</name>\n <preferences type=\"yaml\">--- \n:gem: ruby\n</preferences>\n</legacy:contact>\n
Attached to this ticket is a patch that adds the relevant unit test for this edge case in source:trunk/activerecord/test/xml_serialization_test.rb mostly.
I also found the activerecord_unittest.contacts table wasn't defined in source:trunk/activerecord/test/fixtures/db_definitions/mysql.sql, so I added it to get it to work for my test environment.