Created
May 14, 2011 02:34
-
-
Save AquaGeek/971754 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6195
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -urB a/lib/active_resource/base.rb b/lib/active_resource/base.rb | |
--- a/lib/active_resource/base.rb 2011-02-24 11:10:41.000000000 -0600 | |
+++ b/lib/active_resource/base.rb 2011-02-24 11:11:11.000000000 -0600 | |
@@ -749,7 +749,7 @@ | |
def clone | |
# Clone all attributes except the pk and any nested ARes | |
cloned = attributes.reject {|k,v| k == self.class.primary_key || v.is_a?(ActiveResource::Base)}.inject({}) do |attrs, (k, v)| | |
- attrs[k] = v.clone | |
+ attrs[k] = v.duplicable? ? v.clone : v | |
attrs | |
end | |
# Form the new resource - bypass initialize of resource with 'new' as that will call 'load' which | |
diff -urB a/test/base_test.rb b/test/base_test.rb | |
--- a/test/base_test.rb 2011-02-24 11:10:41.000000000 -0600 | |
+++ b/test/base_test.rb 2011-02-24 11:12:21.000000000 -0600 | |
@@ -8,7 +8,7 @@ | |
class BaseTest < Test::Unit::TestCase | |
def setup | |
- @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') | |
+ @matz = { :id => 1, :name => 'Matz', :age => 31, :male => true }.to_xml(:root => 'person') | |
@david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') | |
@greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person') | |
@addy = { :id => 1, :street => '12345 Street' }.to_xml(:root => 'address') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d1892b4b0e10646452b6adf0dc1f98fbd5392466 Mon Sep 17 00:00:00 2001 | |
From: Pierre Lancien <pierre@toxicode.fr> | |
Date: Sun, 19 Dec 2010 18:37:47 +0100 | |
Subject: [PATCH] Fixed clone in ActiveResource for boolean and Fixum attributes [#6195 state:resolved] | |
--- | |
activeresource/lib/active_resource/base.rb | 2 +- | |
activeresource/test/abstract_unit.rb | 2 +- | |
2 files changed, 2 insertions(+), 2 deletions(-) | |
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb | |
index d959fd1..d43c1dc 100644 | |
--- a/activeresource/lib/active_resource/base.rb | |
+++ b/activeresource/lib/active_resource/base.rb | |
@@ -1009,7 +1009,7 @@ module ActiveResource | |
# not_ryan.hash # => {:not => "an ARes instance"} | |
def clone | |
# Clone all attributes except the pk and any nested ARes | |
- cloned = Hash[attributes.reject {|k,v| k == self.class.primary_key || v.is_a?(ActiveResource::Base)}.map { |k, v| [k, v.clone] }] | |
+ cloned = Hash[attributes.reject {|k,v| k == self.class.primary_key || v.is_a?(ActiveResource::Base)}.map { |k, v| [k, (v.duplicable? ? v.clone : v)] }] | |
# Form the new resource - bypass initialize of resource with 'new' as that will call 'load' which | |
# attempts to convert hashes into member objects and arrays into collections of objects. We want | |
# the raw objects to be cloned so we bypass load by directly setting the attributes hash. | |
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb | |
index 195f93f..5ad050c 100644 | |
--- a/activeresource/test/abstract_unit.rb | |
+++ b/activeresource/test/abstract_unit.rb | |
@@ -21,7 +21,7 @@ end | |
def setup_response | |
@default_request_headers = { 'Content-Type' => 'application/xml' } | |
- @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') | |
+ @matz = { :id => 1, :name => 'Matz', :age => 31, :male => true }.to_xml(:root => 'person') | |
@david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') | |
@greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person') | |
@addy = { :id => 1, :street => '12345 Street', :country => 'Australia' }.to_xml(:root => 'address') | |
-- | |
1.7.0.6 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment