不要怂,就是干,撸起袖子干!

Commit 1387f143 by Matheus Bratfisch

Not executing tests for multiple 1:M (hasMany) on MSSQL since the created constr…

…aints are not supported. #2736
1 parent deca3c5b
Showing with 248 additions and 244 deletions
...@@ -6,7 +6,8 @@ var chai = require('chai') ...@@ -6,7 +6,8 @@ var chai = require('chai')
, DataTypes = require(__dirname + '/../lib/data-types') , DataTypes = require(__dirname + '/../lib/data-types')
, _ = require('lodash') , _ = require('lodash')
, Sequelize = Support.Sequelize , Sequelize = Support.Sequelize
, sinon = require('sinon'); , sinon = require('sinon')
, dialect = Support.getTestDialect();
chai.config.includeStack = true; chai.config.includeStack = true;
...@@ -5332,308 +5333,311 @@ describe(Support.getTestDialectTeaser('Hooks'), function() { ...@@ -5332,308 +5333,311 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
}); });
}); });
describe('multiple 1:M', function () { if (dialect !== "mssql") {
describe('cascade', function() { describe('multiple 1:M', function () {
beforeEach(function() {
var self = this;
this.Projects = this.sequelize.define('Project', {
title: DataTypes.STRING
});
this.Tasks = this.sequelize.define('Task', { describe('cascade', function() {
title: DataTypes.STRING beforeEach(function() {
}); var self = this;
this.Projects = this.sequelize.define('Project', {
title: DataTypes.STRING
});
this.MiniTasks = this.sequelize.define('MiniTask', { this.Tasks = this.sequelize.define('Task', {
mini_title: DataTypes.STRING title: DataTypes.STRING
}); });
this.Projects.hasMany(this.Tasks, {onDelete: 'cascade', hooks: true}); this.MiniTasks = this.sequelize.define('MiniTask', {
this.Projects.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true}); mini_title: DataTypes.STRING
});
this.Tasks.belongsTo(this.Projects, {hooks: true});
this.Tasks.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true});
this.MiniTasks.belongsTo(this.Projects, {hooks: true}); this.Projects.hasMany(this.Tasks, {onDelete: 'cascade', hooks: true});
this.MiniTasks.belongsTo(this.Tasks, {hooks: true}); this.Projects.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true});
this.Tasks.belongsTo(this.Projects, {hooks: true});
this.Tasks.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true});
return this.sequelize.sync({force: true}); this.MiniTasks.belongsTo(this.Projects, {hooks: true});
}); this.MiniTasks.belongsTo(this.Tasks, {hooks: true});
describe('#remove', function() { return this.sequelize.sync({force: true});
it('with no errors', function() { });
var self = this
, beforeProject = false
, afterProject = false
, beforeTask = false
, afterTask = false
, beforeMiniTask = false
, afterMiniTask = false;
describe('#remove', function() {
it('with no errors', function() {
var self = this
, beforeProject = false
, afterProject = false
, beforeTask = false
, afterTask = false
, beforeMiniTask = false
, afterMiniTask = false;
this.Projects.beforeCreate(function(project, options, fn) {
beforeProject = true;
fn();
});
this.Projects.afterCreate(function(project, options, fn) { this.Projects.beforeCreate(function(project, options, fn) {
afterProject = true; beforeProject = true;
fn(); fn();
}); });
this.Tasks.beforeDestroy(function(task, options, fn) { this.Projects.afterCreate(function(project, options, fn) {
beforeTask = true; afterProject = true;
fn(); fn();
}); });
this.Tasks.afterDestroy(function(task, options, fn) { this.Tasks.beforeDestroy(function(task, options, fn) {
afterTask = true; beforeTask = true;
fn(); fn();
}); });
this.MiniTasks.beforeDestroy(function(minitask, options, fn) { this.Tasks.afterDestroy(function(task, options, fn) {
beforeMiniTask = true; afterTask = true;
fn(); fn();
}); });
this.MiniTasks.afterDestroy(function(minitask, options, fn) { this.MiniTasks.beforeDestroy(function(minitask, options, fn) {
afterMiniTask = true; beforeMiniTask = true;
fn(); fn();
}); });
return this.sequelize.Promise.all([ this.MiniTasks.afterDestroy(function(minitask, options, fn) {
this.Projects.create({title: 'New Project'}), afterMiniTask = true;
this.MiniTasks.create({mini_title: 'New MiniTask'}) fn();
]).bind(this).spread(function(project, minitask) { });
return project.addMiniTask(minitask);
}).then(function(project) {
return project.destroy();
}).then(function() {
expect(beforeProject).to.be.true;
expect(afterProject).to.be.true;
expect(beforeTask).to.be.false;
expect(afterTask).to.be.false;
expect(beforeMiniTask).to.be.true;
expect(afterMiniTask).to.be.true;
});
}); return this.sequelize.Promise.all([
this.Projects.create({title: 'New Project'}),
this.MiniTasks.create({mini_title: 'New MiniTask'})
]).bind(this).spread(function(project, minitask) {
return project.addMiniTask(minitask);
}).then(function(project) {
return project.destroy();
}).then(function() {
expect(beforeProject).to.be.true;
expect(afterProject).to.be.true;
expect(beforeTask).to.be.false;
expect(afterTask).to.be.false;
expect(beforeMiniTask).to.be.true;
expect(afterMiniTask).to.be.true;
});
it('with errors', function() { });
var self = this
, beforeProject = false
, afterProject = false
, beforeTask = false
, afterTask = false
, beforeMiniTask = false
, afterMiniTask = false;
it('with errors', function() {
var self = this
, beforeProject = false
, afterProject = false
, beforeTask = false
, afterTask = false
, beforeMiniTask = false
, afterMiniTask = false;
this.Projects.beforeCreate(function(project, options, fn) {
beforeProject = true;
fn();
});
this.Projects.afterCreate(function(project, options, fn) { this.Projects.beforeCreate(function(project, options, fn) {
afterProject = true; beforeProject = true;
fn(); fn();
}); });
this.Tasks.beforeDestroy(function(task, options, fn) { this.Projects.afterCreate(function(project, options, fn) {
beforeTask = true; afterProject = true;
fn(); fn();
}); });
this.Tasks.afterDestroy(function(task, options, fn) { this.Tasks.beforeDestroy(function(task, options, fn) {
afterTask = true; beforeTask = true;
fn(); fn();
}); });
this.MiniTasks.beforeDestroy(function(minitask, options, fn) { this.Tasks.afterDestroy(function(task, options, fn) {
beforeMiniTask = true; afterTask = true;
fn(new Error('Whoops!')); fn();
}); });
this.MiniTasks.afterDestroy(function(minitask, options, fn) { this.MiniTasks.beforeDestroy(function(minitask, options, fn) {
afterMiniTask = true; beforeMiniTask = true;
fn(); fn(new Error('Whoops!'));
}); });
this.MiniTasks.afterDestroy(function(minitask, options, fn) {
afterMiniTask = true;
fn();
});
return this.sequelize.Promise.all([ return this.sequelize.Promise.all([
this.Projects.create({title: 'New Project'}), this.Projects.create({title: 'New Project'}),
this.MiniTasks.create({mini_title: 'New MiniTask'}) this.MiniTasks.create({mini_title: 'New MiniTask'})
]).bind(this).spread(function(project, minitask) { ]).bind(this).spread(function(project, minitask) {
return project.addMiniTask(minitask); return project.addMiniTask(minitask);
}).then(function(project) { }).then(function(project) {
return project.destroy(); return project.destroy();
}).catch(function() { }).catch(function() {
expect(beforeProject).to.be.true; expect(beforeProject).to.be.true;
expect(afterProject).to.be.true; expect(afterProject).to.be.true;
expect(beforeTask).to.be.false; expect(beforeTask).to.be.false;
expect(afterTask).to.be.false; expect(afterTask).to.be.false;
expect(beforeMiniTask).to.be.true; expect(beforeMiniTask).to.be.true;
expect(afterMiniTask).to.be.false; expect(afterMiniTask).to.be.false;
});
}); });
}); });
}); });
}); });
});
describe('multiple 1:M sequential hooks', function () { describe('multiple 1:M sequential hooks', function () {
describe('cascade', function() { describe('cascade', function() {
beforeEach(function() { beforeEach(function() {
var self = this; var self = this;
this.Projects = this.sequelize.define('Project', { this.Projects = this.sequelize.define('Project', {
title: DataTypes.STRING title: DataTypes.STRING
}); });
this.Tasks = this.sequelize.define('Task', { this.Tasks = this.sequelize.define('Task', {
title: DataTypes.STRING title: DataTypes.STRING
}); });
this.MiniTasks = this.sequelize.define('MiniTask', { this.MiniTasks = this.sequelize.define('MiniTask', {
mini_title: DataTypes.STRING mini_title: DataTypes.STRING
}); });
this.Projects.hasMany(this.Tasks, {onDelete: 'cascade', hooks: true}); this.Projects.hasMany(this.Tasks, {onDelete: 'cascade', hooks: true});
this.Projects.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true}); this.Projects.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true});
this.Tasks.belongsTo(this.Projects, {hooks: true}); this.Tasks.belongsTo(this.Projects, {hooks: true});
this.Tasks.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true}); this.Tasks.hasMany(this.MiniTasks, {onDelete: 'cascade', hooks: true});
this.MiniTasks.belongsTo(this.Projects, {hooks: true}); this.MiniTasks.belongsTo(this.Projects, {hooks: true});
this.MiniTasks.belongsTo(this.Tasks, {hooks: true}); this.MiniTasks.belongsTo(this.Tasks, {hooks: true});
return this.sequelize.sync({force: true}); return this.sequelize.sync({force: true});
}); });
describe('#remove', function() { describe('#remove', function() {
it('with no errors', function() { it('with no errors', function() {
var self = this var self = this
, beforeProject = false , beforeProject = false
, afterProject = false , afterProject = false
, beforeTask = false , beforeTask = false
, afterTask = false , afterTask = false
, beforeMiniTask = false , beforeMiniTask = false
, afterMiniTask = false; , afterMiniTask = false;
this.Projects.beforeCreate(function(project, options, fn) { this.Projects.beforeCreate(function(project, options, fn) {
beforeProject = true; beforeProject = true;
fn(); fn();
}); });
this.Projects.afterCreate(function(project, options, fn) { this.Projects.afterCreate(function(project, options, fn) {
afterProject = true; afterProject = true;
fn(); fn();
}); });
this.Tasks.beforeDestroy(function(task, options, fn) { this.Tasks.beforeDestroy(function(task, options, fn) {
beforeTask = true; beforeTask = true;
fn(); fn();
}); });
this.Tasks.afterDestroy(function(task, options, fn) { this.Tasks.afterDestroy(function(task, options, fn) {
afterTask = true; afterTask = true;
fn(); fn();
}); });
this.MiniTasks.beforeDestroy(function(minitask, options, fn) { this.MiniTasks.beforeDestroy(function(minitask, options, fn) {
beforeMiniTask = true; beforeMiniTask = true;
fn(); fn();
}); });
this.MiniTasks.afterDestroy(function(minitask, options, fn) { this.MiniTasks.afterDestroy(function(minitask, options, fn) {
afterMiniTask = true; afterMiniTask = true;
fn(); fn();
}); });
return this.sequelize.Promise.all([
this.Projects.create({title: 'New Project'}),
this.Tasks.create({title: 'New Task'}),
this.MiniTasks.create({mini_title: 'New MiniTask'})
]).bind(this).spread(function(project, task, minitask) {
return this.sequelize.Promise.all([ return this.sequelize.Promise.all([
task.addMiniTask(minitask), this.Projects.create({title: 'New Project'}),
project.addTask(task) this.Tasks.create({title: 'New Task'}),
]).return(project); this.MiniTasks.create({mini_title: 'New MiniTask'})
}).then(function(project) { ]).bind(this).spread(function(project, task, minitask) {
return project.destroy(); return this.sequelize.Promise.all([
}).then(function() { task.addMiniTask(minitask),
expect(beforeProject).to.be.true; project.addTask(task)
expect(afterProject).to.be.true; ]).return(project);
expect(beforeTask).to.be.true; }).then(function(project) {
expect(afterTask).to.be.true; return project.destroy();
expect(beforeMiniTask).to.be.true; }).then(function() {
expect(afterMiniTask).to.be.true; expect(beforeProject).to.be.true;
}); expect(afterProject).to.be.true;
}); expect(beforeTask).to.be.true;
expect(afterTask).to.be.true;
it('with errors', function() { expect(beforeMiniTask).to.be.true;
var self = this expect(afterMiniTask).to.be.true;
, beforeProject = false });
, afterProject = false });
, beforeTask = false
, afterTask = false it('with errors', function() {
, beforeMiniTask = false var self = this
, afterMiniTask = false; , beforeProject = false
, afterProject = false
, beforeTask = false
, afterTask = false
, beforeMiniTask = false
, afterMiniTask = false;
this.Projects.beforeCreate(function(project, options, fn) { this.Projects.beforeCreate(function(project, options, fn) {
beforeProject = true; beforeProject = true;
fn(); fn();
}); });
this.Projects.afterCreate(function(project, options, fn) { this.Projects.afterCreate(function(project, options, fn) {
afterProject = true; afterProject = true;
fn(); fn();
}); });
this.Tasks.beforeDestroy(function(task, options, fn) { this.Tasks.beforeDestroy(function(task, options, fn) {
beforeTask = true; beforeTask = true;
fn(new Error('Whoops!')); fn(new Error('Whoops!'));
fn(); fn();
}); });
this.Tasks.afterDestroy(function(task, options, fn) { this.Tasks.afterDestroy(function(task, options, fn) {
afterTask = true; afterTask = true;
fn(); fn();
}); });
this.MiniTasks.beforeDestroy(function(minitask, options, fn) { this.MiniTasks.beforeDestroy(function(minitask, options, fn) {
beforeMiniTask = true; beforeMiniTask = true;
}); });
this.MiniTasks.afterDestroy(function(minitask, options, fn) { this.MiniTasks.afterDestroy(function(minitask, options, fn) {
afterMiniTask = true; afterMiniTask = true;
fn(); fn();
}); });
return this.sequelize.Promise.all([
this.Projects.create({title: 'New Project'}),
this.Tasks.create({title: 'New Task'}),
this.MiniTasks.create({mini_title: 'New MiniTask'})
]).bind(this).spread(function(project, task, minitask) {
return this.sequelize.Promise.all([ return this.sequelize.Promise.all([
task.addMiniTask(minitask), this.Projects.create({title: 'New Project'}),
project.addTask(task) this.Tasks.create({title: 'New Task'}),
]).return(project); this.MiniTasks.create({mini_title: 'New MiniTask'})
}).then(function(project) { ]).bind(this).spread(function(project, task, minitask) {
return project.destroy(); return this.sequelize.Promise.all([
}).catch(function() { task.addMiniTask(minitask),
expect(beforeProject).to.be.true; project.addTask(task)
expect(afterProject).to.be.true; ]).return(project);
expect(beforeTask).to.be.true; }).then(function(project) {
expect(afterTask).to.be.false; return project.destroy();
expect(beforeMiniTask).to.be.false; }).catch(function() {
expect(afterMiniTask).to.be.false; expect(beforeProject).to.be.true;
expect(afterProject).to.be.true;
expect(beforeTask).to.be.true;
expect(afterTask).to.be.false;
expect(beforeMiniTask).to.be.false;
expect(afterMiniTask).to.be.false;
});
}); });
}); });
}); });
}); });
}); }
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!