From 03800e092938c950a394e23e4dbb57b7a723778d Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Wed, 4 Jun 2008 15:44:17 +0000 Subject: Add tests for bulk_docs, to verify that COUCHDB-16 has been fixed. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@663239 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch.js | 2 +- share/www/script/couch_tests.js | 42 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'share') diff --git a/share/www/script/couch.js b/share/www/script/couch.js index 5fe43fb5..861fd070 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -87,7 +87,7 @@ function CouchDB(name) { var result = JSON.parse(req.responseText); if (req.status != 201) throw result; - for(var i in docs) { + for (var i = 0; i < docs.length; i++) { docs[i]._id = result.new_revs[i].id; docs[i]._rev = result.new_revs[i].rev; } diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 523d7d54..97e91f1e 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -190,6 +190,42 @@ var tests = { } }, + bulk_docs: function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + var docs = makeDocs(5); + + // Create the docs + var result = db.bulkSave(docs); + T(result.ok); + T(result.new_revs.length == 5); + for (var i = 0; i < 5; i++) { + T(result.new_revs[i].id == docs[i]._id); + T(result.new_revs[i].rev); + docs[i].string = docs[i].string + ".00"; + } + + // Update the docs + result = db.bulkSave(docs); + T(result.ok); + T(result.new_revs.length == 5); + for (i = 0; i < 5; i++) { + T(result.new_revs[i].id == i.toString()); + docs[i]._deleted = true; + } + + // Delete the docs + result = db.bulkSave(docs); + T(result.ok); + T(result.new_revs.length == 5); + for (i = 0; i < 5; i++) { + T(db.open(docs[i]._id) == null); + } + }, + // test saving a semi-large quanitity of documents and do some view queries. lots_of_docs: function(debug) { var db = new CouchDB("test_suite_db"); @@ -1034,8 +1070,12 @@ var tests = { function makeDocs(start, end, templateDoc) { var templateDocSrc = templateDoc ? templateDoc.toSource() : "{}" + if (end === undefined) { + end = start; + start = 0; + } var docs = [] - for(var i=start; i