Commit 30b0e964 authored by Bryan Kaperick's avatar Bryan Kaperick

Revision history tests are passing as expected now.

parent adb69072
......@@ -39,7 +39,7 @@
// Prepare to post the current doc as a deprecated version
previous_data = latest_data;
previous_data._deprecated = true;
previous_data._deprecated = "true";
previous_data._doc_id = id;
// Get most recent deprecated version's _revision attribute
......@@ -53,9 +53,9 @@
})
.push(function (query_results) {
if (query_results.length > 0) {
var doc_id = query_results[0];
return this._sub_storage.get(doc_id);
if (query_results.data.rows.length > 0) {
var doc_id = query_results.data.rows[0].id;
return substorage.get(doc_id);
}
throw new jIO.util.jIOError(
"bryanstorage: query returned no results.'",
......@@ -143,30 +143,16 @@
BryanStorage.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
};
/**
BryanStorage.prototype.allDocs = function (options) {
if (options === undefined) {
options = {};
}
console.log("options", options);
BryanStorage.prototype.buildQuery = function (options) {
if (options === undefined) {
options = {query: ""};
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
console.log("query string: ", options.query);
return this._sub_storage.allDocs.apply(this._sub_storage, options);
//return this._sub_storage.buildQuery.apply(this._sub_storage, options);
};
**/
BryanStorage.prototype.buildQuery = function () {
/**
if (options === undefined) {
options = {};
if (options.query !== "") {
options.query = "(" + options.query + ") AND ";
}
options.query = '(' + options.query + ') AND NOT (_deprecated = true)';
**/
console.log("options", arguments);
return this._sub_storage.buildQuery.apply(this._sub_storage, arguments);
options.query = options.query + 'NOT (_deprecated: "true")';
return this._sub_storage.buildQuery(options);
};
jIO.addStorage('bryan', BryanStorage);
......
......@@ -30,17 +30,39 @@
type: "memory"
}
}
}),
not_bryan = jIO.createJIO({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "memory"
}
}
});
jio.put("bar", {"title": "foo"});
jio.put("bar", {"title": "foo0"});
RSVP.all([
jio.put("bar", {"title2": "foo2"}),
jio.put("bar", {"title3": "foo3"})
]
);
//.push(function () {return jio.get("bar"); })
jio.get("bar")
.push(function (result) {equal(result._revision, 3, "parallel exec"); })
jio.put("bar", {"title": "foo1"}),
jio.put("bar", {"title": "foo2"}),
jio.put("bar", {"title": "foo3"}),
jio.put("bar", {"title": "foo4"})
])
.push(function () {return jio.get("bar"); })
.push(function (result) {
deepEqual(result, {
"title": "foo4"
});
})
.push(function () {return not_bryan.allDocs({
query: "_revision: 0"
});
})
.push(function (results) {
equal(results.data.rows.length,
1,
"Only one document with _revision = 0");
})
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
});
......@@ -53,8 +75,8 @@
module("bryanStorage.revision_history");
test("put and get the correct version", function () {
stop();
expect(4);
var dbname = "freshdb0",
expect(7);
var dbname = "rev_hist_db0",
jio = jIO.createJIO({
type: "bryan",
sub_storage: {
......@@ -76,20 +98,22 @@
database: dbname
}
}
});
}),
query_input =
{
query: 'NOT (_deprecated: "true")',
sort_on: [['_revision', 'descending']]
},
query_input2 =
{
query: 'title: "rev1"',
sort_on: [['_revision', 'descending']]
};
jio.put("doc1", {
"title": "rev0",
"subtitle": "subrev0"
})
.push(function () {return jio.get("doc1"); })
.push(function (result) {
deepEqual(result, {
"title": "rev0",
"subtitle": "subrev0"
}, "Retrieve first edition of document correctly");
})
.push(function () {
return jio.put("doc1", {
"title": "rev1",
......@@ -103,60 +127,66 @@
});
})
.push(function () {
return jio.get("doc1");
return jio.put("doc1", {
"title": "rev3",
"subtitle": "subrev3"
});
})
.push(function () {return jio.get("doc1"); })
.push(function (result) {
deepEqual(result, {
"title": "rev2",
"subtitle": "subrev2"
}, "Retrieve second edition of document correctly");
"title": "rev3",
"subtitle": "subrev3"
}, "Retrieve first edition of document correctly");
})
.push(function () {
var options = {query: "title: rev0"};
return jio.allDocs(options);
return not_bryan.allDocs(query_input);
})
.push(function (results) {
console.log("query results: ", results);
equal(results.data.rows.length, 1, "Query only returns latest version");
if (results.data.rows.length > 0) {
equal(results.data.rows.length, 1, "Only 1 version isn't _deprecated");
return jio.get(results.data.rows[0].id);
}
})
.push(function (result) {
deepEqual(result, {
"title": "rev2",
"subtitle": "subrev2"
}, "Retrieve queried document correctly");
"title": "rev3",
"subtitle": "subrev3"
}, "Retrieve most recent edition by querying NOT _deprecated");
})
// When not_bryan queries the storage, all documents are returned.
.push(function () {
var options = {
query: "",
sort_on: [["_revision", "ascending"]]
};
return jio.allDocs(options);
return not_bryan.allDocs(query_input2);
})
.push(function (results) {
equal(results.length, 2, "should get all 2 revisions.");
if (results.length > 0) {
return not_bryan.get(results[0].id);
}
equal(results.data.rows.length, 1, "Only one version is titled 'rev1'");
return jio.get(results.data.rows[0].id);
})
.push(function (results) {
deepEqual(results, {
"title": "rev0",
"subtitle": "subrev0",
"_doc_id": "doc1",
"_revision": 0,
"_deprecated": true
.push(function (result) {
deepEqual(result, {
"title": "rev1",
"subtitle": "subrev1",
"_deprecated": "true",
"_revision": 1,
"_doc_id": "doc1"
},
"Get the earliest copy of the doc with all metadata.");
"Retrieve 1st edit by querying for title: 'rev1' with other storage");
})
.push(function () {
return jio.allDocs({query: ''});
})
.push(function (results) {
equal(results.data.rows.length,
1,
"bryanstorage only sees latest version");
return jio.get(results.data.rows[0].id);
})
.push(function (result) {
deepEqual(result, {
"title": "rev3",
"subtitle": "subrev3"
}, "Retrieve latest version correctly with bryanstorage");
})
.fail(function (error) {
console.log(error);
//console.log(error);
ok(false, error);
})
.always(function () {
......@@ -164,25 +194,35 @@
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.revision_history_multiple_edits
/////////////////////////////////////////////////////////////////
module("bryanStorage.revision_history_multiple_edits");
test("modify first version but save both", function () {
stop();
expect(7);
var jio = jIO.createJIO({
expect(11);
var dbname = "testdb20",
jio = jIO.createJIO({
type: "bryan",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "testdb1"
database: dbname
}
}
}),
not_bryan = jIO.createJIO({
type: "query",
sub_storage: {
type: "uuid",
sub_storage: {
type: "indexeddb",
database: "testdb1"
database: dbname
}
}
});
jio.put("main_doc", {
......@@ -239,8 +279,9 @@
});
})
.push(function (result) {
//console.log(result);
equal(result.length, 2, "Empty query returns only non-deprecated docs");
equal(result.data.rows.length,
2,
"Empty query returns only non-deprecated docs");
})
.push(function () {
return jio.allDocs({
......@@ -248,16 +289,18 @@
});
})
.push(function (result) {
//console.log("res:", result);
if (result.length > 0) {
return jio.get(result[0].id);
equal(result.data.rows.length,
1,
"No deprecated results are returned.");
if (result.data.rows.length > 0) {
return jio.get(result.data.rows[0].id);
}
})
.push(function (result) {
deepEqual(result, {
"attr": "version1",
"subattr": "subversion1"
}, "Retrieve other document correctly");
}, "Only get most recent edit");
})
.push(function () {
return jio.allDocs({
......@@ -265,7 +308,7 @@
});
})
.push(function (result) {
equal(result.length, 0, "Correct number of results returned");
equal(result.data.rows.length, 0, "Correct number of results returned");
})
.push(function () {
return jio.allDocs({
......@@ -273,7 +316,7 @@
});
})
.push(function (result) {
equal(result.length, 0, "Correct number of results returned");
equal(result.data.rows.length, 0, "Correct number of results returned");
})
.push(function () {
return jio.allDocs({
......@@ -281,7 +324,7 @@
});
})
.push(function (result) {
equal(result.length, 2, "Correct number of results returned");
equal(result.data.rows.length, 2, "Correct number of results returned");
})
// When not_bryan queries the storage, all documents are returned.
......@@ -293,8 +336,10 @@
return not_bryan.allDocs(options);
})
.push(function (results) {
equal(results.length, 3, "should get all 3 deprecated versions.");
return not_bryan.get(results[0].id);
equal(results.data.rows.length,
3,
"should get all 3 deprecated versions.");
return not_bryan.get(results.data.rows[0].id);
})
.push(function (results) {
deepEqual(results, {
......@@ -302,7 +347,7 @@
"subtitle": "subrev0",
"_doc_id": "main_doc",
"_revision": 0,
"_deprecated": true
"_deprecated": "true"
},
"Get the earliest copy of the doc with all metadata.");
})
......@@ -316,7 +361,7 @@
return not_bryan.allDocs(options);
})
.push(function (results) {
return not_bryan.get(results[1].id);
return not_bryan.get(results.data.rows[1].id);
})
.push(function (results) {
deepEqual(results, {
......@@ -324,7 +369,7 @@
"subtitle": "subrev1",
"_doc_id": "main_doc",
"_revision": 1,
"_deprecated": true
"_deprecated": "true"
},
"Get the earliest copy of the doc with all metadata.");
})
......
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