From 14b4c245bf3778b7871d3a6d70ddeb14493660ef Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Thu, 30 May 2013 16:13:14 +0200 Subject: [PATCH] Insertion still works as before with indexing --- test/db.test.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/db.test.js b/test/db.test.js index b57cf68..221eec6 100644 --- a/test/db.test.js +++ b/test/db.test.js @@ -1109,7 +1109,7 @@ describe('Database', function () { }); // ==== End of 'Remove' ==== // - describe('Using indexes', function () { + describe.only('Using indexes', function () { describe('ensureIndex and index initialization in database loading', function () { @@ -1416,15 +1416,31 @@ describe('Database', function () { }); }); - it.skip('Insertion still works as before with indexing', function (done) { + it('Insertion still works as before with indexing', function (done) { d.ensureIndex({ fieldName: 'a' }); d.ensureIndex({ fieldName: 'b' }); d.insert({ a: 1, b: 'hello' }, function (err, doc1) { d.insert({ a: 2, b: 'si' }, function (err, doc2) { d.find({}, function (err, docs) { - console.log(d.data); -// TODO + assert.deepEqual(doc1, _.find(docs, function (d) { return d._id === doc1._id; })); + assert.deepEqual(doc2, _.find(docs, function (d) { return d._id === doc2._id; })); + + done(); + }); + }); + }); + }); + + it('The index data points to the db data', function (done) { + d.ensureIndex({ fieldName: 'a' }); + + d.insert({ a: 1, b: 'hello' }, function (err, doc1) { + d.insert({ a: 2, b: 'si' }, function (err, doc2) { + d.find({}, function (err, docs) { + d.data.indexOf(d.indexes.a.getMatching(1)[0]).should.not.equal(-1); + d.data.indexOf(d.indexes.a.getMatching(2)[0]).should.not.equal(-1); + done(); }); });