Added operator

pull/2/head
Louis Chatriot 12 years ago
parent c4141ab945
commit a70f4babac
  1. 9
      lib/model.js
  2. 8
      test/model.test.js

@ -303,7 +303,9 @@ function areComparable (a, b) {
/**
* Arithmetic comparators
* Arithmetic and comparison operators
* @param {Native value} a Value in the object
* @param {Native value} b Value in the query
*/
comparisonFunctions.$lt = function (a, b) {
return areComparable(a, b) && a < b;
@ -321,6 +323,11 @@ comparisonFunctions.$gte = function (a, b) {
return areComparable(a, b) && a >= b;
};
comparisonFunctions.$ne = function (a, b) {
if (!a) { return true; }
return !areThingsEqual(a, b);
};
/**
* Match any of the subqueries

@ -459,7 +459,7 @@ describe('Model', function () {
// General behaviour is tested in the block about $lt. Here we just test operators work
describe('Other comparison operators: $lte, $gt, $gte', function () {
describe('Other comparison operators: $lte, $gt, $gte, $ne', function () {
it('$lte', function () {
model.match({ a: 5 }, { a: { $lte: 6 } }).should.equal(true);
@ -479,6 +479,12 @@ describe('Model', function () {
model.match({ a: 5 }, { a: { $gte: 4 } }).should.equal(true);
});
it('$ne', function () {
model.match({ a: 5 }, { a: { $ne: 4 } }).should.equal(true);
model.match({ a: 5 }, { a: { $ne: 5 } }).should.equal(false);
model.match({ a: 5 }, { b: { $ne: 5 } }).should.equal(true);
});
});

Loading…
Cancel
Save