diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/CHANGELOG.md | 20 | ||||
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/serializers/xml.rb | 7 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/serializers/xml_serialization_test.rb | 12 |
5 files changed, 37 insertions, 6 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 6f09c1cb43..fe83324848 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,4 +1,17 @@ -## Rails 3.2.10 ## +## Rails 3.2.12 (unreleased) ## + +* Specify type of singular association during serialization *Steve Klabnik* + + +## Rails 3.2.11 (Jan 8, 2013) ## + +* No changes. + + +## Rails 3.2.10 (Jan 2, 2013) ## + +* No changes. + ## Rails 3.2.9 (Nov 12, 2012) ## @@ -13,24 +26,29 @@ *Carlos Antonio da Silva* + ## Rails 3.2.8 (Aug 9, 2012) ## * No changes. + ## Rails 3.2.7 (Jul 26, 2012) ## * `validates_inclusion_of` and `validates_exclusion_of` now accept `:within` option as alias of `:in` as documented. * Fix the the backport of the object dup with the ruby 1.9.3p194. + ## Rails 3.2.6 (Jun 12, 2012) ## * No changes. + ## Rails 3.2.4 (May 31, 2012) ## * No changes. + ## Rails 3.2.3 (March 30, 2012) ## * No changes. diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 00bd68512b..7eaee050cd 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -84,7 +84,7 @@ module ActiveModel end # Backport dup from 1.9 so that #initialize_dup gets called - unless Object.respond_to?(:initialize_dup) + unless Object.respond_to?(:initialize_dup, true) def dup # :nodoc: copy = super copy.initialize_dup(self) diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb index 2dc7d00f52..a63856045f 100644 --- a/activemodel/lib/active_model/serializers/xml.rb +++ b/activemodel/lib/active_model/serializers/xml.rb @@ -144,7 +144,12 @@ module ActiveModel end else merged_options[:root] = association.to_s - records.to_xml(merged_options) + + unless records.class.to_s.underscore == association.to_s + merged_options[:type] = records.class.name + end + + records.to_xml merged_options end end diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 45d8677fa0..c7e508958b 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -173,7 +173,7 @@ module ActiveModel end # Backport dup from 1.9 so that #initialize_dup gets called - unless Object.respond_to?(:initialize_dup) + unless Object.respond_to?(:initialize_dup, true) def dup # :nodoc: copy = super copy.initialize_dup(self) diff --git a/activemodel/test/cases/serializers/xml_serialization_test.rb b/activemodel/test/cases/serializers/xml_serialization_test.rb index 83db8d21f4..62c2b2035f 100644 --- a/activemodel/test/cases/serializers/xml_serialization_test.rb +++ b/activemodel/test/cases/serializers/xml_serialization_test.rb @@ -6,12 +6,12 @@ require 'ostruct' class Contact include ActiveModel::Serializers::Xml - attr_accessor :address, :friends + attr_accessor :address, :friends, :contact remove_method :attributes if method_defined?(:attributes) def attributes - instance_values.except("address", "friends") + instance_values.except("address", "friends", "contact") end end @@ -55,6 +55,9 @@ class XmlSerializationTest < ActiveModel::TestCase @contact.address.state = "CA" @contact.address.zip = 11111 @contact.friends = [Contact.new, Contact.new] + @related_contact = SerializableContact.new + @related_contact.name = "related" + @contact.contact = @related_contact end test "should serialize default root" do @@ -203,4 +206,9 @@ class XmlSerializationTest < ActiveModel::TestCase assert_match %r{<friends>}, xml assert_match %r{<friend>}, xml end + + test "association with sti" do + xml = @contact.to_xml(:include => :contact) + assert xml.include?(%(<contact type="SerializableContact">)) + end end |