Skip to content

Commit

Permalink
Merge pull request #10 from Avocarrot/feature/booleanTypes
Browse files Browse the repository at this point in the history
feat(booleans) Adds support for boolean types
  • Loading branch information
giorgosera committed Nov 15, 2015
2 parents dec8ca9 + 0f36bbc commit 9ce9303
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var ValidationError = require('./errors/ValidationError');
var _ = require('./utils');


var supportedTypes = ['String', 'Number', 'Object', 'Array'];
var supportedTypes = ['String', 'Number', 'Object', 'Array', 'Boolean'];
var reservedKeys = ['type', 'default', 'required', 'of'];

var isNotReserved = function(key) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stormer",
"version": "0.4.0",
"version": "0.5.0",
"description": "The flexible Node.js ORM",
"main": "index.js",
"directories": {
Expand Down
35 changes: 35 additions & 0 deletions test/schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ describe('Schema Tests', function() {
schema.should.have.deep.property('schema.nestedObject.nestedOfNumbers.of');
});

it('parse schemas with boolean types', function() {

var schemaDef = {
simpleBoolean: 'Boolean',
complexBoolean: {
type: 'Boolean',
default: true
}
};

var schema = new Schema(schemaDef);

schema.should.have.deep.property('schema.simpleBoolean.type', 'Boolean');
schema.should.have.deep.property('schema.simpleBoolean.path', '.simpleBoolean');

schema.should.have.deep.property('schema.complexBoolean.type', 'Boolean');
schema.should.have.deep.property('schema.complexBoolean.path', '.complexBoolean');
schema.should.have.deep.property('schema.complexBoolean.default', true);

});

});

describe('Schema.prototype.create() should', function() {
Expand Down Expand Up @@ -149,6 +170,20 @@ describe('Schema Tests', function() {
this.schema = new Schema(schemaDef);
});

it('return an error if a boolean property has the wrong type', function(done) {
var schemaDef = {
bool: 'Boolean'
};

var schema = new Schema(schemaDef);
schema.create({
bool: 'this should be a boolean'
}).catch(function(err) {
err.message.should.equal('Property .bool should be of type Boolean');
done();
});
});

it('return an error if a simple property has the wrong type', function(done) {
this.schema.create({
simpleField: 'this should be a number'
Expand Down

0 comments on commit 9ce9303

Please sign in to comment.