Permalink
Browse files

fix for _all_docs_by_seq with include_docs

git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@713914 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 41e60ec commit d32d8acff4bac6f51b87ddef7091c04ff7245d40 @jchris jchris committed Nov 14, 2008
Showing with 94 additions and 23 deletions.
  1. +1 −0 THANKS
  2. +14 −0 share/www/script/couch.js
  3. +73 −18 share/www/script/couch_tests.js
  4. +6 −5 src/couchdb/couch_httpd_view.erl
View
1 THANKS
@@ -8,6 +8,7 @@ Some of these people are:
* Mark Baran <mebaran@gmail.com>
* William Beh <willbeh@gmail.com>
+ * Antony Blakey <antony.blakey@gmail.com>
* Yoan Blanc <yoan.blanc@gmail.com>
* Benoit Chesneau <bchesneau@gmail.com>
* Paul Joseph Davis <paul.joseph.davis@gmail.com>
View
@@ -162,6 +162,20 @@ function CouchDB(name, options) {
return JSON.parse(req.responseText);
}
+ this.allDocsBySeq = function(options,keys) {
+ var req = null;
+ if(!keys) {
+ req = request("GET", this.uri + "_all_docs_by_seq" + encodeOptions(options));
+ } else {
+ req = request("POST", this.uri + "_all_docs_by_seq" + encodeOptions(options), {
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({keys:keys})
+ });
+ }
+ maybeThrowError(req);
+ return JSON.parse(req.responseText);
+ }
+
this.compact = function() {
var req = request("POST", this.uri + "_compact");
maybeThrowError(req);
@@ -67,24 +67,6 @@ var tests = {
// Check the database doc count
T(db.info().doc_count == 4);
- // Check the all docs
- var results = db.allDocs();
- var rows = results.rows;
-
- T(results.total_rows == results.rows.length);
-
- for(var i=0; i < rows.length; i++) {
- T(rows[i].id >= "0" && rows[i].id <= "4");
- }
-
- // Check _all_docs with descending=true
- var desc = db.allDocs({descending:true});
- T(desc.total_rows == desc.rows.length);
-
- // Check _all_docs offset
- var all = db.allDocs({startkey:"2"});
- T(all.offset == 2);
-
// Test a simple map functions
// create a map function that selects all documents whose "a" member
@@ -150,7 +132,80 @@ var tests = {
// make sure restart works
T(restartServer().ok);
},
+ all_docs: function(debug) {
+ var db = new CouchDB("test_suite_db");
+ db.deleteDb();
+ db.createDb();
+ if (debug) debugger;
+
+ // Create some more documents.
+ // Notice the use of the ok member on the return result.
+ T(db.save({_id:"0",a:1,b:1}).ok);
+ T(db.save({_id:"3",a:4,b:16}).ok);
+ T(db.save({_id:"1",a:2,b:4}).ok);
+ T(db.save({_id:"2",a:3,b:9}).ok);
+ // Check the all docs
+ var results = db.allDocs();
+ var rows = results.rows;
+
+ T(results.total_rows == results.rows.length);
+
+ for(var i=0; i < rows.length; i++) {
+ T(rows[i].id >= "0" && rows[i].id <= "4");
+ }
+
+ // Check _all_docs with descending=true
+ var desc = db.allDocs({descending:true});
+ T(desc.total_rows == desc.rows.length);
+
+ // Check _all_docs offset
+ var all = db.allDocs({startkey:"2"});
+ T(all.offset == 2);
+
+ // check that the docs show up in the seq view in the order they were created
+ var all_seq = db.allDocsBySeq();
+ var ids = ["0","3","1","2"];
+ for (var i=0; i < all_seq.rows.length; i++) {
+ var row = all_seq.rows[i];
+ T(row.id == ids[i]);
+ };
+
+ // check that deletions also show up right
+ var doc1 = db.open("1");
+ var deleted = db.deleteDoc(doc1);
+ T(deleted.ok);
+ all_seq = db.allDocsBySeq();
+
+ // the deletion should make doc id 1 have the last seq num
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "1");
+ T(all_seq.rows[3].value.deleted);
+
+ // is this a bug?
+ // T(all_seq.rows.length == all_seq.total_rows);
+
+ // do an update
+ var doc2 = db.open("3");
+ doc2.updated = "totally";
+ db.save(doc2);
+ all_seq = db.allDocsBySeq();
+
+ // the update should make doc id 3 have the last seq num
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "3");
+
+ // ok now lets see what happens with include docs
+ all_seq = db.allDocsBySeq({include_docs: true});
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "3");
+ T(all_seq.rows[3].doc.updated == "totally");
+
+ // and on the deleted one, no doc
+ T(all_seq.rows[2].value.deleted);
+ T(!all_seq.rows[2].doc);
+ },
+
// Do some edit conflict detection tests
conflicts: function(debug) {
var db = new CouchDB("test_suite_db");
@@ -426,12 +426,13 @@ view_row_obj(Db, {{Key, DocId}, Value}, IncludeDocs) ->
[]
end,
?LOG_DEBUG("Include Doc: ~p ~p", [DocId, Rev]),
- case (catch couch_httpd_db:couch_doc_open(Db, DocId,
- Rev, [])) of
- {{not_found, missing}, _} ->
+ case (catch couch_httpd_db:couch_doc_open(Db, DocId, Rev, [])) of
+ {{not_found, missing}, _} ->
{[{id, DocId}, {key, Key}, {value, Value}, {error, missing}]};
- Doc ->
- JsonDoc = couch_doc:to_json_obj(Doc, []),
+ {not_found, deleted} ->
+ {[{id, DocId}, {key, Key}, {value, Value}]};
+ Doc ->
+ JsonDoc = couch_doc:to_json_obj(Doc, []),
{[{id, DocId}, {key, Key}, {value, Value}, {doc, JsonDoc}]}
end;
_ ->

0 comments on commit d32d8ac

Please sign in to comment.