Updated browser tests

pull/2/head
Louis Chatriot 9 years ago
parent 08f37b9cc2
commit cadf4ef434
  1. 3
      browser-version/out/nedb.js
  2. 7
      browser-version/test/nedb-browser.js
  3. 3
      lib/datastore.js

@ -1315,7 +1315,7 @@ Datastore.prototype.updateIndexes = function (oldDoc, newDoc) {
* *
* @param {Query} query * @param {Query} query
* @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations * @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations
* @param {Function} callback Signature err, docs * @param {Function} callback Signature err, candidates
*/ */
Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) { Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) {
var indexNames = Object.keys(this.indexes) var indexNames = Object.keys(this.indexes)
@ -1327,6 +1327,7 @@ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callba
dontExpireStaleDocs = false; dontExpireStaleDocs = false;
} }
async.waterfall([ async.waterfall([
// STEP 1: get candidates list by checking indexes from most to least frequent usecase // STEP 1: get candidates list by checking indexes from most to least frequent usecase
function (cb) { function (cb) {

@ -254,7 +254,8 @@ describe('Indexing', function () {
db.insert({ a: 4 }, function () { db.insert({ a: 4 }, function () {
db.insert({ a: 6 }, function () { db.insert({ a: 6 }, function () {
db.insert({ a: 7 }, function () { db.insert({ a: 7 }, function () {
var candidates = db.getCandidates({ a: 6 }) db.getCandidates({ a: 6 }, function (err, candidates) {
console.log(candidates);
assert.equal(candidates.length, 3); assert.equal(candidates.length, 3);
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; })); assert.isDefined(_.find(candidates, function (doc) { return doc.a === 4; }));
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; }));
@ -262,7 +263,7 @@ describe('Indexing', function () {
db.ensureIndex({ fieldName: 'a' }); db.ensureIndex({ fieldName: 'a' });
candidates = db.getCandidates({ a: 6 }) db.getCandidates({ a: 6 }, function (err, candidates) {
assert.equal(candidates.length, 1); assert.equal(candidates.length, 1);
assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; })); assert.isDefined(_.find(candidates, function (doc) { return doc.a === 6; }));
@ -271,6 +272,8 @@ describe('Indexing', function () {
}); });
}); });
}); });
});
});
it('Can use indexes to enforce a unique constraint', function (done) { it('Can use indexes to enforce a unique constraint', function (done) {
var db = new Nedb(); var db = new Nedb();

@ -250,7 +250,7 @@ Datastore.prototype.updateIndexes = function (oldDoc, newDoc) {
* *
* @param {Query} query * @param {Query} query
* @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations * @param {Boolean} dontExpireStaleDocs Optional, defaults to false, if true don't remove stale docs. Useful for the remove function which shouldn't be impacted by expirations
* @param {Function} callback Signature err, docs * @param {Function} callback Signature err, candidates
*/ */
Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) { Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callback) {
var indexNames = Object.keys(this.indexes) var indexNames = Object.keys(this.indexes)
@ -262,6 +262,7 @@ Datastore.prototype.getCandidates = function (query, dontExpireStaleDocs, callba
dontExpireStaleDocs = false; dontExpireStaleDocs = false;
} }
async.waterfall([ async.waterfall([
// STEP 1: get candidates list by checking indexes from most to least frequent usecase // STEP 1: get candidates list by checking indexes from most to least frequent usecase
function (cb) { function (cb) {

Loading…
Cancel
Save