RUBY-267 Cursor#alive?

This commit is contained in:
Kyle Banker 2011-05-10 15:45:32 -04:00
parent 9a80fbaa66
commit 05dfef2f11
2 changed files with 22 additions and 0 deletions

View File

@ -307,6 +307,13 @@ module Mongo
# @return [Boolean]
def closed?; @closed; end
# Is this cursor alive on the server?
#
# @return [Boolean]
def alive?
@cursor_id && @cursor_id != 0
end
# Returns an integer indicating which query options have been selected.
#
# @return [Integer]

View File

@ -32,6 +32,21 @@ class CursorTest < Test::Unit::TestCase
assert_kind_of Numeric, explaination['nscanned']
end
def test_alive
batch = []
5000.times do |n|
batch << {:a => n}
end
@@coll.insert(batch)
cursor = @@coll.find
assert !cursor.alive?
cursor.next
assert cursor.alive?
cursor.close
assert !cursor.alive?
@@coll.remove
end
def test_count
@@coll.remove