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

Commit a91d8b68 by Sushant

issue(5015) Added unit tests

1 parent 3774bebb
Showing with 32 additions and 8 deletions
...@@ -5,19 +5,19 @@ var Support = require(__dirname + '/../support') ...@@ -5,19 +5,19 @@ var Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types') , DataTypes = require(__dirname + '/../../../lib/data-types')
, expectsql = Support.expectsql , expectsql = Support.expectsql
, current = Support.sequelize , current = Support.sequelize
, sql = current.dialect.QueryGenerator; , sql = current.dialect.QueryGenerator
, _ = require('lodash');
describe(Support.getTestDialectTeaser('SQL'), function() { describe(Support.getTestDialectTeaser('SQL'), function() {
describe('createTable', function () { describe('createTable', function () {
var FooUser = current.define('user', {
mood: DataTypes.ENUM('happy', 'sad')
},{
schema: 'foo',
timestamps: false
});
describe('with enums', function () { describe('with enums', function () {
var FooUser = current.define('user', {
mood: DataTypes.ENUM('happy', 'sad')
},{
schema: 'foo',
timestamps: false
});
it('references enum in the right schema #3171', function () { it('references enum in the right schema #3171', function () {
expectsql(sql.createTableQuery(FooUser.getTableName(), sql.attributesToSQL(FooUser.rawAttributes), { }), { expectsql(sql.createTableQuery(FooUser.getTableName(), sql.attributesToSQL(FooUser.rawAttributes), { }), {
sqlite: 'CREATE TABLE IF NOT EXISTS `foo.users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `mood` TEXT);', sqlite: 'CREATE TABLE IF NOT EXISTS `foo.users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `mood` TEXT);',
...@@ -27,5 +27,29 @@ describe(Support.getTestDialectTeaser('SQL'), function() { ...@@ -27,5 +27,29 @@ describe(Support.getTestDialectTeaser('SQL'), function() {
}); });
}); });
}); });
if (current.dialect.name === 'postgres') {
describe('IF NOT EXISTS version check', function() {
var modifiedSQL = _.clone(sql);
var createTableQueryModified = sql.createTableQuery.bind(modifiedSQL);
it('it will not have IF NOT EXISTS for version 9.0 or below', function () {
modifiedSQL.sequelize.options.databaseVersion = '9.0.0';
expectsql(createTableQueryModified(FooUser.getTableName(), sql.attributesToSQL(FooUser.rawAttributes), { }), {
postgres: 'CREATE TABLE "foo"."users" ("id" SERIAL , "mood" "foo"."enum_users_mood", PRIMARY KEY ("id"));'
});
});
it('it will have IF NOT EXISTS for version 9.1 or above', function () {
modifiedSQL.sequelize.options.databaseVersion = '9.1.0';
expectsql(createTableQueryModified(FooUser.getTableName(), sql.attributesToSQL(FooUser.rawAttributes), { }), {
postgres: 'CREATE TABLE IF NOT EXISTS "foo"."users" ("id" SERIAL , "mood" "foo"."enum_users_mood", PRIMARY KEY ("id"));'
});
});
it('it will have IF NOT EXISTS for default version', function () {
modifiedSQL.sequelize.options.databaseVersion = 0;
expectsql(createTableQueryModified(FooUser.getTableName(), sql.attributesToSQL(FooUser.rawAttributes), { }), {
postgres: 'CREATE TABLE IF NOT EXISTS "foo"."users" ("id" SERIAL , "mood" "foo"."enum_users_mood", PRIMARY KEY ("id"));'
});
});
});
}
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!