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

Commit 4b52b819 by Ryan Fink

Updates to the test to check for valid unique index creation

1 parent 138b076d
Showing with 28 additions and 2 deletions
......@@ -311,11 +311,37 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})))
})
it('allows unique on column with field aliases', function(done) {
it('allows unique on column with field aliases', function() {
var User = this.sequelize.define('UserWithUniqueFieldAlias', {
userName: { type: Sequelize.STRING, unique: 'user_name_unique', field: 'user_name' }
});
return User.sync({ force: true });
return User.sync({ force: true }).bind(this).then(function() {
return this.sequelize.queryInterface.showIndex(User.tableName).then(function(indexes) {
var idxPrimary, idxUnique;
if (dialect === 'sqlite') {
expect(indexes).to.have.length(1);
idxUnique = indexes[0];
expect(idxUnique.primary).to.equal(false);
expect(idxUnique.unique).to.equal(true);
expect(idxUnique.fields).to.deep.equal([{attribute: 'user_name', length: undefined, order: undefined}]);
} else if (dialect === 'mysql') {
expect(indexes).to.have.length(2);
idxPrimary = indexes[0];
idxUnique = indexes[1];
expect(idxUnique.primary).to.equal(false);
expect(idxUnique.unique).to.equal(true);
expect(idxUnique.fields).to.deep.equal([{attribute: 'user_name', length: undefined, order: 'ASC'}]);
expect(idxUnique.type).to.equal('BTREE');
} else if (dialect === 'postgres') {
expect(indexes).to.have.length(2);
idxPrimary = indexes[0];
idxUnique = indexes[1];
expect(idxUnique.primary).to.equal(false);
expect(idxUnique.unique).to.equal(true);
expect(idxUnique.fields).to.deep.equal([{attribute: 'user_name', collate: undefined, order: undefined, length: undefined}]);
}
});
});
});
it('allows us to customize the error message for unique constraint', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!