summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2008-06-04 15:44:17 +0000
committerChristopher Lenz <cmlenz@apache.org>2008-06-04 15:44:17 +0000
commit03800e092938c950a394e23e4dbb57b7a723778d (patch)
treedd37ba34b6703673b875fc11b8ca4c13014b226f /share
parentf6b5608dd05db1f10faaa6b426659dfcb84e22e4 (diff)
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
Diffstat (limited to 'share')
-rw-r--r--share/www/script/couch.js2
-rw-r--r--share/www/script/couch_tests.js42
2 files changed, 42 insertions, 2 deletions
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<end; i++) {
+ for (var i = start; i < end; i++) {
var newDoc = eval("(" + templateDocSrc + ")");
newDoc._id = (i).toString();
newDoc.integer = i