2013-04-06 10:57:12 +00:00
|
|
|
// This test written in mocha+should.js
|
|
|
|
var should = require('./init.js');
|
|
|
|
|
2013-03-26 00:41:00 +00:00
|
|
|
var db = getSchema();
|
2013-03-24 13:37:13 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
describe('defaults', function () {
|
|
|
|
var Server;
|
2013-03-24 13:37:13 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
before(function () {
|
|
|
|
Server = db.define('Server', {
|
|
|
|
host: String,
|
|
|
|
port: {type: Number, default: 80}
|
2013-03-24 13:37:13 +00:00
|
|
|
});
|
2014-01-24 17:09:53 +00:00
|
|
|
});
|
2013-03-24 13:37:13 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
it('should apply defaults on new', function () {
|
|
|
|
var s = new Server;
|
|
|
|
s.port.should.equal(80);
|
|
|
|
});
|
2013-03-24 13:37:13 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
it('should apply defaults on create', function (done) {
|
|
|
|
Server.create(function (err, s) {
|
|
|
|
s.port.should.equal(80);
|
|
|
|
done();
|
2013-03-24 13:37:13 +00:00
|
|
|
});
|
2014-01-24 17:09:53 +00:00
|
|
|
});
|
2013-03-24 13:37:13 +00:00
|
|
|
|
2014-01-24 17:09:53 +00:00
|
|
|
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();
|
2013-03-24 13:37:13 +00:00
|
|
|
});
|
2014-01-24 17:09:53 +00:00
|
|
|
});
|
2014-10-19 16:47:27 +00:00
|
|
|
|
|
|
|
it('should ignore defaults with limited fields', function (done) {
|
|
|
|
Server.create({ host: 'localhost', port: 8080 }, function(err, s) {
|
|
|
|
should.not.exist(err);
|
|
|
|
s.port.should.equal(8080);
|
|
|
|
Server.find({ fields: ['host'] }, function (err, servers) {
|
|
|
|
servers[0].host.should.equal('localhost');
|
|
|
|
servers[0].should.have.property('host');
|
|
|
|
servers[0].should.not.have.property('port');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-03-24 13:37:13 +00:00
|
|
|
});
|