minor: fix for format change is result for 1.9.1 'validate' command.

This commit is contained in:
Kyle Banker 2011-05-09 14:43:39 -04:00
parent 135bebd9ab
commit cb54c6b295
2 changed files with 11 additions and 10 deletions

View File

@ -595,11 +595,16 @@ module Mongo
# @raise [MongoDBError] if the command fails or there's a problem with the validation # @raise [MongoDBError] if the command fails or there's a problem with the validation
# data, or if the collection is invalid. # data, or if the collection is invalid.
def validate_collection(name) def validate_collection(name)
doc = command({:validate => name}, :check_response => false) cmd = BSON::OrderedHash.new
raise MongoDBError, "Error with validate command: #{doc.inspect}" unless ok?(doc) cmd[:validate] = name
result = doc['result'] cmd[:full] = true
raise MongoDBError, "Error with validation data: #{doc.inspect}" unless result.kind_of?(String) doc = command(cmd, :check_response => false)
raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i if !ok?(doc)
raise MongoDBError, "Error with validate command: #{doc.inspect}"
end
if !doc['valid']
raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}"
end
doc doc
end end

View File

@ -298,17 +298,13 @@ class DBTest < Test::Unit::TestCase
assert_kind_of Array, info assert_kind_of Array, info
assert info.length >= 1 assert info.length >= 1
first = info.first first = info.first
assert_kind_of String, first['info']
assert_kind_of Time, first['ts'] assert_kind_of Time, first['ts']
assert_kind_of Numeric, first['millis'] assert_kind_of Numeric, first['millis']
end end
should "validate collection" do should "validate collection" do
doc = @db.validate_collection(@coll.name) doc = @db.validate_collection(@coll.name)
assert_not_nil doc assert doc['valid']
result = doc['result']
assert_not_nil result
assert_match(/firstExtent/, result)
end end
end end