Commit b968fe14 authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: add allAtachments and test

parent 9c0c1922
......@@ -281,8 +281,38 @@
});
};
MappingStorage.prototype.hasCapacity = function () {
return this._sub_storage.hasCapacity.apply(this._sub_storage, arguments);
MappingStorage.prototype.allAttachments = function (id) {
var context = this, sub_id;
return getSubStorageId(context, id)
.push(function (sub_id_result) {
sub_id = sub_id_result;
return context._sub_storage.allAttachments(sub_id);
})
.push(function (result) {
var attachment_id,
attachments = {},
mapping_dict = {};
for (attachment_id in context._attachment_mapping_dict) {
if (context._attachment_mapping_dict.hasOwnProperty(attachment_id)) {
mapping_dict[getAttachmentId(context, sub_id, attachment_id, "get")]
= attachment_id;
}
}
for (attachment_id in result) {
if (result.hasOwnProperty(attachment_id)) {
if (mapping_dict.hasOwnProperty(attachment_id)) {
attachments[mapping_dict[attachment_id]] = {};
} else {
attachments[attachment_id] = {};
}
}
}
return attachments;
});
};
MappingStorage.prototype.hasCapacity = function (name) {
return this._sub_storage.hasCapacity(name);
};
MappingStorage.prototype.repair = function () {
......
......@@ -862,6 +862,69 @@
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.allAttachments
/////////////////////////////////////////////////////////////////
module("mappingStorage.allAttachments");
test("allAttachments use sub_storage one's", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
}
});
Storage2713.prototype.allAttachments = function (doc_id) {
equal(doc_id, "42", "allAttachments 2713 called");
return {};
};
jio.allAttachments("42")
.push(function (result) {
deepEqual(result, {});
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("allAttachments use UriTemplate", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
attachment_mapping_dict: {
"2713": {"get": {"uri_template": "www.2713.bar"}}
}
});
Storage2713.prototype.allAttachments = function (doc_id) {
equal(doc_id, "42", "allAttachments 2713 called");
return {"www.2713.bar": {}};
};
jio.allAttachments("42")
.push(function (result) {
deepEqual(result, {"2713": {}});
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.allDocs
/////////////////////////////////////////////////////////////////
......
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