From 2eaca6bc8e42ca251e9d38882349e116dd304cfb Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 27 Aug 2010 15:50:42 -0400 Subject: [PATCH] RUBY-172 fix for OrderedHash#clone --- lib/bson/ordered_hash.rb | 5 ++++- test/mongo_bson/ordered_hash_test.rb | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/bson/ordered_hash.rb b/lib/bson/ordered_hash.rb index ed22e65..2bce466 100644 --- a/lib/bson/ordered_hash.rb +++ b/lib/bson/ordered_hash.rb @@ -88,7 +88,7 @@ module BSON @ordered_keys ||= [] @ordered_keys.map { |k| [k, self[k]] } end - + def values collect { |k, v| v } end @@ -158,6 +158,9 @@ module BSON end end + def clone + Marshal::load(Marshal.dump(self)) + end end end end diff --git a/test/mongo_bson/ordered_hash_test.rb b/test/mongo_bson/ordered_hash_test.rb index e059b35..0171c3d 100644 --- a/test/mongo_bson/ordered_hash_test.rb +++ b/test/mongo_bson/ordered_hash_test.rb @@ -187,4 +187,11 @@ class OrderedHashTest < Test::Unit::TestCase assert !new.keys.include?('z') end + def test_clone + copy = @oh.clone + assert copy.keys == @oh.keys + + copy[:foo] = 1 + assert copy.keys != @oh.keys + end end