From e0a108b76726e0ad1fa69dc3e91f0ab978f06c92 Mon Sep 17 00:00:00 2001 From: Blythe Dunham Date: Tue, 26 May 2009 15:36:31 -0700 Subject: [PATCH] Demodulize class names to generate proper xml --- .../active_record/serializers/xml_serializer.rb | 4 ++-- activerecord/test/cases/xml_serialization_test.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 4eaf953..4358b5a 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -181,7 +181,7 @@ module ActiveRecord #:nodoc: end def root - root = (options[:root] || @record.class.to_s.underscore).to_s + root = (options[:root] || @record.class.to_s.demodulize.underscore).to_s reformat_name(root) end @@ -245,7 +245,7 @@ module ActiveRecord #:nodoc: if options[:skip_types] record_type = {} else - record_class = (record.class.to_s.underscore == association_name) ? nil : record.class.name + record_class = (record.class.to_s.demodulize.underscore == association_name) ? nil : record.class.name record_type = {:type => record_class} end diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index b499976..a994b39 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -4,6 +4,7 @@ require 'models/post' require 'models/author' require 'models/tagging' require 'models/comment' +require 'models/company_in_module' class XmlSerializationTest < ActiveRecord::TestCase def test_should_serialize_default_root @@ -129,6 +130,25 @@ class NilXmlSerializationTest < ActiveRecord::TestCase end end +class DatabaseConnectedXmlModuleSerializationTest < ActiveRecord::TestCase + + fixtures :projects, :developers, :developers_projects + + def test_module + project = MyApplication::Business::Project.find :first + xml = project.to_xml + assert_match %r{}, xml + assert_match %r{}, xml + end + + def test_module_with_include + project = MyApplication::Business::Project.find :first + xml = project.to_xml :include => :developers + assert_match %r{}, xml + assert_match %r{}, xml + end +end + class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase fixtures :authors, :posts # to_xml used to mess with the hash the user provided which -- 1.6.1.3