Commit 770d537c authored by Sven Franck's avatar Sven Franck

bugfixes remove

parent 01600d61
...@@ -636,7 +636,7 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -636,7 +636,7 @@ jIO.addStorageType('revision', function (spec, my) {
} }
del_rev = command.getDoc()._rev; del_rev = command.getDoc()._rev;
f.removeDocument = function (docid) { f.removeDocument = function (docid, doctree) {
if (command.getOption("keep_revision_history") !== true) { if (command.getOption("keep_revision_history") !== true) {
that.addJob( that.addJob(
"remove", "remove",
...@@ -644,12 +644,13 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -644,12 +644,13 @@ jIO.addStorageType('revision', function (spec, my) {
docid, docid,
option, option,
function (response) { function (response) {
if ( command.getAttachmentId() === undefined ) { if (typeof command.getAttachmentId() === undefined ){
priv.update_doctree_on_remove = true; priv.postToDocumentTree(doctree, command.getDoc(),
true
);
} else { } else {
priv.update_doctree_on_remove = false; priv.postToDocumentTree(doctree, command.getDoc());
} }
that.post(command);
}, },
function (err) { function (err) {
that.error({ that.error({
...@@ -664,12 +665,6 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -664,12 +665,6 @@ jIO.addStorageType('revision', function (spec, my) {
); );
} else { } else {
// keep history = update document tree only // keep history = update document tree only
if (command.getAttachmentId() === undefined ) {
priv.update_doctree_on_remove = true;
} else {
priv.update_doctree_on_remove = false;
}
that.post(command);
} }
}; };
if (typeof del_rev === "string") { if (typeof del_rev === "string") {
...@@ -685,7 +680,8 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -685,7 +680,8 @@ jIO.addStorageType('revision', function (spec, my) {
return; return;
} }
} }
// get doctree
// get doctree
that.addJob( that.addJob(
"get", "get",
priv.substorage, priv.substorage,
...@@ -708,14 +704,13 @@ jIO.addStorageType('revision', function (spec, my) { ...@@ -708,14 +704,13 @@ jIO.addStorageType('revision', function (spec, my) {
// revision provided // revision provided
if (typeof command.getAttachmentId() === "string"){ if (typeof command.getAttachmentId() === "string"){
f.removeDocument(command.getDocId()+"."+del_rev+"/"+ f.removeDocument(command.getDocId()+"."+del_rev+"/"+
command.getAttachmentId()); command.getAttachmentId(), response);
} else { } else {
if (del_rev === // loop leaves
priv.getWinnerRevisionFromDocumentTree(response)[0].rev if (priv.isRevisionALeaf(del_rev,
){ priv.getLeavesFromDocumentTree(response)) === true){
priv.dummy = true; f.removeDocument(command.getDocId()+"."+
f.removeDocument(command.getDocId()+"."+ del_rev, response);
del_rev);
} else { } else {
that.error({ that.error({
"status": 409, "status": 409,
......
...@@ -1561,107 +1561,123 @@ test ("Scenario", function(){ ...@@ -1561,107 +1561,123 @@ test ("Scenario", function(){
}); });
o.localpath = "jio/localstorage/usam1/asam1"; o.localpath = "jio/localstorage/usam1/asam1";
// 1. put non empty document A-1 // 1. new application
ok ( o.jio, "Open Application with Revision and Local Storage (new JIO)");
// 2. put non empty document A-1
o.doc = {"_id": "sample1", "title": "mySample1"}; o.doc = {"_id": "sample1", "title": "mySample1"};
o.revisions = {"start": 0, "ids": []}; o.revisions = {"start": 0, "ids": []};
o.hex = generateRevisionHash(o.doc, o.revisions); o.hex = generateRevisionHash(o.doc, o.revisions);
o.rev = "1-"+o.hex; o.rev = "1-"+o.hex;
o.spy (o, "value", {"ok": true, "id": "sample1", "rev": o.rev}, o.spy (o, "value", {"ok": true, "id": "sample1", "rev": o.rev},
"Open Application with Revision and Local Storage, create document"); "Create a new document");
o.jio.put(o.doc, o.f); o.jio.put(o.doc, o.f);
o.tick(o); o.tick(o);
// 2. put non empty document A-2 o.doc_response = {"_id": "sample1."+o.rev, "title": "mySample1"};
o.doc_b = {"_id": "sample1", "title": "mySample2"};
o.revisions_b = {"start": 0, "ids": []};
o.hex_b = generateRevisionHash(o.doc_b, o.revisions_b);
o.rev_b = "1-"+o.hex_b;
o.spy (o,"status", 409, "409 - Try to create 2nd version (in first tab)");
o.jio.put(o.doc_b, o.f);
o.tick(o);
// FAKE IT
o.doc_f = {"_id": "sample1", "title": "mySample2"};
o.revisions_f = {"start": 0, "ids": []};
o.hex_f = generateRevisionHash(o.doc_f, o.revisions_f);
o.rev_f = "1-"+o.hex_f;
o.doc_f2 = {"_id": "sample1", "title": "mySample2"};
localstorage.setItem(o.localpath+"/sample1."+o.rev_f, o.doc_f2);
o.doctree = {"children":[ // 3. check that document was created
{ "rev": o.rev, "status": "available", "children": []},
{ "rev": o.rev_f, "status": "available", "children": []}
]};
localstorage.setItem(o.localpath+"/sample1.revision_tree.json", o.doctree);
// 3. Check that 2nd version has been created (manually)
deepEqual( deepEqual(
localstorage.getItem(o.localpath+"/sample1."+o.rev_f), localstorage.getItem(o.localpath+"/sample1."+o.rev),
o.doc_f, "Create 2nd version in new tab (manually in local storage)" o.doc_response,
"Keep this document and revision in memory (document exists)"
); );
// 4. GET first version // 4. open new tab (JIO)
o.mydocSample1 = {"_id": "sample1", "title": "mySample1", "_rev": o.rev}; o.jio2 = JIO.newJio({
o.mydocSample1._revisions = {"ids":[o.hex], "start":1 }; "type": "revision",
o.mydocSample1._revs_info = [{"rev": o.rev, "status": "available"}]; "secondstorage": {
o.mydocSample1._conflicts = [o.rev_f]; "type": "local",
o.spy(o, "value", o.mydocSample1, "Get first version"); "username": "usam1",
o.jio.get("sample1", { "applicationname": "asam1"
}
});
o.localpath = "jio/localstorage/usam1/asam1";
// 5. Create a new JIO in a new tab
ok ( o.jio2, "Open a new tab (new JIO)");
// 6. Get the document from the first storage
o.doc._rev = o.rev;
o.doc._revisions = {"ids":[o.hex], "start":1 };
o.doc._revs_info = [{"rev": o.rev, "status": "available"}];
o.spy(o, "value", o.doc, "Get the first document in new tab");
o.jio2.get("sample1", {
"revs_info": true, "revs": true, "conflicts": true, "revs_info": true, "revs": true, "conflicts": true,
"rev": o.rev }, o.f); "rev": o.rev }, o.f);
o.tick(o); o.tick(o);
// 5. MODFIY first version // 7. MODFIY the 2nd version
o.doc_2 = {"_id": "sample1", "_rev": o.rev, "title": "mySample1_modified"}; o.doc_2 = {"_id": "sample1", "_rev": o.rev,
o.revisions_2 = {"start": 1, "ids":[o.rev.split('-')[1] "title":"mySample2_modified"};
]}; o.revisions_2 = {"start":1 , "ids":[o.hex]};
o.hex_2 = generateRevisionHash(o.doc_2, o.revisions_2); o.hex_2 = generateRevisionHash(o.doc_2, o.revisions_2)
o.rev_2 = "2-"+o.hex_2; o.rev_2 = "2-"+o.hex_2;
o.spy (o, "value", {"id":"sample1", "ok":true, "rev": o.rev_2}, o.spy (o, "value", {"id":"sample1", "ok":true, "rev": o.rev_2},
"Modify first version"); "Modify document in 2nd tab");
o.jio.put(o.doc_2, o.f); o.jio2.put(o.doc_2, o.f);
o.tick(o);
// 6. GET second version
o.mydocSample2 = {"_id": "sample1", "title": "mySample2", "_rev": o.rev_f};
o.mydocSample2._revisions = {"start":1 , "ids":[o.hex_f]};
o.mydocSample2._revs_info = [{"rev": o.rev_f, "status": "available"}];
o.mydocSample2._conflicts = [o.rev_2];
o.spy(o, "value", o.mydocSample2,
"Get second version");
o.jio.get("sample1", {
"revs_info": true, "revs": true, "conflicts": true,
"rev": o.rev_f }, o.f);
o.tick(o); o.tick(o);
// 7. MODFIY second version // 8. MODFIY first version
o.doc_f2 = {"_id": "sample1", "_rev": o.rev_f, o.doc_1 = {"_id": "sample1", "_rev": o.rev,
"title":"mySample2_modified"}; "title": "mySample1_modified"};
o.revisions_f2 = {"start":1 , "ids":[o.hex_f]}; o.revisions_1 = {"start": 1, "ids":[o.rev.split('-')[1]
o.hex_f2 = generateRevisionHash(o.doc_f2, o.revisions_f2) ]};
o.rev_f2 = "2-"+o.hex_f2; o.hex_1 = generateRevisionHash(o.doc_1, o.revisions_1);
o.spy (o, "value", {"id":"sample1", "ok":true, "rev": o.rev_f2}, o.rev_1 = "2-"+o.hex_1;
"Modify second document"); o.spy (o, "value", {"id":"sample1", "ok":true, "rev": o.rev_1},
o.jio.put(o.doc_f2, o.f); "Modify document in first tab");
o.jio.put(o.doc_1, o.f);
o.tick(o); o.tick(o);
// 8. GET document without revision = winner & conflict! // 9. Close 2nd tab
o.jio2.close();
ok ( o.jio2, "Close 2nd tab (close jio2)");
// 10. Close 1st tab
o.jio.close();
ok ( o.jio, "Close 1st tab (close jio1)");
// 11 Reopen JIO
o.jio = JIO.newJio({
"type": "revision",
"secondstorage": {
"type": "local",
"username": "usam1",
"applicationname": "asam1"
}
});
o.localpath = "jio/localstorage/usam1/asam1";
ok ( o.jio, "Reopen application");
// 12. GET document without revision = winner & conflict!
o.mydocSample3 = {"_id": "sample1", "title": "mySample1_modified", o.mydocSample3 = {"_id": "sample1", "title": "mySample1_modified",
"_rev": o.rev_2,"_conflicts":[o.rev_f2]}; "_rev": o.rev_1};
o.mydocSample3._revs_info = [{"rev": o.rev_2, "status": "available"},{ o.mydocSample3._conflicts = [o.rev_2]
o.mydocSample3._revs_info = [{"rev": o.rev_1, "status": "available"},{
"rev":o.rev,"status":"available" "rev":o.rev,"status":"available"
}]; }];
o.mydocSample3._revisions = {"ids":[o.hex_2, o.hex], "start":2 }; o.mydocSample3._revisions = {"ids":[o.hex_1, o.hex], "start":2 };
o.spy(o, "value", o.mydocSample3, o.spy(o, "value", o.mydocSample3,
"Get Document = Two conflicting versions = conflict"); "Get Document = Two conflicting versions");
o.jio.get("sample1", {"revs_info": true, "revs": true, "conflicts": true, o.jio.get("sample1", {"revs_info": true, "revs": true, "conflicts": true,
}, o.f); }, o.f);
o.tick(o); o.tick(o);
// 13. REMOVE one of the two conflicting versions
o.revisions = {"start": 1, "ids":[o.rev.split('-')[1]]};
o.doc_myremove4 = {"ok": true, "id": "sample1", "rev": o.rev_1};
o.rev_3 = "3-"+generateRevisionHash(o.doc_myremove4, o.revisions);
o.spy (o, "value", {"ok": true, "id": "sample1", "rev": o.rev_3},
"Remove one of the conflicting document version");
o.jio.remove({"_id":"sample1", "_rev":o.rev_2}, o.f);
o.tick(o);
// 14. END
o.jio.stop(); o.jio.stop();
ok ( o.jio, "Close application");
}); });
/* /*
......
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