Defaults test and fixes

When property type is "undefined" - apply default value
This commit is contained in:
Anatoliy Chakkaev 2013-03-24 17:37:13 +04:00
parent ccced1cd57
commit fcc2869806
3 changed files with 41 additions and 1 deletions

View File

@ -4,6 +4,9 @@
test:
@./node_modules/.bin/mocha --require should test/*.test.js
test-verbose:
@./node_modules/.bin/mocha --require should --reporter spec test/*.test.js
MAN_DOCS = $(shell find docs -name '*.md' \
|sed 's|.md|.3|g' \
|sed 's|docs/|docs/man/|g' )

37
test/defaults.test.js Normal file
View File

@ -0,0 +1,37 @@
var Schema = require('../').Schema;
var db = new Schema('memory');
describe('defaults', function() {
var Server;
before(function() {
Server = db.define('Server', {
host: String,
port: {type: Number, default: 80}
});
});
it('should apply defaults on new', function() {
var s = new Server;
s.port.should.equal(80);
});
it('should apply defaults on create', function(done) {
Server.create(function(err, s) {
s.port.should.equal(80);
console.log(s.__data);
done();
});
});
it('should apply defaults on read', function(done) {
db.defineProperty('Server', 'host', {
type: String,
default: 'localhost'
});
Server.all(function (err, servers) {
(new String('localhost')).should.equal(servers[0].host);
done();
});
});
});

View File

@ -8,7 +8,7 @@ describe('JSON property', function() {
schema = new Schema('memory');
Model = schema.define('Model', {propertyName: Schema.JSON});
var m = new Model;
m.should.have.property('propertyName');
(new Boolean('propertyName' in m)).should.eql(true);
should.not.exist(m.propertyName);
});