From cb54c6b295b80a1d14eabca02dfe97fa77930034 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Mon, 9 May 2011 14:43:39 -0400 Subject: [PATCH] minor: fix for format change is result for 1.9.1 'validate' command. --- lib/mongo/db.rb | 15 ++++++++++----- test/db_test.rb | 6 +----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 6fe6496..57a36f0 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -595,11 +595,16 @@ module Mongo # @raise [MongoDBError] if the command fails or there's a problem with the validation # data, or if the collection is invalid. def validate_collection(name) - doc = command({:validate => name}, :check_response => false) - raise MongoDBError, "Error with validate command: #{doc.inspect}" unless ok?(doc) - result = doc['result'] - raise MongoDBError, "Error with validation data: #{doc.inspect}" unless result.kind_of?(String) - raise MongoDBError, "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i + cmd = BSON::OrderedHash.new + cmd[:validate] = name + cmd[:full] = true + doc = command(cmd, :check_response => false) + 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 end diff --git a/test/db_test.rb b/test/db_test.rb index 0154592..891dbbd 100644 --- a/test/db_test.rb +++ b/test/db_test.rb @@ -298,17 +298,13 @@ class DBTest < Test::Unit::TestCase assert_kind_of Array, info assert info.length >= 1 first = info.first - assert_kind_of String, first['info'] assert_kind_of Time, first['ts'] assert_kind_of Numeric, first['millis'] end should "validate collection" do doc = @db.validate_collection(@coll.name) - assert_not_nil doc - result = doc['result'] - assert_not_nil result - assert_match(/firstExtent/, result) + assert doc['valid'] end end