Commit 62947ca8 authored by Tristan Cavelier's avatar Tristan Cavelier

indexstorage.js can now add metadata to databases

parent 6246d78b
......@@ -509,13 +509,18 @@
});
}
function createDatabaseAndPutAttachmentIfPossible(err) {
var metadata;
if (err.status === 404) {
metadata = {"_id": index.id};
if (typeof index.metadata === 'object' &&
// adding metadata
index.metadata !== null &&
!Array.isArray(index.metadata)) {
metadata = jIO.util.dictUpdate(metadata, index.metadata);
}
return command.storage(
index.sub_storage || that._sub_storage
).post({
"_id": index.id
// XXX add metadata to document if necessary
}).then(putAttachment, null, function () {
).post(metadata).then(putAttachment, null, function () {
throw null; // stop post progress propagation
});
}
......
......@@ -69,7 +69,7 @@
module("IndexStorage");
test("Scenario", 38, function () {
test("Scenario", 39, function () {
var LOCAL_STORAGE_SPEC = local_storage.createDescription(
'indexstorage tests',
......@@ -78,7 +78,9 @@
), INDEX_STORAGE_SPEC = {
"type": "indexed",
"indices": [
{"id": "A", "index": ["contributor"]},
{"id": "A", "index": ["contributor"], "metadata": {
"title": "Database - A"
}},
{"id": "B", "index": ["author"]},
{"id": "C", "index": ["title"]},
{"id": "D", "index": ["title", "year"]}
......@@ -378,6 +380,32 @@
}, "List 8 documents from local (4 document + 4 databases)");
}
function getDatabaseMetadata() {
return jio_local.get({"_id": "A"});
}
function getDatabaseMetadataTest(answer) {
deepEqual(answer, {
"data": {
"_attachments": {
"body": {
"content_type": "application/json",
"digest": "sha256-365910ba219365b68e3431f9762eef21f" +
"77cd390dbcc55d827d42555c66340a6",
"length": 105
}
},
"_id": "A",
"title": "Database - A"
},
"id": "A",
"method": "get",
"result": "success",
"status": 200,
"statusText": "Ok"
}, "Check one index database metadata");
}
// function removeCreatedDocuments() {
// return success(RSVP.all([
// jio_index.remove({"_id": shared.created_document_id}),
......@@ -914,6 +942,8 @@
then(listDocumentsFromNothingTest).
// allD 200 8 documents from local
then(listDocumentsFromLocal).then(listDocumentsFromLocalTest).
// get 200 database to check metadatas from local
then(getDatabaseMetadata).then(getDatabaseMetadataTest).
// remove a b ce dee 204
then(removeCreatedDocuments).then(removeCreatedDocumentsTest).
// allD 200 empty indexes
......
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