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

Commit 946fb729 by Sushant Committed by GitHub

fix(sync): throw when no models defined (#10175)

1 parent 6b1ff3b1
......@@ -733,6 +733,9 @@ class Sequelize {
}
});
// no models defined, just authenticate
if (!models.length) return this.authenticate(options);
return Promise.each(models, model => model.sync(options));
}).then(() => {
if (options.hooks) {
......
......@@ -965,12 +965,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
if (dialect !== 'sqlite') {
it('fails for incorrect connection even when no models are defined', function() {
const sequelize = new Sequelize('cyber_bird', 'user', 'pass', {
dialect: this.sequelize.options.dialect
});
return expect(sequelize.sync({force: true})).to.be.rejected;
});
it('fails with incorrect database credentials (1)', function() {
this.sequelizeWithInvalidCredentials = new Sequelize('omg', 'bar', null, _.omit(this.sequelize.options, ['host']));
const User2 = this.sequelizeWithInvalidCredentials.define('User', { name: DataTypes.STRING, bio: DataTypes.TEXT });
return User2.sync().catch(err => {
return User2.sync()
.then(() => { expect.fail(); })
.catch(err => {
if (dialect === 'postgres' || dialect === 'postgres-native') {
assert([
'fe_sendauth: no password supplied',
......@@ -994,9 +1004,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize.define('Project', {title: Sequelize.STRING});
sequelize.define('Task', {title: Sequelize.STRING});
return sequelize.sync({force: true}).catch(err => {
expect(err).to.be.ok;
});
return expect(sequelize.sync({force: true})).to.be.rejected;
});
it('fails with incorrect database credentials (3)', function() {
......@@ -1008,9 +1016,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize.define('Project', {title: Sequelize.STRING});
sequelize.define('Task', {title: Sequelize.STRING});
return sequelize.sync({force: true}).catch(err => {
expect(err).to.be.ok;
});
return expect(sequelize.sync({force: true})).to.be.rejected;
});
it('fails with incorrect database credentials (4)', function() {
......@@ -1023,19 +1029,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize.define('Project', {title: Sequelize.STRING});
sequelize.define('Task', {title: Sequelize.STRING});
return sequelize.sync({force: true}).catch(err => {
expect(err).to.be.ok;
});
return expect(sequelize.sync({force: true})).to.be.rejected;
});
it('returns an error correctly if unable to sync a foreign key referenced model', function() {
this.sequelize.define('Application', {
authorID: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'User', key: 'id' } }
authorID: {
type: Sequelize.BIGINT,
allowNull: false,
references: {
model: 'User',
key: 'id'
}
}
});
return this.sequelize.sync().catch(error => {
assert.ok(error);
});
return expect(this.sequelize.sync()).to.be.rejected;
});
it('handles this dependant foreign key constraints', function() {
......@@ -1065,6 +1074,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
return this.sequelize.sync();
});
}
it('return the sequelize instance after syncing', function() {
return this.sequelize.sync().then(sequelize => {
......@@ -1086,7 +1096,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
expect(result).to.deep.equal(block);
});
});
}
describe("doesn't emit logging when explicitly saying not to", () => {
afterEach(function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!