From c62e7ed641c3801e03d9b78ab44870549d3ac82b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 29 Dec 2014 17:27:42 -0500 Subject: [PATCH] list test fix --- src/database/mongo/list.js | 38 ++++++-------------------------------- tests/database/list.js | 7 ++++--- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/database/mongo/list.js b/src/database/mongo/list.js index fbd8aa3a4a..40e294a488 100644 --- a/src/database/mongo/list.js +++ b/src/database/mongo/list.js @@ -43,7 +43,7 @@ module.exports = function(db, module) { if (!key) { return callback(); } - module.getListRange(key, -1, 0, function(err, value) { + module.getListRange(key, -1, -1, function(err, value) { if (err) { return callback(err); } @@ -86,43 +86,17 @@ module.exports = function(db, module) { if (!key) { return callback(); } - var skip = start, - limit = stop - start + 1, - splice = false; - if((start < 0 && stop >= 0) || (start >= 0 && stop < 0)) { - skip = 0; - limit = Math.pow(2, 31) - 2; - splice = true; - } else if (start > stop) { - return callback(null, []); - } - - db.collection('objects').findOne({_key:key}, { array: { $slice: [skip, limit] }}, function(err, data) { + db.collection('objects').findOne({_key:key}, { array: 1}, function(err, data) { if(err || !(data && data.array)) { return callback(err, []); } - if(splice) { - - if(start < 0) { - start = data.array.length - Math.abs(start); - } - - if(stop < 0) { - stop = data.array.length - Math.abs(stop); - } - - if(start > stop) { - return callback(null, []); - } - - var howMany = stop - start + 1; - if(start !== 0 || howMany !== data.array.length) { - data.array = data.array.splice(start, howMany); - } + if (stop === -1) { + data.array = data.array.slice(start); + } else { + data.array = data.array.slice(start, stop + 1); } - callback(null, data.array); }); }; diff --git a/tests/database/list.js b/tests/database/list.js index 6287ed7265..3d8e243e33 100644 --- a/tests/database/list.js +++ b/tests/database/list.js @@ -83,14 +83,15 @@ describe('List methods', function() { }); describe('listRemoveAll()', function() { - it('should remove all the elements of list', function(done) { - db.listRemoveAll('testList2', function(err) { + it('should remove all the matching elements of list', function(done) { + db.listRemoveAll('testList2', '1', function(err) { assert.equal(err, null, 'db.listRemoveAll error'); assert.equal(arguments.length, 1, 'arguments.length error'); db.getListRange('testList2', 0, -1, function(err, list) { assert.equal(Array.isArray(list), true, 'list is not an array'); - assert.equal(list.length, 0, 'list is not empty'); + assert.equal(list.length, 1, 'element not removed'); + assert.equal(list.indexOf('1'), -1, 'element not removed'); done(); }); });