-
Notifications
You must be signed in to change notification settings - Fork 27
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
f9abc82
commit 48bcbb6
Showing
1 changed file
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var Database = require('../index.js'); | ||
var Model = Database.Model; | ||
var Instance = Database.Instance; | ||
var should = require('should'); | ||
|
||
describe('plugins', function() { | ||
describe('custom validation', function() { | ||
var plugin = { | ||
validate: function(schema, value) { | ||
if(schema == 'Positive') | ||
return this.assert(value >= 0, 'positive number'); | ||
} | ||
}; | ||
|
||
it('should correctly validate models upon creation', function(done) { | ||
var model = new Model({ | ||
plugins: [plugin], | ||
db: { | ||
collection: function() { return null; } | ||
} | ||
}, 'collection', | ||
{ name: String, age: 'Positive' }, | ||
{}); | ||
|
||
model.insert({ | ||
name: 'test', age: -1 | ||
}, function(err, instance) { | ||
should.exist(err); | ||
should.not.exist(instance); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |