|
|
|
@ -1172,7 +1172,7 @@ describe('Model', function () { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('Logical operator $where', function () { |
|
|
|
|
describe('Comparison operator $where', function () { |
|
|
|
|
|
|
|
|
|
it('Function should match and not match correctly', function () { |
|
|
|
|
model.match({ a: 4}, { $where: function () { return this.a === 4; } }).should.equal(true); |
|
|
|
@ -1187,6 +1187,18 @@ describe('Model', function () { |
|
|
|
|
(function () { model.match({ a: 4 }, { $where: function () { return 'not a boolean'; } }); }).should.throw(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Should be able to do the complex matching it must be used for', function () { |
|
|
|
|
var checkEmail = function() { |
|
|
|
|
if (!this.firstName || !this.lastName) { return false; } |
|
|
|
|
return this.firstName.toLowerCase() + "." + this.lastName.toLowerCase() + "@gmail.com" === this.email; |
|
|
|
|
}; |
|
|
|
|
model.match({ firstName: "John", lastName: "Doe", email: "john.doe@gmail.com" }, { $where: checkEmail }).should.equal(true); |
|
|
|
|
model.match({ firstName: "john", lastName: "doe", email: "john.doe@gmail.com" }, { $where: checkEmail }).should.equal(true); |
|
|
|
|
model.match({ firstName: "Jane", lastName: "Doe", email: "john.doe@gmail.com" }, { $where: checkEmail }).should.equal(false); |
|
|
|
|
model.match({ firstName: "John", lastName: "Deere", email: "john.doe@gmail.com" }, { $where: checkEmail }).should.equal(false); |
|
|
|
|
model.match({ lastName: "Doe", email: "john.doe@gmail.com" }, { $where: checkEmail }).should.equal(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|