Commit d41b35da authored by Tristan Cavelier's avatar Tristan Cavelier

jio putAttachment API changed

// Before:
jio.putAttachment({
  "id": "docid/attmtid",
  "data": "abc",
  "mimetype": "text/plain",
  "rev": "xxxx"
});

// Now:
jio.putAttachment({
  "_id": "docid/attmtid",
  "_data": "abc",
  "_mimetype": "text/plain",
  "_rev": "xxxxx"
});
parent 62bd25fe
...@@ -396,19 +396,13 @@ Object.defineProperty(that, "putAttachment", { ...@@ -396,19 +396,13 @@ Object.defineProperty(that, "putAttachment", {
enumerable: false, enumerable: false,
writable: false, writable: false,
value: function (doc, options, success, error) { value: function (doc, options, success, error) {
var param, k, doc_with_underscores = {}; var param = priv.parametersToObject(
param = priv.parametersToObject(
[options, success, error], [options, success, error],
{max_retry: 0} {max_retry: 0}
); );
for (k in doc) {
if (doc.hasOwnProperty(k) && k.match('[^_].*')) {
doc_with_underscores["_" + k] = doc[k];
}
}
priv.addJob(putAttachmentCommand, { priv.addJob(putAttachmentCommand, {
doc: doc_with_underscores, doc: doc,
options: param.options, options: param.options,
callbacks: {success: param.success, error: param.error} callbacks: {success: param.success, error: param.error}
}); });
......
...@@ -360,9 +360,9 @@ test ("All requests ok", function () { ...@@ -360,9 +360,9 @@ test ("All requests ok", function () {
o.spy(o, "status", 22, o.spy(o, "status", 22,
"Put attachment without id"); "Put attachment without id");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file", "_id": "file",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -370,9 +370,9 @@ test ("All requests ok", function () { ...@@ -370,9 +370,9 @@ test ("All requests ok", function () {
o.spy(o, "value", {"ok": true, "id": "file/attmt"}, o.spy(o, "value", {"ok": true, "id": "file/attmt"},
"Put attachment"); "Put attachment");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file/attmt", "_id": "file/attmt",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -445,9 +445,9 @@ test ("All requests fail", function () { ...@@ -445,9 +445,9 @@ test ("All requests fail", function () {
o.spy(o, "status", 22, o.spy(o, "status", 22,
"Put attachment without id"); "Put attachment without id");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file", "_id": "file",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -455,9 +455,9 @@ test ("All requests fail", function () { ...@@ -455,9 +455,9 @@ test ("All requests fail", function () {
o.spy(o, "status", 0, o.spy(o, "status", 0,
"Put attachment"); "Put attachment");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file/attmt", "_id": "file/attmt",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -513,9 +513,9 @@ test ("All document not found", function () { ...@@ -513,9 +513,9 @@ test ("All document not found", function () {
o.spy(o, "status", 22, o.spy(o, "status", 22,
"Put attachment without id"); "Put attachment without id");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file", "_id": "file",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -523,9 +523,9 @@ test ("All document not found", function () { ...@@ -523,9 +523,9 @@ test ("All document not found", function () {
o.spy(o, "value", {"ok": true, "id": "file/attmt"}, o.spy(o, "value", {"ok": true, "id": "file/attmt"},
"Put attachment"); "Put attachment");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file/attmt", "_id": "file/attmt",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -575,9 +575,9 @@ test ("All document found", function () { ...@@ -575,9 +575,9 @@ test ("All document found", function () {
o.spy(o, "status", 22, o.spy(o, "status", 22,
"Put attachment without id"); "Put attachment without id");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file", "_id": "file",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -585,9 +585,9 @@ test ("All document found", function () { ...@@ -585,9 +585,9 @@ test ("All document found", function () {
o.spy(o, "value", {"ok": true, "id": "file/attmt"}, o.spy(o, "value", {"ok": true, "id": "file/attmt"},
"Put attachment"); "Put attachment");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "file/attmt", "_id": "file/attmt",
"data": "0123456789", "_data": "0123456789",
"mimetype": "text/plain" "_mimetype": "text/plain"
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -881,13 +881,13 @@ test ("PutAttachment", function(){ ...@@ -881,13 +881,13 @@ test ("PutAttachment", function(){
// putAttachment without attachment id // putAttachment without attachment id
// error 22 -> attachment id required // error 22 -> attachment id required
o.spy(o, "status", 22, "PutAttachment without attachment id"); o.spy(o, "status", 22, "PutAttachment without attachment id");
o.jio.putAttachment({"id": "putattmt1"}, o.f); o.jio.putAttachment({"_id": "putattmt1"}, o.f);
o.tick(o); o.tick(o);
// putAttachment without document // putAttachment without document
// error 404 -> not found // error 404 -> not found
o.spy(o, "status", 404, "PutAttachment without document"); o.spy(o, "status", 404, "PutAttachment without document");
o.jio.putAttachment({"id": "putattmt1/putattmt2"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2"}, o.f);
o.tick(o); o.tick(o);
// adding a document // adding a document
...@@ -899,7 +899,7 @@ test ("PutAttachment", function(){ ...@@ -899,7 +899,7 @@ test ("PutAttachment", function(){
// putAttachment with document // putAttachment with document
o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"}, o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"},
"PutAttachment with document, without data"); "PutAttachment with document, without data");
o.jio.putAttachment({"id": "putattmt1/putattmt2"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
...@@ -929,7 +929,7 @@ test ("PutAttachment", function(){ ...@@ -929,7 +929,7 @@ test ("PutAttachment", function(){
// update attachment // update attachment
o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"}, o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"},
"Update Attachment, with data"); "Update Attachment, with data");
o.jio.putAttachment({"id": "putattmt1/putattmt2", "data": "abc"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2", "_data": "abc"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
...@@ -1584,7 +1584,7 @@ test("Put Attachment", function () { ...@@ -1584,7 +1584,7 @@ test("Put Attachment", function () {
// putAttachment without attachment id // putAttachment without attachment id
// erorr 22 -> attachment id required // erorr 22 -> attachment id required
o.spy(o, "status", 22, "PutAttachment without attachment id"); o.spy(o, "status", 22, "PutAttachment without attachment id");
o.jio.putAttachment({"id": "putattmt1"}, o.f); o.jio.putAttachment({"_id": "putattmt1"}, o.f);
o.tick(o); o.tick(o);
// putAttachment without document // putAttachment without document
...@@ -1594,7 +1594,7 @@ test("Put Attachment", function () { ...@@ -1594,7 +1594,7 @@ test("Put Attachment", function () {
o.rev = "1-" + o.rev_hash; o.rev = "1-" + o.rev_hash;
o.spy(o, "value", {"ok": true, "id": "doc1/attmt1", "rev": o.rev}, o.spy(o, "value", {"ok": true, "id": "doc1/attmt1", "rev": o.rev},
"PutAttachment without document, without data"); "PutAttachment without document, without data");
o.jio.putAttachment({"id": "doc1/attmt1"}, o.f); o.jio.putAttachment({"_id": "doc1/attmt1"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
...@@ -1636,9 +1636,9 @@ test("Put Attachment", function () { ...@@ -1636,9 +1636,9 @@ test("Put Attachment", function () {
o.spy(o, "value", {"ok": true, "id": "doc1/attmt1", "rev": o.rev}, o.spy(o, "value", {"ok": true, "id": "doc1/attmt1", "rev": o.rev},
"Update Attachment, with data"); "Update Attachment, with data");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "doc1/attmt1", "_id": "doc1/attmt1",
"data": "abc", "_data": "abc",
"rev": o.prev_rev "_rev": o.prev_rev
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -1681,9 +1681,9 @@ test("Put Attachment", function () { ...@@ -1681,9 +1681,9 @@ test("Put Attachment", function () {
o.spy(o, "value", {"ok": true, "id": "doc1/attmt2", "rev": o.rev}, o.spy(o, "value", {"ok": true, "id": "doc1/attmt2", "rev": o.rev},
"PutAttachment without document, without data"); "PutAttachment without document, without data");
o.jio.putAttachment({ o.jio.putAttachment({
"id": "doc1/attmt2", "_id": "doc1/attmt2",
"data": "def", "_data": "def",
"rev": o.prev_rev "_rev": o.prev_rev
}, o.f); }, o.f);
o.tick(o); o.tick(o);
...@@ -3449,13 +3449,13 @@ test ("PutAttachment", function(){ ...@@ -3449,13 +3449,13 @@ test ("PutAttachment", function(){
// putAttachment without attachment id // putAttachment without attachment id
// error 22 -> attachment id required // error 22 -> attachment id required
o.spy(o, "status", 22, "PutAttachment without attachment id"); o.spy(o, "status", 22, "PutAttachment without attachment id");
o.jio.putAttachment({"id": "putattmt1"}, o.f); o.jio.putAttachment({"_id": "putattmt1"}, o.f);
o.tick(o); o.tick(o);
// putAttachment without document // putAttachment without document
// error 404 -> not found // error 404 -> not found
o.spy(o, "status", 404, "PutAttachment without document"); o.spy(o, "status", 404, "PutAttachment without document");
o.jio.putAttachment({"id": "putattmt1/putattmt2"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2"}, o.f);
o.tick(o); o.tick(o);
// putAttachment with document // putAttachment with document
...@@ -3467,7 +3467,7 @@ test ("PutAttachment", function(){ ...@@ -3467,7 +3467,7 @@ test ("PutAttachment", function(){
o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"}, o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"},
"PutAttachment with document, without data"); "PutAttachment with document, without data");
o.jio.putAttachment({"id": "putattmt1/putattmt2"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
...@@ -3497,7 +3497,7 @@ test ("PutAttachment", function(){ ...@@ -3497,7 +3497,7 @@ test ("PutAttachment", function(){
// update attachment // update attachment
o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"}, o.spy(o, "value", {"ok": true, "id": "putattmt1/putattmt2"},
"Update Attachment, with data"); "Update Attachment, with data");
o.jio.putAttachment({"id": "putattmt1/putattmt2", "data": "abc"}, o.f); o.jio.putAttachment({"_id": "putattmt1/putattmt2", "_data": "abc"}, o.f);
o.tick(o); o.tick(o);
// check document // check document
...@@ -3685,13 +3685,13 @@ test ("Remove", function(){ ...@@ -3685,13 +3685,13 @@ test ("Remove", function(){
o.tick(o); o.tick(o);
// adding an attachment // adding an attachment
o.jio.putAttachment({"id":"remove3/removeAtt", "mimetype":"text/plain", o.jio.putAttachment({"_id":"remove3/removeAtt", "_mimetype":"text/plain",
"content":"hello"}); "_data":"hello"});
o.tick(o); o.tick(o);
// add another attachment // add another attachment
o.jio.putAttachment({"id":"remove3/removeAtt2", "mimetype":"text/plain", o.jio.putAttachment({"_id":"remove3/removeAtt2", "_mimetype":"text/plain",
"content":"hello2"}); "_data":"hello2"});
o.tick(o); o.tick(o);
// remove attachment // remove attachment
......
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