RUBY-304 add Collection#capped?

This commit is contained in:
Kyle Banker 2011-08-08 17:52:44 -04:00
parent a323911507
commit a9b975eaaa
2 changed files with 20 additions and 0 deletions

View File

@ -88,6 +88,16 @@ module Mongo
@hint = nil
end
# Indicate whether this is a capped collection.
#
# @raise [Mongo::OperationFailure]
# if the collection doesn't exist.
#
# @return [Boolean]
def capped?
@db.command({:collstats => @name})['capped'] == 1
end
# Return a sub-collection of this collection by name. If 'users' is a collection, then
# 'users.comments' is a sub-collection of users.
#

View File

@ -10,6 +10,16 @@ class TestCollection < Test::Unit::TestCase
@@test.remove
end
def test_capped_method
@@db.create_collection('normal')
assert !@@db['normal'].capped?
@@db.drop_collection('normal')
@@db.create_collection('c', :capped => true)
assert @@db['c'].capped?
@@db.drop_collection('c')
end
def test_optional_pk_factory
@coll_default_pk = @@db.collection('stuff')
assert_equal BSON::ObjectId, @coll_default_pk.pk_factory