diff --git a/README.rdoc b/README.rdoc index 7d516d7..649a545 100644 --- a/README.rdoc +++ b/README.rdoc @@ -63,8 +63,6 @@ See the git log comments. * More tests. -* Implement the rest of the Admin interface. - * Study src/main/ed/db/{dbcollection,dbcursor,db}.js and ByteEncoder.java in the Babble code. That's what I should be writing to. diff --git a/lib/mongo/admin.rb b/lib/mongo/admin.rb index 8f2e641..1ce950a 100644 --- a/lib/mongo/admin.rb +++ b/lib/mongo/admin.rb @@ -69,8 +69,15 @@ module XGen @db.query(DB::SYSTEM_PROFILE_COLLECTION, Query.new({})).to_a end - # Validate a named collection. + # Validate a named collection by raising an exception if there is a + # problem or returning +true+ if all is well. def validate_collection(name) + doc = @db.db_command(:validate => name) + raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc) + result = doc['result'] + raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String) + raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i + true end end diff --git a/tests/test_admin.rb b/tests/test_admin.rb index a16873b..f574744 100644 --- a/tests/test_admin.rb +++ b/tests/test_admin.rb @@ -53,4 +53,8 @@ class AdminTest < Test::Unit::TestCase @admin.profiling_level = :off end + def test_validate_collection + assert @admin.validate_collection(@coll.name) + end + end