Permalink
Browse files

Duplicate the hash provided to AR::Base#to_xml to prevent unexpected …

…side effects [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5170 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8d809e7 commit 83d972e365963f44e4b1dd100a7c9c55a77e6d41 @NZKoz NZKoz committed Sep 24, 2006
@@ -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]
@@ -112,7 +112,7 @@ class XmlSerializer #:nodoc:
attr_reader :options
def initialize(record, options = {})
- @record, @options = record, options
+ @record, @options = record, options.dup
end
def builder
@@ -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 @@ def test_should_serialize_datetime
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

0 comments on commit 83d972e

Please sign in to comment.