Commit 4ac3936c authored by Tristan Cavelier's avatar Tristan Cavelier

Fix bug: no conflict object was returned from Conflict Manager allDocs method.

parent 6c2edc36
/*! JIO Storage - v0.1.0 - 2012-08-14 /*! JIO Storage - v0.1.0 - 2012-08-16
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
(function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) { (function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) {
...@@ -1862,7 +1862,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1862,7 +1862,7 @@ var newConflictManagerStorage = function ( spec, my ) {
that.allDocs = function (command) { that.allDocs = function (command) {
var o = {}, am = priv.newAsyncModule(), var o = {}, am = priv.newAsyncModule(),
metadata_only = command.getOption('metadata_only'), metadata_only = command.getOption('metadata_only'),
result_list = [], result_list = [], conflict_object = {total_rows:0,rows:[]},
nb_loaded_file = 0, nb_loaded_file = 0,
success_count = 0, success_max = 0; success_count = 0, success_max = 0;
o.retreiveList = function () { o.retreiveList = function () {
...@@ -1898,8 +1898,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1898,8 +1898,7 @@ var newConflictManagerStorage = function ( spec, my ) {
var revision = priv.chooseARevision(data); var revision = priv.chooseARevision(data);
if (!data[revision]._deleted) { if (!data[revision]._deleted) {
am.call( am.call(
o,'loadFile', o,'loadFile',[path,revision,data]
[path,revision,data]
); );
} else { } else {
am.call(o,'success'); am.call(o,'success');
...@@ -1917,15 +1916,18 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1917,15 +1916,18 @@ var newConflictManagerStorage = function ( spec, my ) {
_rev:revision _rev:revision
} }
}; };
if (command.getOption('revs')) {
doc.value._revisions = priv._revs(data,revision);
}
if (command.getOption('revs_info')) { if (command.getOption('revs_info')) {
doc.value._revs_info = priv._revs_info(data,revision); doc.value._revs_info = priv._revs_info(data,revision);
} }
if (command.getOption('conflicts')) { if (command.getOption('conflicts')) {
if (data[revision]._conflict) { if (data[revision]._conflict) {
doc.value._conflicts = priv.createConflictObject( conflict_object.total_rows ++;
command, data, revision ); conflict_object.rows.push(priv.createConflictRow(
} else { command, path, data, revision
doc.value._conflicts = {total_rows:0,rows:[]}; ));
} }
} }
if (!metadata_only) { if (!metadata_only) {
...@@ -1944,10 +1946,15 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1944,10 +1946,15 @@ var newConflictManagerStorage = function ( spec, my ) {
} }
}; };
o.success = function (){ o.success = function (){
var obj;
success_count ++; success_count ++;
if (success_count >= success_max) { if (success_count >= success_max) {
am.end(); am.end();
that.success({total_rows:result_list.length,rows:result_list}); obj = {total_rows:result_list.length,rows:result_list};
if (command.getOption('conflicts')) {
obj.conflicts = conflict_object;
}
that.success(obj);
} }
}; };
o.error = function (error){ o.error = function (error){
......
This diff is collapsed.
...@@ -638,7 +638,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -638,7 +638,7 @@ var newConflictManagerStorage = function ( spec, my ) {
that.allDocs = function (command) { that.allDocs = function (command) {
var o = {}, am = priv.newAsyncModule(), var o = {}, am = priv.newAsyncModule(),
metadata_only = command.getOption('metadata_only'), metadata_only = command.getOption('metadata_only'),
result_list = [], result_list = [], conflict_object = {total_rows:0,rows:[]},
nb_loaded_file = 0, nb_loaded_file = 0,
success_count = 0, success_max = 0; success_count = 0, success_max = 0;
o.retreiveList = function () { o.retreiveList = function () {
...@@ -674,8 +674,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -674,8 +674,7 @@ var newConflictManagerStorage = function ( spec, my ) {
var revision = priv.chooseARevision(data); var revision = priv.chooseARevision(data);
if (!data[revision]._deleted) { if (!data[revision]._deleted) {
am.call( am.call(
o,'loadFile', o,'loadFile',[path,revision,data]
[path,revision,data]
); );
} else { } else {
am.call(o,'success'); am.call(o,'success');
...@@ -693,15 +692,18 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -693,15 +692,18 @@ var newConflictManagerStorage = function ( spec, my ) {
_rev:revision _rev:revision
} }
}; };
if (command.getOption('revs')) {
doc.value._revisions = priv._revs(data,revision);
}
if (command.getOption('revs_info')) { if (command.getOption('revs_info')) {
doc.value._revs_info = priv._revs_info(data,revision); doc.value._revs_info = priv._revs_info(data,revision);
} }
if (command.getOption('conflicts')) { if (command.getOption('conflicts')) {
if (data[revision]._conflict) { if (data[revision]._conflict) {
doc.value._conflicts = priv.createConflictObject( conflict_object.total_rows ++;
command, data, revision ); conflict_object.rows.push(priv.createConflictRow(
} else { command, path, data, revision
doc.value._conflicts = {total_rows:0,rows:[]}; ));
} }
} }
if (!metadata_only) { if (!metadata_only) {
...@@ -720,10 +722,15 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -720,10 +722,15 @@ var newConflictManagerStorage = function ( spec, my ) {
} }
}; };
o.success = function (){ o.success = function (){
var obj;
success_count ++; success_count ++;
if (success_count >= success_max) { if (success_count >= success_max) {
am.end(); am.end();
that.success({total_rows:result_list.length,rows:result_list}); obj = {total_rows:result_list.length,rows:result_list};
if (command.getOption('conflicts')) {
obj.conflicts = conflict_object;
}
that.success(obj);
} }
}; };
o.error = function (error){ o.error = function (error){
......
...@@ -151,7 +151,8 @@ makeRevsAccordingToRevsInfo = function (revs,revs_info) { ...@@ -151,7 +151,8 @@ makeRevsAccordingToRevsInfo = function (revs,revs_info) {
}, },
checkRev = function (rev) { checkRev = function (rev) {
if (typeof rev === 'string') { if (typeof rev === 'string') {
if (parseInt(rev.split('-')[0],10) > 0) { if (rev.split('-').length > 1 &&
parseInt(rev.split('-')[0],10) > 0) {
return rev; return rev;
} }
} }
...@@ -2081,6 +2082,120 @@ test ('Load Revisions', function () { ...@@ -2081,6 +2082,120 @@ test ('Load Revisions', function () {
o.jio.stop(); o.jio.stop();
}); });
test ('Get revision List', function () {
var o = {}; o.clock = this.sandbox.useFakeTimers(); o.t = this;
o.clock.tick (base_tick);
o.spy = basic_spy_function;
o.tick = basic_tick_function;
o.secondstorage_spec = {type:'local',
username:'getrevisionlist',
applicationname:'jiotests'}
o.rev = {};
//////////////////////////////////////////////////////////////////////
o.jio = JIO.newJio({type:'conflictmanager',
storage:o.secondstorage_spec});
o.spy(o,'value',{total_rows:0,rows:[]},'Get revision list');
o.jio.allDocs(o.f);
o.tick(o);
o.spy(o,'value',{total_rows:0,rows:[],conflicts:{total_rows:0,rows:[]}},
'Get revision list with informations');
o.jio.allDocs({conflicts:true,revs:true,info_revs:true},o.f);
o.tick(o);
o.spy(o,'jobstatus','done','saving file');
o.jio.put({_id:'file',content:'content file'},function (err,val) {
o.rev.file1 = val?val.rev:undefined;
o.f(err,val);
});
o.tick(o);
o.spy(o,'jobstatus','done','saving memo');
o.jio.put({_id:'memo',content:'content memo'},function (err,val) {
o.rev.memo1 = val?val.rev:undefined;
o.f(err,val);
});
o.tick(o);
o.spy(o,'status',409,'saving memo conflict');
o.jio.put({_id:'memo',content:'content memo'},function (err,val) {
o.rev.memo2 = err?err.rev:undefined;
o.f(err,val);
});
o.tick(o);
o.f = o.t.spy();
o.jio.allDocs(function (err,val) {
var i;
if (val) {
for (i = 0; i < val.total_rows; i+= 1) {
val.rows[i].value._creation_date =
val.rows[i].value._creation_date?true:undefined;
val.rows[i].value._last_modified =
val.rows[i].value._last_modified?true:undefined;
o.rev[i] = checkRev (val.rows[i].value._rev);
}
}
deepEqual(err||val,{total_rows:2,rows:[{
id:'file',key:'file',value:{
_creation_date:true,_last_modified:true,_rev:o.rev[0]
}
},{
id:'memo',key:'memo',value:{
_creation_date:true,_last_modified:true,_rev:o.rev[1]
}
}]},'Get revision list after adding 2 files');
o.f();
});
o.tick(o);
o.f = o.t.spy();
o.jio.allDocs(
{conflicts:true,revs:true,revs_info:true},
function (err,val) {
var i;
if (val) {
for (i = 0; i < val.total_rows; i+= 1) {
val.rows[i].value._creation_date =
val.rows[i].value._creation_date?true:undefined;
val.rows[i].value._last_modified =
val.rows[i].value._last_modified?true:undefined;
if (val.conflicts && val.conflicts.rows) {
o.solveConflict =
checkConflictRow (val.conflicts.rows[0]);
}
}
}
deepEqual(err||val,{
total_rows:2,rows:[{
id:'file',key:'file',value:{
_creation_date:true,_last_modified:true,
_revisions:{start:1,ids:[getHashFromRev(o.rev.file1)]},
_rev:o.rev.file1,_revs_info:[{
rev:o.rev.file1,status:'available'
}]
}
},{
id:'memo',key:'memo',value:{
_creation_date:true,_last_modified:true,
_revisions:{start:1,ids:[getHashFromRev(o.rev.memo2)]},
_rev:o.rev.memo2,_revs_info:[{
rev:o.rev.memo1,status:'available'
},{
rev:o.rev.memo2,status:'available'
}]
}
}],
conflicts:{total_rows:1,rows:[{
id:'memo',key:[o.rev.memo1,o.rev.memo2],
value:{_solveConflict:'function'}
}]}
},'Get revision list with informations after adding 2 files');
o.f();
});
o.tick(o);
o.jio.stop();
});
}; // end thisfun }; // end thisfun
if (window.requirejs) { if (window.requirejs) {
......
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