Commit 09b72b51 authored by Romain Courteaud's avatar Romain Courteaud

wip indexeddb: do not delete before putting

parent a4c8a030
......@@ -507,39 +507,39 @@
return waitForTransaction(db, ["attachment", "blob"], "readwrite",
function (tx) {
// First remove the previous attachment
return removeAttachment(tx, id, name)
.then(function () {
var blob_store,
promise_list,
i;
// Then write the attachment info
promise_list = [
waitForIDBRequest(tx.objectStore("attachment").put({
"_key_path": buildKeyPath([id, name]),
"_id": id,
"_attachment": name,
"info": {
"content_type": blob.type,
"length": blob.size
}
}))
];
// Finally, write all blob parts
blob_store = tx.objectStore("blob");
for (i = 0; i < blob_part.length; i += 1) {
promise_list.push(
waitForIDBRequest(blob_store.put({
"_key_path": buildKeyPath([id, name, i]),
"_id" : id,
"_attachment" : name,
"_part" : i,
"blob": blob_part[i]
}))
);
// return removeAttachment(tx, id, name)
// .then(function () {
var blob_store,
promise_list,
i;
// Then write the attachment info
promise_list = [
waitForIDBRequest(tx.objectStore("attachment").put({
"_key_path": buildKeyPath([id, name]),
"_id": id,
"_attachment": name,
"info": {
"content_type": blob.type,
"length": blob.size
}
return RSVP.all(promise_list);
});
}))
];
// Finally, write all blob parts
blob_store = tx.objectStore("blob");
for (i = 0; i < blob_part.length; i += 1) {
promise_list.push(
waitForIDBRequest(blob_store.put({
"_key_path": buildKeyPath([id, name, i]),
"_id" : id,
"_attachment" : name,
"_part" : i,
"blob": blob_part[i]
}))
);
}
return RSVP.all(promise_list);
});
// });
});
});
};
......
......@@ -1554,7 +1554,7 @@
var context = this,
attachment = "attachment";
stop();
expect(23);
expect(17);
deleteIndexedDB(context.jio)
.then(function () {
......@@ -1601,27 +1601,30 @@
equal(context.spy_transaction.firstCall.args[1], "readwrite",
"transaction second argument");
equal(context.spy_store.callCount, 4, "store count " +
equal(context.spy_store.callCount, 2, "store count " +
context.spy_store.callCount);
deepEqual(context.spy_store.firstCall.args[0], "attachment",
"store first argument");
deepEqual(context.spy_store.secondCall.args[0], "blob",
"store first argument");
/*
deepEqual(context.spy_store.thirdCall.args[0], "attachment",
"store first argument");
deepEqual(context.spy_store.getCall(3).args[0], "blob",
"store first argument");
equal(context.spy_delete.callCount, 1, "delete count " +
*/
equal(context.spy_delete.callCount, 0, "delete count " +
context.spy_delete.callCount);
/*
deepEqual(context.spy_delete.firstCall.args[0], "foo_attachment",
"delete first argument");
ok(context.spy_index.calledOnce, "index count " +
*/
equal(context.spy_index.callCount, 0, "index count " +
context.spy_index.callCount);
ok(context.spy_cursor.calledOnce, "cursor count " +
equal(context.spy_cursor.callCount, 0, "cursor count " +
context.spy_cursor.callCount);
/*
equal(context.spy_cursor_delete.callCount, 0, "delete count " +
context.spy_cursor_delete.callCount);
ok(context.spy_key_range.calledOnce, "key range count " +
......@@ -1629,7 +1632,7 @@
deepEqual(context.spy_key_range.firstCall.args[0],
["foo", "attachment"],
"key range first argument");
*/
equal(context.spy_put.callCount, 3, "put count " +
context.spy_put.callCount);
deepEqual(context.spy_put.firstCall.args[0], {
......
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