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

Commit 3229b061 by Mick Hansen

add a few logging option tests

1 parent 6f46f980
...@@ -731,7 +731,7 @@ module.exports = (function() { ...@@ -731,7 +731,7 @@ module.exports = (function() {
return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({ return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({
hasJoin: hasJoin, hasJoin: hasJoin,
tableNames: Object.keys(tableNames) tableNames: Object.keys(tableNames)
}, queryOptions, { transaction: options.transaction })); }, queryOptions, { transaction: options.transaction, logging: options.logging }));
}).tap(function(results) { }).tap(function(results) {
if (options.hooks) { if (options.hooks) {
return this.runHooks('afterFind', results, options); return this.runHooks('afterFind', results, options);
......
...@@ -117,6 +117,8 @@ SequelizePromise.all = function (promises) { ...@@ -117,6 +117,8 @@ SequelizePromise.all = function (promises) {
* @deprecated * @deprecated
*/ */
Promise.prototype.on = function(evt, fct) { Promise.prototype.on = function(evt, fct) {
deprecated('on() is deprecated and will be removed in 2.1, please use promise-style instead or use logging: fn in method options for method sql log');
if (evt === 'success') { if (evt === 'success') {
this.then(fct); this.then(fct);
} }
......
'use strict'; 'use strict';
var chai = require('chai') var chai = require('chai')
, sinon = require('sinon')
, expect = chai.expect , expect = chai.expect
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types') , DataTypes = require(__dirname + '/../../../lib/data-types')
...@@ -127,6 +128,25 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() { ...@@ -127,6 +128,25 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() {
expect(user).to.be.ok; expect(user).to.be.ok;
}); });
}); });
it('should support logging', function () {
var spy = sinon.spy();
var User = this.sequelize.define('user', {})
, Project = this.sequelize.define('project', {});
User.belongsTo(Project);
return this.sequelize.sync({ force: true }).bind(this).then(function() {
return User.create({});
}).then(function(user) {
return user.getProject({
logging: spy
});
}).then(function() {
expect(spy.called).to.be.ok;
});
});
}); });
describe('setAssociation', function() { describe('setAssociation', function() {
...@@ -232,6 +252,24 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() { ...@@ -232,6 +252,24 @@ describe(Support.getTestDialectTeaser('BelongsTo'), function() {
}); });
}); });
it('should support logging', function() {
var User = this.sequelize.define('UserXYZ', { username: DataTypes.STRING })
, Task = this.sequelize.define('TaskXYZ', { title: DataTypes.STRING })
, spy = sinon.spy();
Task.belongsTo(User);
return this.sequelize.sync({ force: true }).then(function() {
return User.create().then(function(user) {
return Task.create({}).then(function(task) {
return task.setUserXYZ(user, {logging: spy}).then(function() {
expect(spy.called).to.be.ok;
});
});
});
});
});
it('should not clobber atributes', function(done) { it('should not clobber atributes', function(done) {
var Comment = this.sequelize.define('comment', { var Comment = this.sequelize.define('comment', {
text: DataTypes.STRING text: DataTypes.STRING
......
'use strict'; 'use strict';
var chai = require('chai') var chai = require('chai')
, sinon = require('sinon')
, Sequelize = require('../../../index') , Sequelize = require('../../../index')
, expect = chai.expect , expect = chai.expect
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
...@@ -386,5 +387,15 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -386,5 +387,15 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
}); });
}); });
}); });
it('should support logging', function () {
var spy = sinon.spy();
return this.User.create({}).then(function (user) {
return user.update({username: 'yolo'}, {logging: spy}).then(function () {
expect(spy.called).to.be.ok;
});
});
});
}); });
}); });
'use strict'; 'use strict';
var chai = require('chai') var chai = require('chai')
, sinon = require('sinon')
, Sequelize = require('../../../index') , Sequelize = require('../../../index')
, Promise = Sequelize.Promise , Promise = Sequelize.Promise
, expect = chai.expect , expect = chai.expect
...@@ -1590,4 +1591,14 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1590,4 +1591,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
}); });
it('should support logging', function () {
var spy = sinon.spy();
return this.User.create({}, {
logging: spy
}).then(function () {
expect(spy.called).to.be.ok;
});
});
}); });
'use strict'; 'use strict';
var chai = require('chai') var chai = require('chai')
, sinon = require('sinon')
, Sequelize = require('../../../index') , Sequelize = require('../../../index')
, Promise = Sequelize.Promise , Promise = Sequelize.Promise
, expect = chai.expect , expect = chai.expect
...@@ -1036,5 +1037,16 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1036,5 +1037,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
}); });
it('should support logging', function () {
var spy = sinon.spy();
return this.User.findOne({
where: {},
logging: spy
}).then(function () {
expect(spy.called).to.be.ok;
});
});
}); });
}); });
'use strict'; 'use strict';
var chai = require('chai') var chai = require('chai')
, sinon = require('sinon')
, Sequelize = require('../../../index') , Sequelize = require('../../../index')
, expect = chai.expect , expect = chai.expect
, Support = require(__dirname + '/../support') , Support = require(__dirname + '/../support')
...@@ -1542,4 +1543,15 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1542,4 +1543,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
}); });
it('should support logging', function () {
var spy = sinon.spy();
return this.User.findAll({
where: {},
logging: spy
}).then(function () {
expect(spy.called).to.be.ok;
});
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!