From 9fd3865f326384bb1aa4ed39704f5992d3393798 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 20 Feb 2015 21:44:49 -0800 Subject: [PATCH] Make sure models are migrated to avoid conflicts --- test/manipulation.test.js | 125 +++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 42 deletions(-) diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 3530d11e..1864dbfc 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -447,68 +447,109 @@ describe('manipulation', function () { person.isNewRecord().should.be.true; }); - it('should report current date when using $now as default value for date property', - function (done) { - var CustomModel = db.define('CustomModel', { + describe('Date $now function', function() { + var CustomModel; + + before(function(done) { + CustomModel = db.define('CustomModel1', { createdAt: { type: Date, default: '$now' } }); + db.automigrate('CustomModel1', done); + }); - var now = Date.now(); + it('should report current date as default value for date property', + function(done) { + var now = Date.now(); - var myCustomModel = CustomModel.create(function (err, m) { - m.createdAt.should.be.instanceOf(Date); - (m.createdAt >= now).should.be.true; + var myCustomModel = CustomModel.create(function(err, m) { + should.not.exists(err); + m.createdAt.should.be.instanceOf(Date); + (m.createdAt >= now).should.be.true; + }); + + done(); }); - - done(); }); - it('should report \'$now\' when using $now as default value for string property', - function (done) { - var CustomModel = db.define('CustomModel', { + describe('Date $now function', function() { + var CustomModel; + + before(function(done) { + CustomModel = db.define('CustomModel2', { now: { type: String, default: '$now' } }); + db.automigrate('CustomModel2', done); + }); - var myCustomModel = CustomModel.create(function (err, m) { - m.now.should.be.instanceOf(String); - m.now.should.equal('$now'); + it('should report \'$now\' as default value for string property', + function(done) { + var myCustomModel = CustomModel.create(function(err, m) { + should.not.exists(err); + m.now.should.be.instanceOf(String); + m.now.should.equal('$now'); + }); + + done(); }); - - done(); }); - it('should generate a new id when "defaultFn" is "guid"', function (done) { - var CustomModel = db.define('CustomModel', { - guid: { type: String, defaultFn: 'guid' } + describe('now defaultFn', function() { + var CustomModel; + + before(function(done) { + CustomModel = db.define('CustomModel3', { + now: { type: Date, defaultFn: 'now' } + }); + db.automigrate('CustomModel3', done); }); - var inst = CustomModel.create(function (err, m) { - m.guid.should.match(UUID_REGEXP); - done(); + it('should generate current time when "defaultFn" is "now"', + function(done) { + var now = Date.now(); + var inst = CustomModel.create(function(err, m) { + should.not.exists(err); + m.now.should.be.instanceOf(Date); + m.now.should.be.within(now, now + 200); + done(); + }); + }); + }); + + describe('guid defaultFn', function() { + var CustomModel; + + before(function(done) { + CustomModel = db.define('CustomModel4', { + guid: { type: String, defaultFn: 'guid' } + }); + db.automigrate('CustomModel4', done); + }); + + it('should generate a new id when "defaultFn" is "guid"', function(done) { + var inst = CustomModel.create(function(err, m) { + should.not.exists(err); + m.guid.should.match(UUID_REGEXP); + done(); + }); }); }); - it('should generate a new id when "defaultfn" is "uuid"', function (done) { - var CustomModel = db.define('custommodel', { - guid: { type: String, defaultFn: 'uuid' } + describe('uuid defaultFn', function() { + var CustomModel; + + before(function(done) { + CustomModel = db.define('CustomModel5', { + guid: { type: String, defaultFn: 'uuid' } + }); + db.automigrate('CustomModel5', done); }); - var inst = CustomModel.create(function (err, m) { - m.guid.should.match(UUID_REGEXP); - done(); - }); - }); - - it('should generate current time when "defaultFn" is "now"', function (done) { - var CustomModel = db.define('CustomModel', { - now: { type: Date, defaultFn: 'now' } - }); - - var now = Date.now(); - var inst = CustomModel.create(function (err, m) { - m.now.should.be.instanceOf(Date); - m.now.should.be.within(now, now + 200); - done(); + it('should generate a new id when "defaultfn" is "uuid"', function(done) { + var inst = CustomModel.create(function(err, m) { + should.not.exists(err); + m.guid.should.match(UUID_REGEXP); + done(); + }); }); });