Commit f8efbe05 authored by Romain Courteaud's avatar Romain Courteaud

Allow to create document in union.put

parent 1b3203be
......@@ -102,6 +102,14 @@
var arg = arguments,
context = this;
return this._getWithStorageIndex({"_id": arg[0]._id})
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
// Document does not exist, create in first substorage
return [0];
}
throw error;
})
.push(function (result) {
// Storage found, modify in it directly
var sub_storage = context._storage_list[result[0]];
......
......@@ -395,6 +395,45 @@
});
});
test("put create on first storage", function () {
stop();
expect(4);
function StoragePut404() {
return this;
}
function generatePut404Error(param) {
equal(param._id, "bar", "get Put404 called");
throw new jIO.util.jIOError("Cannot find document", 404);
}
StoragePut404.prototype.get = generatePut404Error;
StoragePut404.prototype.put = function (param) {
deepEqual(param, {"_id": "bar", "title": "foo"}, "put 404 called");
return param._id;
};
jIO.addStorage('unionstorageput404', StoragePut404);
var jio = jIO.createJIO({
type: "union",
storage_list: [{
type: "unionstorageput404"
}, {
type: "unionstorage404"
}]
});
jio.put({"_id": "bar", "title": "foo"})
.then(function (result) {
equal(result, "bar");
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// unionStorage.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