Commit a6d76543 authored by Romain Courteaud's avatar Romain Courteaud

DocumentStorage: remove should also drop document attachments

parent 29effa3f
/*jslint nomen: true*/ /*jslint nomen: true*/
/*global Blob, atob, btoa*/ /*global Blob, atob, btoa, RSVP*/
(function (jIO, Blob, atob, btoa) { (function (jIO, Blob, atob, btoa, RSVP) {
"use strict"; "use strict";
/** /**
...@@ -74,10 +74,24 @@ ...@@ -74,10 +74,24 @@
}; };
DocumentStorage.prototype.remove = function (id) { DocumentStorage.prototype.remove = function (id) {
return this._sub_storage.removeAttachment( var context = this;
this._document_id, return this.allAttachments(id)
getSubAttachmentIdFromParam(id) .push(function (result) {
) var key,
promise_list = [];
for (key in result) {
if (result.hasOwnProperty(key)) {
promise_list.push(context.removeAttachment(id, key));
}
}
return RSVP.all(promise_list);
})
.push(function () {
return context._sub_storage.removeAttachment(
context._document_id,
getSubAttachmentIdFromParam(id)
);
})
.push(function () { .push(function () {
return id; return id;
}); });
...@@ -141,4 +155,4 @@ ...@@ -141,4 +155,4 @@
jIO.addStorage('document', DocumentStorage); jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, atob, btoa)); }(jIO, Blob, atob, btoa, RSVP));
...@@ -226,22 +226,59 @@ ...@@ -226,22 +226,59 @@
// documentStorage.remove // documentStorage.remove
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
module("documentStorage.remove"); module("documentStorage.remove");
test("remove called substorage removeAttachment", function () { test("remove called substorage removeAttachment", function () {
stop(); stop();
expect(3); expect(8);
var jio = jIO.createJIO({ var i = 0,
jio;
function StorageRemoveWithAttachment() {
return this;
}
StorageRemoveWithAttachment.prototype.allAttachments = function (id) {
equal(id, "foo", "allAttachments 200 called");
var result = {};
result['jio_attachment/' + btoa("bar") + "/" +
btoa("bar1")] = {};
result['jio_attachment/' + btoa("bar") + "/" +
btoa("bar2")] = {};
result['jio_attachment/' + btoa("foo") + "/" +
btoa("foo3")] = {};
return result;
};
StorageRemoveWithAttachment.prototype.removeAttachment =
function (id, name) {
if (i === 0) {
equal(id, "foo", "removeAttachment called");
equal(name, "jio_attachment/YmFy/YmFyMQ==",
"removeAttachment called");
} else if (i === 1) {
equal(id, "foo", "removeAttachment called");
equal(name, "jio_attachment/YmFy/YmFyMg==",
"removeAttachment called");
} else if (i === 2) {
equal(id, "foo", "removeAttachment called");
equal(name, "jio_document/YmFy.json",
"removeAttachment called");
} else {
ok(false, "Unexpected removeAttachment call: " + id + " " + name);
}
i += 1;
return id;
};
jIO.addStorage('documentstorageremovewithattachment',
StorageRemoveWithAttachment);
jio = jIO.createJIO({
type: "document", type: "document",
document_id: "foo", document_id: "foo",
sub_storage: { sub_storage: {
type: "documentstorage200" type: "documentstorageremovewithattachment"
} }
}); });
Storage200.prototype.removeAttachment = function (id, name) {
equal(id, "foo", "removeAttachment 200 called");
equal(name, "jio_document/YmFy.json", "removeAttachment 200 called");
return id;
};
jio.remove("bar") jio.remove("bar")
.then(function (result) { .then(function (result) {
......
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