diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index bcff827..bbbd39b 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -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 diff --git a/test/cursor_test.rb b/test/cursor_test.rb index 9bf14fb..c78d4ce 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -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