Commit 3d03aafb authored by Bryan Kaperick's avatar Bryan Kaperick

Changed allDocs behavior for returned id when include_revisions is true

parent a1fa77a9
...@@ -438,15 +438,12 @@ ...@@ -438,15 +438,12 @@
if (options.query === undefined) {options.query = ""; } if (options.query === undefined) {options.query = ""; }
if (options.sort_on === undefined) {options.sort_on = []; } if (options.sort_on === undefined) {options.sort_on = []; }
if (options.select_list === undefined) {options.select_list = []; } if (options.select_list === undefined) {options.select_list = []; }
if (options.include_revisions === undefined) {
options.include_revisions = false;
}
options.query = jIO.QueryFactory.create(options.query); options.query = jIO.QueryFactory.create(options.query);
var meta_options = { var meta_options = {
query: "", query: "",
sort_on: [["timestamp", "descending"]], sort_on: [["timestamp", "descending"]],
select_list: ["doc", "op", "doc_id"] select_list: ["doc", "op", "doc_id", "timestamp"]
}, },
include_revs = this._include_revisions; include_revs = this._include_revisions;
...@@ -554,8 +551,13 @@ ...@@ -554,8 +551,13 @@
// Put into correct format to be passed back to query storage // Put into correct format to be passed back to query storage
.map(function (docum) { .map(function (docum) {
docum.doc = docum.value.doc; docum.doc = docum.value.doc;
if (include_revs) {
docum.id = docum.value.timestamp;
} else {
docum.id = docum.value.doc_id; docum.id = docum.value.doc_id;
}
delete docum.value.doc_id; delete docum.value.doc_id;
delete docum.value.timestamp;
delete docum.value.op; delete docum.value.op;
if (options.include_docs) { if (options.include_docs) {
......
...@@ -79,12 +79,11 @@ ...@@ -79,12 +79,11 @@
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history, not_history = this.not_history,
//timestamps, timestamps;
id;
return jio.post({title: "foo0"}) return jio.post({title: "foo0"})
.push(function (result) { .push(function (result) {
id = result; //id = result;
return jio.put(result, {title: "foo1"}); return jio.put(result, {title: "foo1"});
}) })
.push(function (result) { .push(function (result) {
...@@ -97,7 +96,12 @@ ...@@ -97,7 +96,12 @@
}) })
.push(function () { .push(function () {
return not_history.allDocs({ return not_history.allDocs({
select_list: ["timestamp"] sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
}); });
}) })
.push(function () { .push(function () {
...@@ -110,16 +114,14 @@ ...@@ -110,16 +114,14 @@
title: "foo1" title: "foo1"
}, },
doc: {}, doc: {},
//timestamp: timestamps[1], id: timestamps[1]
id: id
}, },
{ {
value: { value: {
title: "foo0" title: "foo0"
}, },
doc: {}, doc: {},
//timestamp: timestamps[0], id: timestamps[0]
id: id
} }
], ],
"Two revisions logged with correct metadata"); "Two revisions logged with correct metadata");
...@@ -765,7 +767,9 @@ ...@@ -765,7 +767,9 @@
stop(); stop();
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history; history = this.history,
timestamps,
not_history = this.not_history;
jio.remove("doc") jio.remove("doc")
.push(function () { .push(function () {
...@@ -779,21 +783,30 @@ ...@@ -779,21 +783,30 @@
title: "foo" title: "foo"
}, "A put was the most recent edit on 'doc'"); }, "A put was the most recent edit on 'doc'");
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
.push(function (results) { .push(function (results) {
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
id: "doc", //id: "doc",
value: {title: "foo"}, value: {title: "foo"},
//timestamp: timestamps[0], id: timestamps[1],
doc: {} doc: {}
}, },
{ {
id: "doc",
value: {}, value: {},
//timestamp: timestamps[1], id: timestamps[0],
doc: {} doc: {}
}], "DOcument that was removed before being put is not retrieved"); }], "DOcument that was removed before being put is not retrieved");
}) })
...@@ -1494,30 +1507,30 @@ ...@@ -1494,30 +1507,30 @@
"Querying with include_revisions retrieves all versions"); "Querying with include_revisions retrieves all versions");
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
id: "doc", //id: results.data.rows[0].id,
value: { value: {
title: "version2", title: "version2",
subtitle: "subvers2" subtitle: "subvers2"
}, },
//timestamp: timestamps[2], id: timestamps[2],
doc: {} doc: {}
}, },
{ {
id: "doc", //id: results.data.rows[1].id,
value: { value: {
title: "version1", title: "version1",
subtitle: "subvers1" subtitle: "subvers1"
}, },
//timestamp: timestamps[1], id: timestamps[1],
doc: {} doc: {}
}, },
{ {
id: "doc", //id: results.data.rows[2].id,
value: { value: {
title: "version0", title: "version0",
subtitle: "subvers0" subtitle: "subvers0"
}, },
//timestamp: timestamps[0], id: timestamps[0],
doc: {} doc: {}
} }
], "Full version history is included."); ], "Full version history is included.");
...@@ -1951,8 +1964,7 @@ ...@@ -1951,8 +1964,7 @@
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
doc: {}, doc: {},
id: "second_doc", id: timestamps[9],
//timestamp: timestamps[9],
value: { value: {
date: 4, date: 4,
title: "second_doc", title: "second_doc",
...@@ -1961,8 +1973,7 @@ ...@@ -1961,8 +1973,7 @@
}, },
{ {
doc: {}, doc: {},
id: "second_doc", id: timestamps[8],
//timestamp: timestamps[8],
value: { value: {
date: 4, date: 4,
title: "second_doc", title: "second_doc",
...@@ -1971,8 +1982,7 @@ ...@@ -1971,8 +1982,7 @@
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[6],
//timestamp: timestamps[6],
value: { value: {
date: 4, date: 4,
title: "doc", title: "doc",
...@@ -1981,8 +1991,7 @@ ...@@ -1981,8 +1991,7 @@
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[5],
//timestamp: timestamps[5],
value: { value: {
date: 4, date: 4,
title: "doc", title: "doc",
...@@ -1992,8 +2001,7 @@ ...@@ -1992,8 +2001,7 @@
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[2],
//timestamp: timestamps[2],
value: { value: {
date: 1, date: 1,
title: "doc", title: "doc",
...@@ -2002,8 +2010,7 @@ ...@@ -2002,8 +2010,7 @@
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[1],
//timestamp: timestamps[1],
value: { value: {
date: 1, date: 1,
title: "doc", title: "doc",
...@@ -2028,7 +2035,8 @@ ...@@ -2028,7 +2035,8 @@
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history, not_history = this.not_history,
blob = new Blob(['a']); blob = new Blob(['a']),
timestamps;
jio.put("document", {title: "foo"}) jio.put("document", {title: "foo"})
.push(function () { .push(function () {
...@@ -2037,27 +2045,34 @@ ...@@ -2037,27 +2045,34 @@
.push(function () { .push(function () {
return jio.putAttachment("document", "attachment", blob); return jio.putAttachment("document", "attachment", blob);
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
.push(function (results) { .push(function (results) {
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
id: "document", id: timestamps[2],
doc: {}, doc: {},
//timestamp: timestamps[2],
value: {} value: {}
}, },
{ {
id: "document", id: timestamps[1],
doc: {}, doc: {},
//timestamp: timestamps[1],
value: {} value: {}
}, },
{ {
id: "document", id: timestamps[0],
doc: {}, doc: {},
//timestamp: timestamps[0],
value: {title: "foo"} value: {title: "foo"}
}], }],
"Attachment on removed document is handled correctly" "Attachment on removed document is handled correctly"
...@@ -2079,7 +2094,9 @@ ...@@ -2079,7 +2094,9 @@
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
blob = new Blob(['a']); blob = new Blob(['a']),
timestamps,
not_history = this.not_history;
jio.put("document", {title: "foo"}) jio.put("document", {title: "foo"})
.push(function () { .push(function () {
...@@ -2088,28 +2105,34 @@ ...@@ -2088,28 +2105,34 @@
.push(function () { .push(function () {
return jio.removeAttachment("document", "attachment"); return jio.removeAttachment("document", "attachment");
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({select_list: ["title"]}); return history.allDocs({select_list: ["title"]});
}) })
.push(function (results) { .push(function (results) {
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
id: "document", id: timestamps[2],
doc: {}, doc: {},
//timestamp: timestamps[2],
value: {title: "foo"} value: {title: "foo"}
}, },
{ {
id: "document", id: timestamps[1],
doc: {}, doc: {},
//timestamp: timestamps[1],
value: {title: "foo"} value: {title: "foo"}
}, },
{ {
id: "document", id: timestamps[0],
doc: {}, doc: {},
//timestamp: timestamps[0],
value: {title: "foo"} value: {title: "foo"}
}], }],
"Attachment on removed document is handled correctly" "Attachment on removed document is handled correctly"
...@@ -2281,6 +2304,8 @@ ...@@ -2281,6 +2304,8 @@
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
timestamps,
not_history = this.not_history,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2314,6 +2339,16 @@ ...@@ -2314,6 +2339,16 @@
.push(function () { .push(function () {
return putFullDoc(jio, "doc", {title: "bar3"}, "data", blobs1[4]); return putFullDoc(jio, "doc", {title: "bar3"}, "data", blobs1[4]);
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({ return history.allDocs({
...@@ -2324,86 +2359,72 @@ ...@@ -2324,86 +2359,72 @@
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[13],
//timestamp: timestamps[13],
value: {title: "bar3"} value: {title: "bar3"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[12],
//timestamp: timestamps[12],
value: {title: "bar3"} value: {title: "bar3"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[11],
//timestamp: timestamps[11],
value: {title: "bar2"} value: {title: "bar2"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[10],
//timestamp: timestamps[10],
value: {title: "bar2"} value: {title: "bar2"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[9],
//timestamp: timestamps[9],
value: {title: "foo1"} value: {title: "foo1"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[8],
//timestamp: timestamps[8],
value: {title: "foo1"} value: {title: "foo1"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[7],
//timestamp: timestamps[7],
value: {title: "foo0"} value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[6],
//timestamp: timestamps[6],
value: {title: "foo0"} value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[5],
//timestamp: timestamps[5],
value: {title: "bar1"} value: {title: "bar1"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[4],
//timestamp: timestamps[4],
value: {title: "bar1"} value: {title: "bar1"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[3],
//timestamp: timestamps[3],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[2],
//timestamp: timestamps[2],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[1],
//timestamp: timestamps[1],
value: {title: "bar"} value: {title: "bar"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[0],
//timestamp: timestamps[0],
value: {title: "bar"} value: {title: "bar"}
} }
], ],
...@@ -2423,6 +2444,8 @@ ...@@ -2423,6 +2444,8 @@
expect(1); expect(1);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history,
timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2443,6 +2466,16 @@ ...@@ -2443,6 +2466,16 @@
.push(function () { .push(function () {
return jio.putAttachment("doc", "data", blobs1[1]); return jio.putAttachment("doc", "data", blobs1[1]);
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({ return history.allDocs({
...@@ -2453,32 +2486,27 @@ ...@@ -2453,32 +2486,27 @@
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[4],
//timestamp: timestamps[4],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[3],
//timestamp: timestamps[3],
value: {title: "foo0"} value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[2],
//timestamp: timestamps[2],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[1],
//timestamp: timestamps[1],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[0],
//timestamp: timestamps[0],
value: {title: "bar"} value: {title: "bar"}
} }
], ],
...@@ -2498,6 +2526,8 @@ ...@@ -2498,6 +2526,8 @@
expect(2); expect(2);
var jio = this.jio, var jio = this.jio,
history = this.history, history = this.history,
not_history = this.not_history,
timestamps,
blobs1 = [ blobs1 = [
new Blob(['a']), new Blob(['a']),
new Blob(['ab']), new Blob(['ab']),
...@@ -2540,6 +2570,16 @@ ...@@ -2540,6 +2570,16 @@
], ],
"allDocs with include_revisions false should return all revisions"); "allDocs with include_revisions false should return all revisions");
}) })
.push(function () {
return not_history.allDocs({
sort_on: [["timestamp", "ascending"]]
});
})
.push(function (results) {
timestamps = results.data.rows.map(function (d) {
return d.id;
});
})
.push(function () { .push(function () {
return history.allDocs({ return history.allDocs({
select_list: ["title"] select_list: ["title"]
...@@ -2549,32 +2589,27 @@ ...@@ -2549,32 +2589,27 @@
deepEqual(results.data.rows, [ deepEqual(results.data.rows, [
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[4],
//timestamp: timestamps[4],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc2", id: timestamps[3],
//timestamp: timestamps[3],
value: {title: "foo0"} value: {title: "foo0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[2],
//timestamp: timestamps[2],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[1],
//timestamp: timestamps[1],
value: {title: "bar0"} value: {title: "bar0"}
}, },
{ {
doc: {}, doc: {},
id: "doc", id: timestamps[0],
//timestamp: timestamps[0],
value: {title: "bar"} value: {title: "bar"}
} }
], ],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment