Skip to content

Commit

Permalink
Added plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 11, 2013
1 parent f9abc82 commit 48bcbb6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/plugins.js
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();
});
});
});
});

0 comments on commit 48bcbb6

Please sign in to comment.