aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/xml_serialization.rb2
-rw-r--r--activerecord/test/xml_serialization_test.rb15
3 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index c9d08632ae..5f6c6e8931 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Duplicate the hash provided to AR::Base#to_xml to prevent unexpected side effects [Koz]
+
* Add a :namespace option to AR::Base#to_xml [Koz]
* Deprecation tests. Remove warnings for dynamic finders and for the foo_count method if it's also an attribute. [Jeremy Kemper]
diff --git a/activerecord/lib/active_record/xml_serialization.rb b/activerecord/lib/active_record/xml_serialization.rb
index 54d024fc89..78a3a2193c 100644
--- a/activerecord/lib/active_record/xml_serialization.rb
+++ b/activerecord/lib/active_record/xml_serialization.rb
@@ -112,7 +112,7 @@ module ActiveRecord #:nodoc:
attr_reader :options
def initialize(record, options = {})
- @record, @options = record, options
+ @record, @options = record, options.dup
end
def builder
diff --git a/activerecord/test/xml_serialization_test.rb b/activerecord/test/xml_serialization_test.rb
index 2fd9006821..73ff354c48 100644
--- a/activerecord/test/xml_serialization_test.rb
+++ b/activerecord/test/xml_serialization_test.rb
@@ -1,4 +1,6 @@
require 'abstract_unit'
+require 'fixtures/post'
+require 'fixtures/author'
class Contact < ActiveRecord::Base
# mock out self.columns so no pesky db is needed for these tests
@@ -107,4 +109,17 @@ class NilXmlSerializationTest < Test::Unit::TestCase
def test_should_serialize_boolean
assert_match %r{<awesome type=\"boolean\"></awesome>}, @xml
end
+end
+
+class DatabaseConnectedXmlSerializationTest < Test::Unit::TestCase
+ fixtures :authors, :posts
+ # to_xml used to mess with the hash the user provided which
+ # caused the builder to be reused
+ def test_passing_hash_shouldnt_reuse_builder
+ options = {:include=>:posts}
+ david = authors(:david)
+ first_xml_size = david.to_xml(options).size
+ second_xml_size = david.to_xml(options).size
+ assert_equal first_xml_size, second_xml_size
+ end
end \ No newline at end of file