test fixes for deprecations
This commit is contained in:
parent
64a8b09c2e
commit
a8e3a80fde
|
@ -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
|
||||
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue