diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index 898a4e57..ea9c9d3a 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -406,9 +406,10 @@ function applyFilter(filter) { if (typeof value === 'string' && (example instanceof RegExp)) { return value.match(example); } - if (example === undefined || value === undefined) { + if (example === undefined) { return undefined; } + if (typeof example === 'object') { // ignore geo near filter if (example.near) { @@ -425,6 +426,10 @@ function applyFilter(filter) { return false; } + if ('neq' in example) { + return compare(example.neq, value) !== 0; + } + if (example.like || example.nlike) { var like = example.like || example.nlike; @@ -445,7 +450,8 @@ function applyFilter(filter) { } } // not strict equality - return (example !== null ? example.toString() : example) == (value !== null ? value.toString() : value); + return (example !== null ? example.toString() : example) + == (value != null ? value.toString() : value); } /** diff --git a/test/memory.test.js b/test/memory.test.js index 40283b82..453ac9e8 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -199,6 +199,41 @@ describe('Memory connector', function () { }); }); + it('should support neq operator for number', function (done) { + User.find({where: {order: {neq: 6}}}, function (err, users) { + should.not.exist(err); + users.length.should.be.equal(5); + for (var i = 0; i < users.length; i++) { + users[i].order.should.not.be.equal(6); + } + done(); + }); + }); + + it('should support neq operator for string', function (done) { + User.find({where: {role: {neq: 'lead'}}}, function (err, users) { + should.not.exist(err); + users.length.should.be.equal(4); + for (var i = 0; i < users.length; i++) { + if (users[i].role) { + users[i].role.not.be.equal('lead'); + } + } + done(); + }); + }); + + it('should support neq operator for null', function (done) { + User.find({where: {role: {neq: null}}}, function (err, users) { + should.not.exist(err); + users.length.should.be.equal(2); + for (var i = 0; i < users.length; i++) { + should.exist(users[i].role); + } + done(); + }); + }); + function seed(done) { var beatles = [ {