RUBY-288 ensure we cannot modify with add_option or remove_option after iteration starts.
This commit is contained in:
parent
1142c33910
commit
b32f895ed6
@ -350,10 +350,15 @@ module Mongo
|
||||
#
|
||||
# @param opt a valid query option
|
||||
#
|
||||
# @raise InvalidOperation if this method is run after the cursor has bee
|
||||
# iterated for the first time.
|
||||
#
|
||||
# @return [Integer] the current value of the options bitfield for this cursor.
|
||||
#
|
||||
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
||||
def add_option(opt)
|
||||
check_modifiable
|
||||
|
||||
@options |= opt
|
||||
@options
|
||||
end
|
||||
@ -362,10 +367,15 @@ module Mongo
|
||||
#
|
||||
# @param opt a valid query option
|
||||
#
|
||||
# @raise InvalidOperation if this method is run after the cursor has bee
|
||||
# iterated for the first time.
|
||||
#
|
||||
# @return [Integer] the current value of the options bitfield for this cursor.
|
||||
#
|
||||
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
||||
def remove_option(opt)
|
||||
check_modifiable
|
||||
|
||||
@options &= ~opt
|
||||
@options
|
||||
end
|
||||
|
@ -39,6 +39,15 @@ class CursorTest < Test::Unit::TestCase
|
||||
assert_equal OP_QUERY_EXHAUST, c.options & OP_QUERY_EXHAUST
|
||||
c.remove_option(OP_QUERY_EXHAUST)
|
||||
assert_equal 0, c.options & OP_QUERY_EXHAUST
|
||||
|
||||
c.next
|
||||
assert_raise Mongo::InvalidOperation do
|
||||
c.add_option(OP_QUERY_EXHAUST)
|
||||
end
|
||||
|
||||
assert_raise Mongo::InvalidOperation do
|
||||
c.add_option(OP_QUERY_EXHAUST)
|
||||
end
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
|
Loading…
Reference in New Issue
Block a user