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

MemoryStorage.get now returns attachment list

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