forked from louischatriot/nedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81a4025
commit cf43ec1
Showing
2 changed files
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -1186,6 +1186,18 @@ describe('Model', function () { | |
it('Should throw an error if the $where function returns a non-boolean', 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: "[email protected]" }, { $where: checkEmail }).should.equal(true); | ||
model.match({ firstName: "john", lastName: "doe", email: "[email protected]" }, { $where: checkEmail }).should.equal(true); | ||
model.match({ firstName: "Jane", lastName: "Doe", email: "[email protected]" }, { $where: checkEmail }).should.equal(false); | ||
model.match({ firstName: "John", lastName: "Deere", email: "[email protected]" }, { $where: checkEmail }).should.equal(false); | ||
model.match({ lastName: "Doe", email: "[email protected]" }, { $where: checkEmail }).should.equal(false); | ||
}); | ||
|
||
}); | ||
|
||
|