Commit a6d76543 authored by Romain Courteaud's avatar Romain Courteaud

DocumentStorage: remove should also drop document attachments

parent 29effa3f
/*jslint nomen: true*/
/*global Blob, atob, btoa*/
(function (jIO, Blob, atob, btoa) {
/*global Blob, atob, btoa, RSVP*/
(function (jIO, Blob, atob, btoa, RSVP) {
"use strict";
/**
......@@ -74,10 +74,24 @@
};
DocumentStorage.prototype.remove = function (id) {
return this._sub_storage.removeAttachment(
this._document_id,
var context = this;
return this.allAttachments(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 () {
return id;
});
......@@ -141,4 +155,4 @@
jIO.addStorage('document', DocumentStorage);
}(jIO, Blob, atob, btoa));
}(jIO, Blob, atob, btoa, RSVP));
......@@ -226,22 +226,59 @@
// documentStorage.remove
/////////////////////////////////////////////////////////////////
module("documentStorage.remove");
test("remove called substorage removeAttachment", function () {
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",
document_id: "foo",
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")
.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