From d1892b4b0e10646452b6adf0dc1f98fbd5392466 Mon Sep 17 00:00:00 2001 From: Pierre Lancien 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