Commit 0e2d44a4 authored by preetwinder's avatar preetwinder

reimplement repair

parent 9f2e7bd5
This diff is collapsed.
...@@ -241,6 +241,14 @@ ...@@ -241,6 +241,14 @@
// indexStorage2.buildQuery // indexStorage2.buildQuery
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
module("indexStorage2.buildQuery", { module("indexStorage2.buildQuery", {
setup: function () {
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
},
teardown: function () { teardown: function () {
deleteIndexedDB(this.jio); deleteIndexedDB(this.jio);
} }
...@@ -257,24 +265,22 @@ ...@@ -257,24 +265,22 @@
} }
}); });
stop(); stop();
expect(3); expect(2);
DummyStorage3.prototype.put = function (id) { DummyStorage3.prototype.put = function (id) {
return id; return id;
}; };
DummyStorage3.prototype.hasCapacity = function (name) {
return name === "list";
};
DummyStorage3.prototype.buildQuery = function (options) { DummyStorage3.prototype.buildQuery = function (options) {
deepEqual(options, {}); if (options.include_docs !== true) {
return [ return [
{id: "2", value: {}}, {id: "2", value: {}},
{id: "32", value: {}}, {id: "32", value: {}},
{id: "16", value: {}}, {id: "16", value: {}},
{id: "21", value: {}} {id: "21", value: {}}
]; ];
}
return [];
}; };
RSVP.all([ RSVP.all([
...@@ -322,6 +328,9 @@ ...@@ -322,6 +328,9 @@
}; };
DummyStorage3.prototype.buildQuery = function (options) { DummyStorage3.prototype.buildQuery = function (options) {
if (options.include_docs === true) {
return [];
}
deepEqual(options, {include_docs: false, select_list: ["a", "c"], deepEqual(options, {include_docs: false, select_list: ["a", "c"],
limit: 3, sort_on: [["a", "descending"], ["b", "ascending"]]}); limit: 3, sort_on: [["a", "descending"], ["b", "ascending"]]});
return [ return [
...@@ -463,10 +472,20 @@ ...@@ -463,10 +472,20 @@
deepEqual(value, {"a": "3", "b": "2"}); deepEqual(value, {"a": "3", "b": "2"});
return id; return id;
}; };
DummyStorage3.prototype.hasCapacity = function (capacity) { DummyStorage3.prototype.hasCapacity = function (name) {
return capacity === 'list'; return (name === 'list');
};
DummyStorage3.prototype.buildQuery = function () {
return [{id: "32", doc: {"a": "3", "b": "2"}}];
};
DummyStorage3.prototype.buildQuery = function () {
return [{id: "32", value: {}}];
};
DummyStorage3.prototype.get = function (id) {
if (id === "32") {
return {"a": "3", "b": "2"};
}
}; };
DummyStorage3.prototype.buildQuery = undefined;
context.jio.put("32", {"a": "3", "b": "2"}) context.jio.put("32", {"a": "3", "b": "2"})
.then(function () { .then(function () {
...@@ -542,9 +561,6 @@ ...@@ -542,9 +561,6 @@
DummyStorage3.prototype.put = function (id) { DummyStorage3.prototype.put = function (id) {
return id; return id;
}; };
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
};
RSVP.all([ RSVP.all([
context.jio.put("1", {"a": "55", "b": "2"}), context.jio.put("1", {"a": "55", "b": "2"}),
...@@ -569,106 +585,6 @@ ...@@ -569,106 +585,6 @@
}); });
}); });
test("select_list option is preset", function () {
var context = this;
context.jio = jIO.createJIO({
type: "index2",
database: "index2_test",
index_keys: ["a", "b", "c"],
sub_storage: {
type: "dummystorage3"
}
});
stop();
expect(2);
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
};
RSVP.all([
context.jio.put("1", {"a": "55", "b": "2", "c": "try"}),
context.jio.put("2", {"a": "98", "b": "2", "c": "adverse"}),
context.jio.put("3", {"a": "75", "b": "2", "c": "invite"}),
context.jio.put("8", {"a": "43", "b": "3", "c": "absolve"}),
context.jio.put("6", {"a": "21", "b": "2", "c": "defy"}),
context.jio.put("4", {"a": "65", "b": "3", "c": "odd"})
])
.then(function () {
return context.jio.allDocs({select_list: ["a", "c"],
query: "b:2"});
})
.then(function (result) {
equal(result.data.total_rows, 4);
deepEqual(result.data.rows.sort(idCompare), [
{id: "1", value: {"a": "55", "c": "try"}},
{id: "2", value: {"a": "98", "c": "adverse"}},
{id: "3", value: {"a": "75", "c": "invite"}},
{id: "6", value: {"a": "21", "c": "defy"}}
]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Select_list key is not present in the index", function () {
var context = this;
context.jio = jIO.createJIO({
type: "index2",
database: "index2_test",
index_keys: ["a", "c"],
sub_storage: {
type: "dummystorage3"
}
});
stop();
expect(3);
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'query') || (name === 'select');
};
DummyStorage3.prototype.buildQuery = function (options) {
deepEqual(options, {select_list: ["a", "b"], query: "a:55"});
return [
{id: "1", value: {"a": "55", "b": "2"}},
{id: "2", value: {"a": "55", "b": "5"}},
{id: "3", value: {"a": "55", "b": "1"}}
];
};
RSVP.all([
context.jio.put("1", {"a": "55", "b": "2", "c": "try"}),
context.jio.put("2", {"a": "55", "b": "5", "c": "adverse"}),
context.jio.put("3", {"a": "55", "b": "1", "c": "invite"})
])
.then(function () {
return context.jio.allDocs({select_list: ["a", "b"],
query: "a:55"});
})
.then(function (result) {
equal(result.data.total_rows, 3);
deepEqual(result.data.rows.sort(idCompare), [
{id: "1", value: {"a": "55", "b": "2"}},
{id: "2", value: {"a": "55", "b": "5"}},
{id: "3", value: {"a": "55", "b": "1"}}
]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Index keys are modified", function () { test("Index keys are modified", function () {
var context = this, dummy_data; var context = this, dummy_data;
context.jio = jIO.createJIO({ context.jio = jIO.createJIO({
...@@ -684,18 +600,18 @@ ...@@ -684,18 +600,18 @@
expect(8); expect(8);
dummy_data = { dummy_data = {
"32": {id: "32", value: {"a": "3", "b": "2", "c": "inverse"}}, "32": {id: "32", doc: {"a": "3", "b": "2", "c": "inverse"}},
"5": {id: "5", value: {"a": "6", "b": "2", "c": "strong"}}, "5": {id: "5", doc: {"a": "6", "b": "2", "c": "strong"}},
"14": {id: "14", value: {"a": "67", "b": "3", "c": "disolve"}} "14": {id: "14", doc: {"a": "67", "b": "3", "c": "disolve"}}
}; };
DummyStorage3.prototype.put = function (id, value) { DummyStorage3.prototype.put = function (id, value) {
dummy_data[id] = {id: id, value: value}; dummy_data[id] = {id: id, doc: value};
return id; return id;
}; };
DummyStorage3.prototype.hasCapacity = function (name) { DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list'); return (name === 'list') || (name === 'include');
}; };
DummyStorage3.prototype.buildQuery = function () { DummyStorage3.prototype.buildQuery = function () {
...@@ -937,6 +853,14 @@ ...@@ -937,6 +853,14 @@
return id; return id;
}; };
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
RSVP.all([ RSVP.all([
context.jio.put("32", {"a": "894", "b": "inversion", "c": 2}), context.jio.put("32", {"a": "894", "b": "inversion", "c": 2}),
context.jio.put("33", {"a": "65", "b": "division", "c": 4}), context.jio.put("33", {"a": "65", "b": "division", "c": 4}),
...@@ -1021,6 +945,14 @@ ...@@ -1021,6 +945,14 @@
} }
}; };
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
RSVP.all([ RSVP.all([
context.jio.post({"a": "5", "b": "inversion", "c": 2}), context.jio.post({"a": "5", "b": "inversion", "c": 2}),
context.jio.post({"a": "62", "b": "division", "c": 4}), context.jio.post({"a": "62", "b": "division", "c": 4}),
......
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