From 29cbfa2f33b2d0e2d16a203941998687af7831db Mon Sep 17 00:00:00 2001 From: Geoff Petrie & Sean Griffin Date: Sun, 1 Jun 2014 11:40:40 -0600 Subject: Test the serialized types of virtual columns in XML The previous tests were passing, because nothing ever looked at the generated XML. What was previously being generated was `...`, which is not consistent with all other cases where there is not a known type. --- activerecord/lib/active_record/serializers/xml_serializer.rb | 2 -- activerecord/test/cases/xml_serialization_test.rb | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 1a766093d0..08e8346b49 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -184,8 +184,6 @@ module ActiveRecord #:nodoc: super elsif klass.columns_hash.key?(name) klass.columns_hash[name].type - else - NilClass end { :text => :string, diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index 1a690c01a6..c34e7d5a30 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -416,8 +416,9 @@ class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase def test_should_support_aliased_attributes xml = Author.select("name as firstname").to_xml - array = Hash.from_xml(xml)['authors'] - assert_equal array.size, array.select { |author| author.has_key? 'firstname' }.size + Author.all.each do |author| + assert xml.include?(%(#{author.name})), xml + end end def test_array_to_xml_including_has_many_association -- cgit v1.2.3 From 04919c79d71726aac1732b1d1a305051ceee541b Mon Sep 17 00:00:00 2001 From: Geoff Petrie & Sean Griffin Date: Sun, 1 Jun 2014 12:00:24 -0600 Subject: Refactor XML serializer to not depend on `serialized_attributes` --- activerecord/lib/active_record/serializers/xml_serializer.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 08e8346b49..019fe2218e 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -180,10 +180,12 @@ module ActiveRecord #:nodoc: class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc: def compute_type klass = @serializable.class - type = if klass.serialized_attributes.key?(name) + column = klass.columns_hash[name] || Type::Value.new + + type = if column.serialized? super - elsif klass.columns_hash.key?(name) - klass.columns_hash[name].type + else + column.type end { :text => :string, -- cgit v1.2.3