From a8e3a80fde31b71522580b26ea67ffa3687e0f91 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 23 Feb 2010 13:06:48 -0500 Subject: [PATCH] test fixes for deprecations --- lib/mongo/collection.rb | 6 ++++-- test/db_api_test.rb | 9 +++------ test/objectid_test.rb | 35 ----------------------------------- 3 files changed, 7 insertions(+), 43 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 03375a0..654acec 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -453,8 +453,10 @@ module Mongo end # only add finalize if specified - if finalize - finalize = Code.new(finalize) unless finalize.is_a?(Code) + # check to see if users have sent the finalizer as the last argument. + finalize = deprecated if deprecated.is_a?(String) || deprecated.is_a?(Code) + finalize = Code.new(finalize) if finalize.is_a?(String) + if finalize.is_a?(Code) group_command['group']['finalize'] = finalize end diff --git a/test/db_api_test.rb b/test/db_api_test.rb index 44ac825..bbff146 100644 --- a/test/db_api_test.rb +++ b/test/db_api_test.rb @@ -539,22 +539,19 @@ class DBAPITest < Test::Unit::TestCase test = @@db.collection("test") assert_equal [], test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }") - assert_equal [], test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }", true) + assert_equal [], test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }") test.insert("a" => 2) test.insert("b" => 5) test.insert("a" => 1) assert_equal 3, test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }")[0]["count"] - assert_equal 3, test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }", true)[0]["count"] + assert_equal 3, test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }")[0]["count"] + assert_equal 1, test.group([], {"a" => {"$gt" => 1}}, {"count" => 0}, "function (obj, prev) { prev.count++; }")[0]["count"] assert_equal 1, test.group([], {"a" => {"$gt" => 1}}, {"count" => 0}, "function (obj, prev) { prev.count++; }")[0]["count"] - assert_equal 1, test.group([], {"a" => {"$gt" => 1}}, {"count" => 0}, "function (obj, prev) { prev.count++; }", true)[0]["count"] finalize = "function (obj) { obj.f = obj.count - 1; }" assert_equal 2, test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }", true, finalize)[0]["f"] - assert_raise OperationFailure do - test.group([], {}, {"count" => 0}, "function (obj, prev) { prev.count++; }", false, finalize)[0]["f"] - end test.insert("a" => 2, "b" => 3) expected = [{"a" => 2, "count" => 2}, diff --git a/test/objectid_test.rb b/test/objectid_test.rb index 3156937..76afa98 100644 --- a/test/objectid_test.rb +++ b/test/objectid_test.rb @@ -48,15 +48,6 @@ class ObjectIDTest < Test::Unit::TestCase assert_equal 24, $1.length end - def test_to_s_legacy - s = @o.to_s_legacy - assert_equal 24, s.length - s =~ /^([0-9a-f]+)$/ - assert_equal 24, $1.length - - assert_not_equal s, @o.to_s - end - def test_save_and_restore host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT @@ -85,20 +76,6 @@ class ObjectIDTest < Test::Unit::TestCase end end - def test_from_string_legacy - hex_str = @o.to_s_legacy - o2 = ObjectID.from_string_legacy(hex_str) - assert_equal hex_str, o2.to_s_legacy - assert_equal @o, o2 - assert_equal @o.to_s, o2.to_s - end - - def test_illegal_from_string_legacy - assert_raise InvalidObjectID do - ObjectID.from_string_legacy("") - end - end - def test_legal assert !ObjectID.legal?(nil) assert !ObjectID.legal?("fred") @@ -121,18 +98,6 @@ class ObjectIDTest < Test::Unit::TestCase assert_equal [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b], o.to_a end - def test_legacy_byte_order - hex_str = '000102030405060708090A0B' - o = ObjectID.from_string_legacy(hex_str) - assert_equal [0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x0b, 0x0a, 0x09, 0x08], o.to_a - end - - def test_legacy_string_convert - l = @o.to_s_legacy - s = @o.to_s - assert_equal s, ObjectID.legacy_string_convert(l) - end - def test_generation_time time = Time.now id = ObjectID.new