Stashing tests on

pull/2/head
Louis Chatriot 11 years ago
parent 7ea00ef9cb
commit 4ff94fa1bf
  1. 2
      lib/model.js
  2. 55
      test/model.test.js
  3. 2
      test/persistence.test.js

@ -575,7 +575,7 @@ comparisonFunctions.$exists = function (value, exists) {
}; };
queryOperatorArray.$size = function (obj, value) { queryOperatorArray.$size = function (obj, value) {
if (!util.isArray(obj)) { throw "$size operator not being applied to an array"; } if (!util.isArray(obj)) { return false; }
if (value % 1 !== 0) { throw "$size operator called without an integer"; } if (value % 1 !== 0) { throw "$size operator called without an integer"; }
return (obj.length == value); return (obj.length == value);

@ -1038,6 +1038,36 @@ describe('Model', function () {
}); });
describe('Query operator array $size', function () {
it('Can query on the size of an array field', function () {
// Non nested documents
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 0 } }).should.equal(false);
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 2 } }).should.equal(false);
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 3 } }).should.equal(true);
// Nested documents
model.match({ hello: 'world', description: { satellites: ['Moon', 'Hubble'], diameter: 6300 } }, { "description.satellites": { $size: 0 } }).should.equal(false);
model.match({ hello: 'world', description: { satellites: ['Moon', 'Hubble'], diameter: 6300 } }, { "description.satellites": { $size: 1 } }).should.equal(false);
model.match({ hello: 'world', description: { satellites: ['Moon', 'Hubble'], diameter: 6300 } }, { "description.satellites": { $size: 2 } }).should.equal(true);
model.match({ hello: 'world', description: { satellites: ['Moon', 'Hubble'], diameter: 6300 } }, { "description.satellites": { $size: 3 } }).should.equal(false);
});
it('$size operator works with empty arrays', function () {
model.match({ childrens: [] }, { "childrens": { $size: 0 } }).should.equal(true);
model.match({ childrens: [] }, { "childrens": { $size: 2 } }).should.equal(false);
model.match({ childrens: [] }, { "childrens": { $size: 3 } }).should.equal(false);
});
it.only('Should throw an error if a query operator is used without being applied to an array and comparing to an integer', function () {
model.match({ a: 5 }, { a: { $size: 1 } });
(function () { model.match({ a: [1, 5] }, { a: { $size: 1.4 } }); }).should.throw();
(function () { model.match({ a: [1, 5] }, { a: { $size: 'fdf' } }); }).should.throw();
});
});
describe('Logical operators $or, $and, $not', function () { describe('Logical operators $or, $and, $not', function () {
it('Any of the subqueries should match for an $or to match', function () { it('Any of the subqueries should match for an $or to match', function () {
@ -1079,30 +1109,7 @@ describe('Model', function () {
}); });
describe('Query operator array $size', function () { describe('Array fields', function () {
it('$size', function () {
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 0 } }).should.equal(false);
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 2 } }).should.equal(false);
model.match({ childrens: [ { name: "Huey", age: 3 }, { name: "Dewey", age: 7 }, { name: "Louie", age: 12 } ] }, { "childrens": { $size: 3 } }).should.equal(true);
});
it('$size operator works with empty arrays', function () {
model.match({ childrens: [ ] }, { "childrens": { $size: 0 } }).should.equal(true);
model.match({ childrens: [ ] }, { "childrens": { $size: 2 } }).should.equal(false);
model.match({ childrens: [ ] }, { "childrens": { $size: 3 } }).should.equal(false);
});
it('Should throw an error if a query operator is used without being applied to an array and comparing to an integer', function () {
(function () { model.match({ a: 5 }, { a: { $size: 1 } }); }).should.throw();
(function () { model.match({ a: [1, 5] }, { a: { $size: 1.4 } }); }).should.throw();
(function () { model.match({ a: [1, 5] }, { a: { $size: 'fdf' } }); }).should.throw();
});
});
describe('Array fields', function () {
it('Field equality', function () { it('Field equality', function () {
model.match({ tags: ['node', 'js', 'db'] }, { tags: 'python' }).should.equal(false); model.match({ tags: ['node', 'js', 'db'] }, { tags: 'python' }).should.equal(false);

@ -552,7 +552,7 @@ describe('Persistence', function () {
// That depends on the machine and the load on the machine when the tests are run // That depends on the machine and the load on the machine when the tests are run
// It is timed for my machine with nothing else running but may not work as expected on others (it will not fail but may not be a proof) // It is timed for my machine with nothing else running but may not work as expected on others (it will not fail but may not be a proof)
// Every new version of NeDB passes it on my machine before rtelease // Every new version of NeDB passes it on my machine before rtelease
it('If system crashes during a loadDatabase, the former version is not lost', function (done) { it.skip('If system crashes during a loadDatabase, the former version is not lost', function (done) {
var cp, N = 150000, toWrite = "", i; var cp, N = 150000, toWrite = "", i;
// Ensuring the state is clean // Ensuring the state is clean

Loading…
Cancel
Save