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

Commit c8683217 by overlookmotel

Sequelize() hooks change name Instantiate to Init

1 parent f58a9a03
......@@ -56,8 +56,8 @@ var hookTypes = {
afterFind: {params: 2},
beforeDefine: {params: 2, sync: true},
afterDefine: {params: 1, sync: true},
beforeInstantiate: {params: 2, sync: true},
afterInstantiate: {params: 1, sync: true}
beforeInit: {params: 2, sync: true},
afterInit: {params: 1, sync: true}
};
var hookAliases = {
beforeDelete: 'beforeDestroy',
......@@ -370,8 +370,8 @@ Hooks.afterDefine = function(name, fn) {
* @param {String} name
* @param {Function} fn A callback function that is called with config, options, callback(err)
*/
Hooks.beforeInstantiate = function(name, fn) {
return Hooks.addHook.call(this, 'beforeInstantiate', name, fn);
Hooks.beforeInit = function(name, fn) {
return Hooks.addHook.call(this, 'beforeInit', name, fn);
};
/**
......@@ -379,6 +379,6 @@ Hooks.beforeInstantiate = function(name, fn) {
* @param {String} name
* @param {Function} fn A callback function that is called with sequelize, callback(err)
*/
Hooks.afterInstantiate = function(name, fn) {
return Hooks.addHook.call(this, 'afterInstantiate', name, fn);
Hooks.afterInit = function(name, fn) {
return Hooks.addHook.call(this, 'afterInit', name, fn);
};
......@@ -123,7 +123,7 @@ module.exports = (function() {
}
var config = {database: database, username: username, password: password};
Sequelize.runHooks('beforeInstantiate', config, options);
Sequelize.runHooks('beforeInit', config, options);
database = config.database;
username = config.username;
password = config.password;
......@@ -196,7 +196,7 @@ module.exports = (function() {
this.importCache = {};
Sequelize.runHooks('afterInstantiate', this);
Sequelize.runHooks('afterInit', this);
};
Sequelize.options = {hooks: {}};
......
......@@ -4359,29 +4359,29 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
});
});
describe('#instantiate', function() {
describe('#init', function() {
before(function() {
Sequelize.addHook('beforeInstantiate', function(config, options) {
Sequelize.addHook('beforeInit', function(config, options) {
config.database = 'db2';
options.host = 'server9';
});
Sequelize.addHook('afterInstantiate', function(sequelize) {
Sequelize.addHook('afterInit', function(sequelize) {
sequelize.options.protocol = 'udp';
});
this.seq = new Sequelize('db', 'user', 'pass', {});
});
it('beforeInstantiate hook can alter config', function() {
it('beforeInit hook can alter config', function() {
expect(this.seq.config.database).to.equal('db2');
});
it('beforeInstantiate hook can alter options', function() {
it('beforeInit hook can alter options', function() {
expect(this.seq.options.host).to.equal('server9');
});
it('afterInstantiate hook can alter options', function() {
it('afterInit hook can alter options', function() {
expect(this.seq.options.protocol).to.equal('udp');
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!