Optimze automigrate() to cut the test time signicantly

This commit is contained in:
Raymond Feng 2015-08-27 15:59:58 -07:00
parent e2df36c006
commit 682f6340d3
6 changed files with 78 additions and 150 deletions

View File

@ -631,7 +631,7 @@ describe.skip('queries', function() {
}, { }, {
idInjection: false idInjection: false
}); });
db.automigrate(done); db.automigrate(['Todo'], done);
}); });
beforeEach(function resetFixtures(done) { beforeEach(function resetFixtures(done) {
Todo.destroyAll(function() { Todo.destroyAll(function() {

View File

@ -19,7 +19,7 @@ describe('crud-with-options', function () {
options = {}; options = {};
filter = {fields: ['name', 'id']}; filter = {fields: ['name', 'id']};
db.automigrate(done); db.automigrate(['User'], done);
}); });

View File

@ -18,9 +18,7 @@ describe('datatypes', function () {
arr: Array, arr: Array,
nested: Nested nested: Nested
}); });
db.automigrate(function () { db.automigrate(['Model'], done);
Model.destroyAll(done);
});
}); });
it('should return 400 when property of type array is set to string value', it('should return 400 when property of type array is set to string value',
@ -161,7 +159,7 @@ describe('datatypes', function () {
Model = db.define('RequiredNumber', { Model = db.define('RequiredNumber', {
num: { type: Number, required: true } num: { type: Number, required: true }
}); });
db.automigrate(function () { db.automigrate(['Model'], function () {
Model.create({ num: [1,2,3] }, function(err, inst) { Model.create({ num: [1,2,3] }, function(err, inst) {
should.exist(err); should.exist(err);
err.should.have.property('name').equal('ValidationError'); err.should.have.property('name').equal('ValidationError');
@ -185,7 +183,7 @@ describe('datatypes', function () {
isStrict = TestModel.definition.settings.strict; isStrict = TestModel.definition.settings.strict;
db.automigrate(done); db.automigrate(['TestModel'], done);
}); });
it('should set missing optional properties to null', function(done) { it('should set missing optional properties to null', function(done) {

View File

@ -20,7 +20,7 @@ describe('hooks', function () {
state: String state: String
}); });
db.automigrate(done); db.automigrate('User', done);
}); });
describe('initialize', function () { describe('initialize', function () {

View File

@ -21,7 +21,7 @@ describe('manipulation', function () {
createdAt: {type: Date, default: Date} createdAt: {type: Date, default: Date}
}, { forceId: true, strict: true }); }, { forceId: true, strict: true });
db.automigrate(done); db.automigrate(['Person'], done);
}); });
@ -296,7 +296,7 @@ describe('manipulation', function () {
// NOTE(bajtos) We cannot reuse Person model here, // NOTE(bajtos) We cannot reuse Person model here,
// `settings.forceId` aborts the CREATE request at the validation step. // `settings.forceId` aborts the CREATE request at the validation step.
var Product = db.define('ProductTest', { name: String }); var Product = db.define('ProductTest', { name: String });
db.automigrate(function(err) { db.automigrate('ProductTest', function(err) {
if (err) return done(err); if (err) return done(err);
Product.create({ name: 'a-name' }, function(err, p) { Product.create({ name: 'a-name' }, function(err, p) {

View File

@ -32,15 +32,7 @@ describe('relations', function () {
Author = db.define('Author', {name: String}); Author = db.define('Author', {name: String});
Reader = db.define('Reader', {name: String}); Reader = db.define('Reader', {name: String});
db.automigrate(function () { db.automigrate(['Book', 'Chapter', 'Author', 'Reader'], done);
Book.destroyAll(function () {
Chapter.destroyAll(function () {
Author.destroyAll(function () {
Reader.destroyAll(done);
});
});
});
});
}); });
it('can be declared in different ways', function (done) { it('can be declared in different ways', function (done) {
@ -54,7 +46,7 @@ describe('relations', function () {
Object.keys((new Chapter).toObject()).should.containEql('bookId'); Object.keys((new Chapter).toObject()).should.containEql('bookId');
Object.keys((new Author).toObject()).should.containEql('projectId'); Object.keys((new Author).toObject()).should.containEql('projectId');
db.automigrate(done); db.automigrate(['Book', 'Chapter', 'Author', 'Reader'], done);
}); });
it('can be declared in short form', function (done) { it('can be declared in short form', function (done) {
@ -62,7 +54,7 @@ describe('relations', function () {
(new Author).readers.should.be.an.instanceOf(Function); (new Author).readers.should.be.an.instanceOf(Function);
Object.keys((new Reader).toObject()).should.containEql('authorId'); Object.keys((new Reader).toObject()).should.containEql('authorId');
db.autoupdate(done); db.autoupdate(['Author', 'Reader'], done);
}); });
describe('with scope', function() { describe('with scope', function() {
@ -562,7 +554,7 @@ describe('relations', function () {
var Physician, Patient, Appointment, Address; var Physician, Patient, Appointment, Address;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Physician = db.define('Physician', {name: String}); Physician = db.define('Physician', {name: String});
Patient = db.define('Patient', {name: String}); Patient = db.define('Patient', {name: String});
Appointment = db.define('Appointment', {date: {type: Date, Appointment = db.define('Appointment', {date: {type: Date,
@ -577,9 +569,7 @@ describe('relations', function () {
Appointment.belongsTo(Patient); Appointment.belongsTo(Patient);
Appointment.belongsTo(Physician); Appointment.belongsTo(Physician);
db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], function (err) { db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], done);
done(err);
});
}); });
it('should build record on scope', function (done) { it('should build record on scope', function (done) {
@ -1135,7 +1125,7 @@ describe('relations', function () {
var Physician, Patient, Appointment, Address; var Physician, Patient, Appointment, Address;
beforeEach(function (done) { beforeEach(function (done) {
db = getSchema(); // db = getSchema();
Physician = db.define('Physician', {name: String}); Physician = db.define('Physician', {name: String});
Patient = db.define('Patient', {name: String}); Patient = db.define('Patient', {name: String});
Appointment = db.define('Appointment', {date: {type: Date, Appointment = db.define('Appointment', {date: {type: Date,
@ -1144,9 +1134,7 @@ describe('relations', function () {
}}}); }}});
Address = db.define('Address', {name: String}); Address = db.define('Address', {name: String});
db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], function (err) { db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], done);
done(err);
});
}); });
describe('with default options', function () { describe('with default options', function () {
@ -1254,7 +1242,7 @@ describe('relations', function () {
var User, Follow, Address; var User, Follow, Address;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
User = db.define('User', {name: String}); User = db.define('User', {name: String});
Follow = db.define('Follow', {date: {type: Date, Follow = db.define('Follow', {date: {type: Date,
default: function () { default: function () {
@ -1267,9 +1255,7 @@ describe('relations', function () {
User.belongsTo(Address); User.belongsTo(Address);
Follow.belongsTo(User, {as: 'follower'}); Follow.belongsTo(User, {as: 'follower'});
Follow.belongsTo(User, {as: 'followee'}); Follow.belongsTo(User, {as: 'followee'});
db.automigrate(['User', 'Follow'], function (err) { db.automigrate(['User', 'Follow'], done);
done(err);
});
}); });
@ -1304,7 +1290,7 @@ describe('relations', function () {
var User, Follow, Address; var User, Follow, Address;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
User = db.define('User', {name: String}); User = db.define('User', {name: String});
Follow = db.define('Follow', {date: {type: Date, Follow = db.define('Follow', {date: {type: Date,
default: function () { default: function () {
@ -1317,9 +1303,7 @@ describe('relations', function () {
User.belongsTo(Address); User.belongsTo(Address);
Follow.belongsTo(User, {as: 'follower'}); Follow.belongsTo(User, {as: 'follower'});
Follow.belongsTo(User, {as: 'followee'}); Follow.belongsTo(User, {as: 'followee'});
db.automigrate(['User', 'Follow', 'Address'], function (err) { db.automigrate(['User', 'Follow', 'Address'], done);
done(err);
});
}); });
it('should set the keyThrough and the foreignKey', function (done) { it('should set the keyThrough and the foreignKey', function (done) {
@ -1348,7 +1332,7 @@ describe('relations', function () {
describe('hasMany with properties', function () { describe('hasMany with properties', function () {
it('can be declared with properties', function (done) { it('can be declared with properties', function (done) {
Book.hasMany(Chapter, { properties: { type: 'bookType' } }); Book.hasMany(Chapter, { properties: { type: 'bookType' } });
db.automigrate(done); db.automigrate(['Book', 'Chapter'], done);
}); });
it('should create record on scope', function (done) { it('should create record on scope', function (done) {
@ -1379,7 +1363,7 @@ describe('relations', function () {
describe('hasMany with scope and properties', function () { describe('hasMany with scope and properties', function () {
it('can be declared with properties', function (done) { it('can be declared with properties', function (done) {
db = getSchema(); // db = getSchema();
Category = db.define('Category', {name: String, jobType: String}); Category = db.define('Category', {name: String, jobType: String});
Job = db.define('Job', {name: String, type: String}); Job = db.define('Job', {name: String, type: String});
@ -1393,7 +1377,7 @@ describe('relations', function () {
if (m) return { where: m }; if (m) return { where: m };
} }
}); });
db.automigrate(done); db.automigrate(['Category', 'Job'], done);
}); });
it('should create record on scope', function (done) { it('should create record on scope', function (done) {
@ -1573,25 +1557,19 @@ describe('relations', function () {
describe('polymorphic hasOne', function () { describe('polymorphic hasOne', function () {
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Picture = db.define('Picture', {name: String}); Picture = db.define('Picture', {name: String});
Author = db.define('Author', {name: String}); Author = db.define('Author', {name: String});
Reader = db.define('Reader', {name: String}); Reader = db.define('Reader', {name: String});
db.automigrate(function () { db.automigrate(['Picture', 'Author', 'Reader'], done);
Picture.destroyAll(function () {
Author.destroyAll(function () {
Reader.destroyAll(done);
});
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
Author.hasOne(Picture, { as: 'avatar', polymorphic: 'imageable' }); Author.hasOne(Picture, { as: 'avatar', polymorphic: 'imageable' });
Reader.hasOne(Picture, { as: 'mugshot', polymorphic: 'imageable' }); Reader.hasOne(Picture, { as: 'mugshot', polymorphic: 'imageable' });
Picture.belongsTo('imageable', { polymorphic: true }); Picture.belongsTo('imageable', { polymorphic: true });
db.automigrate(done); db.automigrate(['Picture', 'Author', 'Reader'], done);
}); });
it('should create polymorphic relation - author', function (done) { it('should create polymorphic relation - author', function (done) {
@ -1726,7 +1704,7 @@ describe('relations', function () {
describe('polymorphic hasOne with non standard ids', function () { describe('polymorphic hasOne with non standard ids', function () {
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Picture = db.define('Picture', {name: String}); Picture = db.define('Picture', {name: String});
Author = db.define('Author', { Author = db.define('Author', {
username: {type: String, id: true, generated: true}, username: {type: String, id: true, generated: true},
@ -1737,13 +1715,7 @@ describe('relations', function () {
name: String name: String
}); });
db.automigrate(function () { db.automigrate(['Picture', 'Author', 'Reader'], done);
Picture.destroyAll(function () {
Author.destroyAll(function () {
Reader.destroyAll(done);
});
});
});
}); });
it('can be declared with non standard foreign key', function (done) { it('can be declared with non standard foreign key', function (done) {
@ -1769,7 +1741,7 @@ describe('relations', function () {
discriminator: 'type' discriminator: 'type'
} }
}); });
db.automigrate(done); db.automigrate(['Picture', 'Author', 'Reader'], done);
}); });
it('should create polymorphic relation - author', function (done) { it('should create polymorphic relation - author', function (done) {
@ -1891,18 +1863,12 @@ describe('relations', function () {
describe('polymorphic hasMany', function () { describe('polymorphic hasMany', function () {
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Picture = db.define('Picture', {name: String}); Picture = db.define('Picture', {name: String});
Author = db.define('Author', {name: String}); Author = db.define('Author', {name: String});
Reader = db.define('Reader', {name: String}); Reader = db.define('Reader', {name: String});
db.automigrate(function () { db.automigrate(['Picture', 'Author', 'Reader'], done);
Picture.destroyAll(function () {
Author.destroyAll(function () {
Reader.destroyAll(done);
});
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -1943,7 +1909,7 @@ describe('relations', function () {
} }
}); });
db.automigrate(done); db.automigrate(['Picture', 'Author', 'Reader'], done);
}); });
it('should create polymorphic relation - author', function (done) { it('should create polymorphic relation - author', function (done) {
@ -2091,21 +2057,13 @@ describe('relations', function () {
describe('polymorphic hasAndBelongsToMany through', function () { describe('polymorphic hasAndBelongsToMany through', function () {
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Picture = db.define('Picture', {name: String}); Picture = db.define('Picture', {name: String});
Author = db.define('Author', {name: String}); Author = db.define('Author', {name: String});
Reader = db.define('Reader', {name: String}); Reader = db.define('Reader', {name: String});
PictureLink = db.define('PictureLink', {}); PictureLink = db.define('PictureLink', {});
db.automigrate(function () { db.automigrate(['Picture', 'Author', 'Reader', 'PictureLink'], done);
Picture.destroyAll(function () {
PictureLink.destroyAll(function () {
Author.destroyAll(function () {
Reader.destroyAll(done);
});
});
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -2114,7 +2072,7 @@ describe('relations', function () {
// Optionally, define inverse relations: // Optionally, define inverse relations:
Picture.hasMany(Author, { through: PictureLink, polymorphic: 'imageable', invert: true }); Picture.hasMany(Author, { through: PictureLink, polymorphic: 'imageable', invert: true });
Picture.hasMany(Reader, { through: PictureLink, polymorphic: 'imageable', invert: true }); Picture.hasMany(Reader, { through: PictureLink, polymorphic: 'imageable', invert: true });
db.automigrate(done); db.automigrate(['Picture', 'Author', 'Reader', 'PictureLink'], done);
}); });
it('can determine the collect via modelTo name', function () { it('can determine the collect via modelTo name', function () {
@ -2423,7 +2381,7 @@ describe('relations', function () {
it('can be used to query data', function (done) { it('can be used to query data', function (done) {
List.hasMany('todos', {model: Item}); List.hasMany('todos', {model: Item});
db.automigrate(function () { db.automigrate(['List', 'Item', 'Fear', 'Find'], function () {
List.create({name: 'List 1'}, function (e, list) { List.create({name: 'List 1'}, function (e, list) {
listId = list.id; listId = list.id;
should.not.exist(e); should.not.exist(e);
@ -2445,7 +2403,7 @@ describe('relations', function () {
it('can be used to query data with getAsync with callback', function (done) { it('can be used to query data with getAsync with callback', function (done) {
List.hasMany('todos', {model: Item}); List.hasMany('todos', {model: Item});
db.automigrate(function () { db.automigrate(['List', 'Item', 'Fear', 'Find'], function () {
List.create({name: 'List 1'}, function (e, list) { List.create({name: 'List 1'}, function (e, list) {
listId = list.id; listId = list.id;
should.not.exist(e); should.not.exist(e);
@ -2467,7 +2425,7 @@ describe('relations', function () {
it('can be used to query data with promises', function (done) { it('can be used to query data with promises', function (done) {
List.hasMany('todos', {model: Item}); List.hasMany('todos', {model: Item});
db.automigrate(function () { db.automigrate(['List', 'Item', 'Fear', 'Find'], function () {
List.create({name: 'List 1'}) List.create({name: 'List 1'})
.then(function (list) { .then(function (list) {
listId = list.id; listId = list.id;
@ -2600,7 +2558,7 @@ describe('relations', function () {
properties: { notes: 'passportNotes' }, properties: { notes: 'passportNotes' },
scope: { fields: { id: true, name: true } } scope: { fields: { id: true, name: true } }
}); });
db.automigrate(done); db.automigrate(['Person', 'Passport'], done);
}); });
var personCreated; var personCreated;
@ -2675,7 +2633,7 @@ describe('relations', function () {
properties: ['name'], properties: ['name'],
options: { embedsProperties: true, invertProperties: true } options: { embedsProperties: true, invertProperties: true }
}); });
db.automigrate(done); db.automigrate(['Person', 'Passport'], done);
}); });
it('should create record with embedded data', function (done) { it('should create record with embedded data', function (done) {
@ -2719,7 +2677,7 @@ describe('relations', function () {
var supplierId, accountId; var supplierId, accountId;
before(function () { before(function () {
db = getSchema(); // db = getSchema();
Supplier = db.define('Supplier', {name: String}); Supplier = db.define('Supplier', {name: String});
Account = db.define('Account', {accountNo: String, supplierName: String}); Account = db.define('Account', {accountNo: String, supplierName: String});
}); });
@ -2749,7 +2707,7 @@ describe('relations', function () {
}); });
it('can be used to query data', function (done) { it('can be used to query data', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}, function (e, supplier) { Supplier.create({name: 'Supplier 1'}, function (e, supplier) {
supplierId = supplier.id; supplierId = supplier.id;
should.not.exist(e); should.not.exist(e);
@ -2770,7 +2728,7 @@ describe('relations', function () {
}); });
it('can be used to query data with getAsync with callback', function (done) { it('can be used to query data with getAsync with callback', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}, function (e, supplier) { Supplier.create({name: 'Supplier 1'}, function (e, supplier) {
supplierId = supplier.id; supplierId = supplier.id;
should.not.exist(e); should.not.exist(e);
@ -2791,7 +2749,7 @@ describe('relations', function () {
}); });
it('can be used to query data with promises', function (done) { it('can be used to query data with promises', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}) Supplier.create({name: 'Supplier 1'})
.then(function (supplier) { .then(function (supplier) {
supplierId = supplier.id; supplierId = supplier.id;
@ -2954,14 +2912,14 @@ describe('relations', function () {
var supplierId, accountId; var supplierId, accountId;
before(function () { before(function () {
db = getSchema(); // db = getSchema();
Supplier = db.define('Supplier', {name: String}); Supplier = db.define('Supplier', {name: String});
Account = db.define('Account', {accountNo: String, supplierName: String, block: Boolean}); Account = db.define('Account', {accountNo: String, supplierName: String, block: Boolean});
Supplier.hasOne(Account, { scope: { where: { block: false } }, properties: { name: 'supplierName' } }); Supplier.hasOne(Account, { scope: { where: { block: false } }, properties: { name: 'supplierName' } });
}); });
it('can be used to query data', function (done) { it('can be used to query data', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}, function (e, supplier) { Supplier.create({name: 'Supplier 1'}, function (e, supplier) {
supplierId = supplier.id; supplierId = supplier.id;
should.not.exist(e); should.not.exist(e);
@ -3017,7 +2975,7 @@ describe('relations', function () {
}); });
it('can be used to query data with promises', function (done) { it('can be used to query data with promises', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}) Supplier.create({name: 'Supplier 1'})
.then(function (supplier) { .then(function (supplier) {
supplierId = supplier.id; supplierId = supplier.id;
@ -3063,7 +3021,7 @@ describe('relations', function () {
var supplierId, accountId; var supplierId, accountId;
before(function () { before(function () {
db = getSchema(); // db = getSchema();
Supplier = db.define('Supplier', { Supplier = db.define('Supplier', {
sid: { sid: {
type: String, type: String,
@ -3092,7 +3050,7 @@ describe('relations', function () {
}); });
it('can be used to query data', function (done) { it('can be used to query data', function (done) {
db.automigrate(function () { db.automigrate(['Supplier', 'Account'], function () {
Supplier.create({name: 'Supplier 1'}, function (e, supplier) { Supplier.create({name: 'Supplier 1'}, function (e, supplier) {
supplierId = supplier.sid; supplierId = supplier.sid;
should.not.exist(e); should.not.exist(e);
@ -3152,13 +3110,7 @@ describe('relations', function () {
TagName = db.define('TagName', {name: String, flag: String}); TagName = db.define('TagName', {name: String, flag: String});
Article.hasAndBelongsToMany('tagNames'); Article.hasAndBelongsToMany('tagNames');
ArticleTag = db.models.ArticleTagName; ArticleTag = db.models.ArticleTagName;
db.automigrate(function () { db.automigrate(['Article', 'TagName', 'ArticleTagName'], done);
Article.destroyAll(function () {
TagName.destroyAll(function () {
ArticleTag.destroyAll(done)
});
});
});
}); });
it('should allow to create instances on scope', function (done) { it('should allow to create instances on scope', function (done) {
@ -3220,7 +3172,7 @@ describe('relations', function () {
}); });
it('should allow to create instances on scope with promises', function (done) { it('should allow to create instances on scope with promises', function (done) {
db.automigrate(function () { db.automigrate(['Article', 'TagName', 'ArticleTagName'], function () {
Article.create() Article.create()
.then(function (article) { .then(function (article) {
return article.tagNames.create({name: 'popular'}) return article.tagNames.create({name: 'popular'})
@ -3354,7 +3306,7 @@ describe('relations', function () {
before(function () { before(function () {
tmp = getTransientDataSource(); tmp = getTransientDataSource();
db = getSchema(); // db = getSchema();
Person = db.define('Person', {name: String}); Person = db.define('Person', {name: String});
Passport = tmp.define('Passport', Passport = tmp.define('Passport',
{name:{type:'string', required: true}}, {name:{type:'string', required: true}},
@ -3370,7 +3322,7 @@ describe('relations', function () {
methods: { check: function() { return true; } } methods: { check: function() { return true; } }
}); });
Person.embedsOne(Address); // all by default Person.embedsOne(Address); // all by default
db.automigrate(done); db.automigrate(['Person'], done);
}); });
it('should have setup a property and accessor', function() { it('should have setup a property and accessor', function() {
@ -3656,7 +3608,7 @@ describe('relations', function () {
Person.embedsOne(Passport, { Person.embedsOne(Passport, {
options: {persistent: true} options: {persistent: true}
}); });
db.automigrate(done); db.automigrate(['Person', 'Passport'], done);
}); });
it('should create an item - to offset id', function(done) { it('should create an item - to offset id', function(done) {
@ -3698,7 +3650,7 @@ describe('relations', function () {
before(function () { before(function () {
tmp = getTransientDataSource(); tmp = getTransientDataSource();
db = getSchema(); // db = getSchema();
Person = db.define('Person', {name: String}); Person = db.define('Person', {name: String});
Passport = tmp.define('Passport', Passport = tmp.define('Passport',
{id: {type:'string', id: true, generated:true}}, {id: {type:'string', id: true, generated:true}},
@ -3708,7 +3660,7 @@ describe('relations', function () {
it('can be declared using embedsOne method', function (done) { it('can be declared using embedsOne method', function (done) {
Person.embedsOne(Passport); Person.embedsOne(Passport);
db.automigrate(done); db.automigrate(['Person'], done);
}); });
it('should create an embedded item on scope', function(done) { it('should create an embedded item on scope', function(done) {
@ -3731,19 +3683,17 @@ describe('relations', function () {
before(function (done) { before(function (done) {
tmp = getTransientDataSource({defaultIdType: Number}); tmp = getTransientDataSource({defaultIdType: Number});
db = getSchema(); // db = getSchema();
Person = db.define('Person', {name: String}); Person = db.define('Person', {name: String});
Address = tmp.define('Address', {street: String}); Address = tmp.define('Address', {street: String});
Address.validatesPresenceOf('street'); Address.validatesPresenceOf('street');
db.automigrate(function () { db.automigrate(['Person'], done);
Person.destroyAll(done);
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
Person.embedsMany(Address); Person.embedsMany(Address);
db.automigrate(done); db.automigrate(['Person'], done);
}); });
it('should have setup embedded accessor/scope', function() { it('should have setup embedded accessor/scope', function() {
@ -3969,21 +3919,19 @@ describe('relations', function () {
before(function (done) { before(function (done) {
tmp = getTransientDataSource(); tmp = getTransientDataSource();
db = getSchema(); // db = getSchema();
Person = db.define('Person', {name: String}); Person = db.define('Person', {name: String});
Address = tmp.define('Address', { Address = tmp.define('Address', {
id: {type: Number, id:true}, id: {type: Number, id:true},
street: String street: String
}); });
db.automigrate(function () { db.automigrate(['Person'], done);
Person.destroyAll(done);
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
Person.embedsMany(Address, {options: {forceId: true}}); Person.embedsMany(Address, {options: {forceId: true}});
db.automigrate(done); db.automigrate(['Person'], done);
}); });
it('should create embedded items on scope', function(done) { it('should create embedded items on scope', function(done) {
@ -4007,19 +3955,17 @@ describe('relations', function () {
describe('embedsMany - explicit ids', function () { describe('embedsMany - explicit ids', function () {
before(function (done) { before(function (done) {
tmp = getTransientDataSource(); tmp = getTransientDataSource();
db = getSchema(); // db = getSchema();
Person = db.define('Person', {name: String}); Person = db.define('Person', {name: String});
Address = tmp.define('Address', {street: String}); Address = tmp.define('Address', {street: String});
Address.validatesPresenceOf('street'); Address.validatesPresenceOf('street');
db.automigrate(function () { db.automigrate(['Person'], done);
Person.destroyAll(done);
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
Person.embedsMany(Address); Person.embedsMany(Address);
db.automigrate(done); db.automigrate(['Person'], done);
}); });
it('should create embedded items on scope', function(done) { it('should create embedded items on scope', function(done) {
@ -4190,9 +4136,7 @@ describe('relations', function () {
Address = db.define('Address', {street: String}); Address = db.define('Address', {street: String});
Address.validatesPresenceOf('street'); Address.validatesPresenceOf('street');
db.automigrate(function () { db.automigrate(['Person', 'Address'], done);
Person.destroyAll(done);
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -4202,7 +4146,7 @@ describe('relations', function () {
scope: {order: 'street'}, scope: {order: 'street'},
options: {persistent: true} options: {persistent: true}
}); });
db.automigrate(done); db.automigrate(['Person', 'Address'], done);
}); });
it('should create individual items (0)', function(done) { it('should create individual items (0)', function(done) {
@ -4308,7 +4252,7 @@ describe('relations', function () {
var category, job1, job2, job3; var category, job1, job2, job3;
before(function () { before(function () {
db = getSchema(); // db = getSchema();
Category = db.define('Category', {name: String}); Category = db.define('Category', {name: String});
Job = db.define('Job', {name: String}); Job = db.define('Job', {name: String});
Link = db.define('Link', {name: String, notes: String}); Link = db.define('Link', {name: String, notes: String});
@ -4325,7 +4269,7 @@ describe('relations', function () {
properties: { id: 'id', name: 'name' }, // denormalize, transfer id properties: { id: 'id', name: 'name' }, // denormalize, transfer id
options: { invertProperties: true } options: { invertProperties: true }
}); });
db.automigrate(function() { db.automigrate(['Category', 'Job', 'Link'], function() {
Job.create({ name: 'Job 0' }, done); // offset ids for tests Job.create({ name: 'Job 0' }, done); // offset ids for tests
}); });
}); });
@ -4540,7 +4484,7 @@ describe('relations', function () {
var person1, person2; var person1, person2;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
tmp = getTransientDataSource(); tmp = getTransientDataSource();
Book = db.define('Book', {name: String}); Book = db.define('Book', {name: String});
@ -4554,13 +4498,7 @@ describe('relations', function () {
Link.validatesPresenceOf('linkedId'); Link.validatesPresenceOf('linkedId');
Link.validatesPresenceOf('linkedType'); Link.validatesPresenceOf('linkedType');
db.automigrate(function () { db.automigrate(['Book', 'Author', 'Reader'], done);
Book.destroyAll(function() {
Author.destroyAll(function() {
Reader.destroyAll(done);
});
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -4575,7 +4513,7 @@ describe('relations', function () {
properties: { name: 'name' }, // denormalized properties: { name: 'name' }, // denormalized
options: { invertProperties: true } options: { invertProperties: true }
}); });
db.automigrate(done); db.automigrate(['Book', 'Author', 'Reader'], done);
}); });
it('should setup related items', function(done) { it('should setup related items', function(done) {
@ -4683,15 +4621,11 @@ describe('relations', function () {
var job1, job2, job3; var job1, job2, job3;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Category = db.define('Category', {name: String}); Category = db.define('Category', {name: String});
Job = db.define('Job', {name: String}); Job = db.define('Job', {name: String});
db.automigrate(function () { db.automigrate(['Job', 'Category'], done);
Category.destroyAll(function() {
Job.destroyAll(done);
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -4717,7 +4651,7 @@ describe('relations', function () {
should.exist(Category.prototype['__reverse__jobs'].shared); should.exist(Category.prototype['__reverse__jobs'].shared);
Category.prototype['__reverse__jobs'].http.should.eql(reverse.http); Category.prototype['__reverse__jobs'].http.should.eql(reverse.http);
db.automigrate(done); db.automigrate(['Job', 'Category'], done);
}); });
it('should setup test records', function (done) { it('should setup test records', function (done) {
@ -4945,7 +4879,7 @@ describe('relations', function () {
}); });
it('should setup test records with promises', function (done) { it('should setup test records with promises', function (done) {
db.automigrate(function () { db.automigrate(['Job', 'Category'], function () {
return Job.create({ name: 'Job 1' }) return Job.create({ name: 'Job 1' })
.then(function (p) { .then(function (p) {
job1 = p; job1 = p;
@ -5217,15 +5151,11 @@ describe('relations', function () {
var categoryId; var categoryId;
before(function (done) { before(function (done) {
db = getSchema(); // db = getSchema();
Category = db.define('Category', {name: String}); Category = db.define('Category', {name: String});
Job = db.define('Job', {name: String}); Job = db.define('Job', {name: String});
db.automigrate(function () { db.automigrate(['Job', 'Category'], done);
Category.destroyAll(function() {
Job.destroyAll(done);
});
});
}); });
it('can be declared', function (done) { it('can be declared', function (done) {
@ -5255,7 +5185,7 @@ describe('relations', function () {
should.exist(Category.prototype['__summarize__jobs'].shared); should.exist(Category.prototype['__summarize__jobs'].shared);
Category.prototype['__summarize__jobs'].http.should.eql(summarize.http); Category.prototype['__summarize__jobs'].http.should.eql(summarize.http);
db.automigrate(done); db.automigrate(['Job', 'Category'], done);
}); });
it('should setup test records', function (done) { it('should setup test records', function (done) {