Commit 315da2d6 authored by Romain Courteaud's avatar Romain Courteaud

MemoryStorage.get now returns attachment list

parent eab60f05
......@@ -33,7 +33,6 @@
this._database = {};
}
MemoryStorage.prototype.put = function (metadata) {
if (!this._database.hasOwnProperty(metadata._id)) {
this._database[metadata._id] = {
......@@ -45,8 +44,13 @@
};
MemoryStorage.prototype.get = function (param) {
var doc,
key,
found = false,
attachments = {};
try {
return JSON.parse(this._database[param._id].doc);
doc = JSON.parse(this._database[param._id].doc);
} catch (error) {
if (error instanceof TypeError) {
throw new jIO.util.jIOError(
......@@ -58,22 +62,16 @@
}
// XXX NotImplemented: list all attachments
// var doc = JSON.parse(this._database[param._id].doc),
// key,
// found = false,
// attachments = {};
//
// for (key in this._database[param._id].attachments) {
// if (this._database[param._id].attachments.hasOwnProperty(key)) {
// found = true;
// attachments[key] = {};
// }
// }
// if (found) {
// doc._attachments = attachments;
// }
// return doc;
for (key in this._database[param._id].attachments) {
if (this._database[param._id].attachments.hasOwnProperty(key)) {
found = true;
attachments[key] = {};
}
}
if (found) {
doc._attachments = attachments;
}
return doc;
};
MemoryStorage.prototype.remove = function (param) {
......
......@@ -155,34 +155,33 @@
});
});
// test("get document with attachment", function () {
// var id = "putattmt1";
//
// this.jio.__storage._database[id] = {
// "doc": JSON.stringify({}),
// "attachments": {
// putattmt2: undefined
// }
// };
//
// stop();
// expect(1);
//
// this.jio.get({"_id": id})
// .then(function (result) {
// deepEqual(result, {
// "_id": id,
// "_attachment": {},
// "title": "myPost1"
// }, "Check document");
// })
// .fail(function (error) {
// ok(false, error);
// })
// .always(function () {
// start();
// });
// });
test("get document with attachment", function () {
var id = "putattmt1";
this.jio.__storage._database[id] = {
"doc": JSON.stringify({}),
"attachments": {
putattmt2: undefined
}
};
stop();
expect(1);
this.jio.get({"_id": id})
.then(function (result) {
deepEqual(result, {
"_id": id,
"_attachments": {putattmt2: {}}
}, "Check document");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// memoryStorage.remove
......
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