test/unit/cursor_test.rb in mongo-1.3.1 vs test/unit/cursor_test.rb in mongo-1.4.0
- old
+ new
@@ -3,13 +3,13 @@
class CursorTest < Test::Unit::TestCase
context "Cursor options" do
setup do
@logger = mock()
@logger.stubs(:debug)
- @connection = stub(:class => Connection, :logger => @logger)
- @db = stub(:name => "testing", :slave_ok? => false, :connection => @connection)
- @collection = stub(:db => @db, :name => "items")
+ @connection = stub(:class => Connection, :logger => @logger, :slave_ok? => false, :read_preference => :primary)
+ @db = stub(:name => "testing", :slave_ok? => false, :connection => @connection, :read_preference => :primary)
+ @collection = stub(:db => @db, :name => "items", :read_preference => :primary)
@cursor = Cursor.new(@collection)
end
should "set timeout" do
assert @cursor.timeout
@@ -74,18 +74,36 @@
end
should "cache full collection name" do
assert_equal "testing.items", @cursor.full_collection_name
end
+
+ should "raise error when batch_size is 1" do
+ e = assert_raise ArgumentError do
+ @cursor.batch_size(1)
+ end
+ assert_equal "Invalid value for batch_size 1; must be 0 or > 1.", e.message
+ end
+
+ should "use the limit for batch size when it's smaller than the specified batch_size" do
+ @cursor.limit(99)
+ @cursor.batch_size(100)
+ assert_equal 99, @cursor.batch_size
+ end
+
+ should "use the specified batch_size" do
+ @cursor.batch_size(100)
+ assert_equal 100, @cursor.batch_size
+ end
end
context "Query fields" do
setup do
@logger = mock()
@logger.stubs(:debug)
- @connection = stub(:class => Connection, :logger => @logger)
+ @connection = stub(:class => Connection, :logger => @logger, :slave_ok? => false)
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
- @collection = stub(:db => @db, :name => "items")
+ @collection = stub(:db => @db, :name => "items", :read_preference => :primary)
end
should "when an array should return a hash with each key" do
@cursor = Cursor.new(@collection, :fields => [:name, :age])
result = @cursor.fields