diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-04 11:03:28 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-04 11:03:28 -0300 |
commit | ed38c5a4854e32fe9e57975812b45a8bb67a8719 (patch) | |
tree | eb9289a6abbda5031284a6c7c1a8bc9beb7b870c /activerecord | |
parent | 0329d59a65a5afbf57de83670e3e05e4a73815e4 (diff) | |
parent | 04919c79d71726aac1732b1d1a305051ceee541b (diff) | |
download | rails-ed38c5a4854e32fe9e57975812b45a8bb67a8719.tar.gz rails-ed38c5a4854e32fe9e57975812b45a8bb67a8719.tar.bz2 rails-ed38c5a4854e32fe9e57975812b45a8bb67a8719.zip |
Merge pull request #15463 from geopet/refactor_xml_compute_type
Refactor XML serializer to not depend on `serialized_attributes`
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/xml_serialization_test.rb | 5 |
2 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 1a766093d0..019fe2218e 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -180,12 +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 - NilClass + column.type 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?(%(<firstname>#{author.name}</firstname>)), xml + end end def test_array_to_xml_including_has_many_association |