Handles removes in the good cases

pull/2/head
Louis Chatriot 11 years ago
parent db1cc10202
commit f48a1565bc
  1. 6
      lib/indexes.js
  2. 19
      test/indexes.test.js

@ -125,7 +125,13 @@ Index.prototype.remove = function (doc) {
if (key === undefined && this.sparse) { return; }
if (!util.isArray(key)) {
this.tree.delete(key, doc);
} else {
_.uniq(key, projectForUnique).forEach(function (_key) {
self.tree.delete(_key, doc);
});
}
};

@ -177,6 +177,25 @@ describe('Indexes', function () {
(function () { idx.insert(obj2); }).should.throw();
});
it('When removing a document, remove it from the index at all array elements', function () {
var obj = { tf: ['aa', 'aa'], really: 'yeah' }
, obj2 = { tf: ['cc', 'aa', 'cc'], yes: 'indeed' }
, idx = new Index({ fieldName: 'tf' })
;
idx.insert(obj);
idx.insert(obj2);
idx.getMatching('aa').length.should.equal(2);
idx.getMatching('aa').indexOf(obj).should.not.equal(-1);
idx.getMatching('aa').indexOf(obj2).should.not.equal(-1);
idx.getMatching('cc').length.should.equal(1);
idx.remove(obj2);
idx.getMatching('aa').length.should.equal(1);
idx.getMatching('aa').indexOf(obj).should.not.equal(-1);
idx.getMatching('aa').indexOf(obj2).should.equal(-1);
idx.getMatching('cc').length.should.equal(0);
});
}); // ==== End of 'Array fields' ==== //

Loading…
Cancel
Save