minor: make DB#validate_collection compatible with server v1.8 and v1.9.1

This commit is contained in:
Kyle Banker 2011-05-10 14:28:04 -04:00
parent 604d0f60ed
commit f7e1feaeba
2 changed files with 6 additions and 2 deletions

View File

@ -602,7 +602,7 @@ module Mongo
if !ok?(doc) if !ok?(doc)
raise MongoDBError, "Error with validate command: #{doc.inspect}" raise MongoDBError, "Error with validate command: #{doc.inspect}"
end end
if !doc['valid'] if (doc.has_key?('valid') && !doc['valid']) || (doc['result'] =~ /\b(exception|corrupt)\b/i)
raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}" raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}"
end end
doc doc

View File

@ -304,7 +304,11 @@ class DBTest < Test::Unit::TestCase
should "validate collection" do should "validate collection" do
doc = @db.validate_collection(@coll.name) doc = @db.validate_collection(@coll.name)
assert doc['valid'] if @@version >= "1.9.1"
assert doc['valid']
else
assert doc['result']
end
end end
end end