Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test the format and result of ?revs=true parameter (fixes #42)

  • Loading branch information...
commit bfc4d84f5b42c3fbfca2c531dcb471dadbfb71ae 1 parent b5d0bf7
@daleharvey daleharvey authored
View
10 src/adapters/pouch.idb.js
@@ -362,6 +362,16 @@ var IdbPouch = function(opts, callback) {
delete doc._junk;
doc._id = metadata.id;
doc._rev = metadata.rev;
+ if (opts.revs) {
+ var path = arrayFirst(rootToLeaf(metadata.rev_tree), function(arr) {
+ return arr.ids.indexOf(metadata.rev.split('-')[1]) !== -1;
+ });
+ path.ids.reverse();
+ doc._revisions = {
+ start: (path.pos + path.ids.length) - 1,
+ ids: path.ids
+ };
+ }
if (opts.revs_info) {
doc._revs_info = metadata.rev_tree.reduce(function(prev, current) {
return prev.concat(collectRevs(current));
View
20 src/pouch.merge.js
@@ -23,26 +23,6 @@
return root;
}
- // Turn a tree into a list of rootToLeaf paths
- function expandTree(all, current, pos, arr) {
- current = current.slice(0);
- current.push(arr[0]);
- if (!arr[1].length) {
- all.push({pos: pos, ids: current});
- }
- arr[1].forEach(function(child) {
- expandTree(all, current, pos, child);
- });
- }
-
- function rootToLeaf(tree) {
- var all = [];
- tree.forEach(function(path) {
- expandTree(all, [], path.pos, path.ids);
- });
- return all;
- }
-
// To ensure we dont grow the revision tree infinitely, we stem old revisions
function stem(tree, depth) {
// First we break out the tree into a complete list of root to leaf paths,
View
29 src/pouch.utils.js
@@ -151,6 +151,35 @@ var writeCheckpoint = function(src, target, checkpoint, callback) {
});
};
+// Turn a tree into a list of rootToLeaf paths
+function expandTree2(all, current, pos, arr) {
+ current = current.slice(0);
+ current.push(arr[0]);
+ if (!arr[1].length) {
+ all.push({pos: pos, ids: current});
+ }
+ arr[1].forEach(function(child) {
+ expandTree2(all, current, pos, child);
+ });
+}
+
+function rootToLeaf(tree) {
+ var all = [];
+ tree.forEach(function(path) {
+ expandTree2(all, [], path.pos, path.ids);
+ });
+ return all;
+}
+
+var arrayFirst = function(arr, callback) {
+ for (var i = 0; i < arr.length; i++) {
+ if (callback(arr[i], i) === true) {
+ return arr[i];
+ }
+ }
+ return false;
+};
+
// Basic wrapper for localStorage
var localJSON = (function(){
if (!localStorage) {
View
21 tests/test.basics.js
@@ -151,3 +151,24 @@ asyncTest("Basic checks", function() {
});
});
});
+
+asyncTest("Testing Rev format", function() {
+ var revs = [];
+ initTestDB(this.name, function(err, db) {
+ db.post({test: "somestuff"}, function (err, info) {
+ revs.unshift(info.rev.split('-')[1]);
+ db.put({_id: info.id, _rev: info.rev, another: 'test'}, function(err, info2) {
+ revs.unshift(info2.rev.split('-')[1]);
+ db.put({_id: info.id, _rev: info2.rev, last: 'test'}, function(err, info3) {
+ revs.unshift(info3.rev.split('-')[1]);
+ db.get(info.id, {revs:true}, function(err, doc) {
+ ok(doc._revisions.start === 3, 'correct starting position');
+ same(revs, doc._revisions.ids, 'correct revs returned');
+ start();
+ });
+ });
+ });
+ });
+ });
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.