From 4b57038362096954b73655d7e528b82340fd825f Mon Sep 17 00:00:00 2001 From: Sascha Depold Date: Wed, 12 Dec 2012 22:39:28 +0100 Subject: [PATCH] moved migration specs to buster --- .watchr.js | 14 + package.json | 3 +- spec-jasmine/migrator.spec.js | 313 ------------------ .../migrations/20111117063700-createPerson.js | 15 + .../20111130161100-emptyMigration.js | 4 + .../20111205064000-renamePersonToUser.js | 9 + ...20111205162700-addSignatureColumnToUser.js | 13 + ...111206061400-removeShopIdColumnFromUser.js | 9 + ...-changeSignatureColumnOfUserToMendatory.js | 11 + ...163300-renameSignatureColumnOfUserToSig.js | 9 + spec/assets/project.js | 5 + spec/associations/belongs-to.spec.js | 2 +- spec/associations/has-many.spec.js | 2 +- spec/associations/has-one.spec.js | 2 +- spec/associations/mixin.spec.js | 2 +- spec/buster-helpers.js | 17 +- spec/dao-factory.spec.js | 2 +- spec/dao.spec.js | 2 +- spec/dao.validations.spec.js | 2 +- {spec-jasmine => spec}/migration.spec.js | 21 +- spec/migrator.spec.js | 278 ++++++++++++++++ spec/query-chainer.spec.js | 2 +- spec/sequelize.spec.js | 2 +- 23 files changed, 404 insertions(+), 335 deletions(-) create mode 100644 .watchr.js delete mode 100644 spec-jasmine/migrator.spec.js create mode 100644 spec/assets/migrations/20111117063700-createPerson.js create mode 100644 spec/assets/migrations/20111130161100-emptyMigration.js create mode 100644 spec/assets/migrations/20111205064000-renamePersonToUser.js create mode 100644 spec/assets/migrations/20111205162700-addSignatureColumnToUser.js create mode 100644 spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js create mode 100644 spec/assets/migrations/20111206063000-changeSignatureColumnOfUserToMendatory.js create mode 100644 spec/assets/migrations/20111206163300-renameSignatureColumnOfUserToSig.js create mode 100644 spec/assets/project.js rename {spec-jasmine => spec}/migration.spec.js (72%) create mode 100644 spec/migrator.spec.js diff --git a/.watchr.js b/.watchr.js new file mode 100644 index 000000000000..191a5c85c88c --- /dev/null +++ b/.watchr.js @@ -0,0 +1,14 @@ +var watchr = require('watchr') + , spawn = require('child_process').spawn + +watchr.watch({ + path: __dirname, + listener: function(eventName, filePath) { + if (['new', 'change'].indexOf(eventName) > -1) { + var buster = spawn('./node_modules/.bin/buster-test', ['--reporter', 'specification'], { env: process.ENV }) + + buster.stderr.on('data', function(data) { console.log(data.toString()) }) + buster.stdout.on('data', function(data) { console.log(data.toString()) }) + } + } +}) diff --git a/package.json b/package.json index 5f74b16e2b02..b966138b21f1 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "sqlite3": "~2.1.5", "pg": "~0.8.7", "buster": "~0.6.0", - "dox-foundation": "~0.3.0" + "dox-foundation": "~0.3.0", + "watchr": "~2.1.6" }, "keywords": [ "mysql", diff --git a/spec-jasmine/migrator.spec.js b/spec-jasmine/migrator.spec.js deleted file mode 100644 index 62a2a16aa9c3..000000000000 --- a/spec-jasmine/migrator.spec.js +++ /dev/null @@ -1,313 +0,0 @@ -var config = require("./config/config") - , Sequelize = require("../index") - , sequelize = new Sequelize(config.mysql.database, config.mysql.username, config.mysql.password, { logging: false }) - , Helpers = new (require("./config/helpers"))(sequelize) - , Migrator = require("../lib/migrator") - , _ = Sequelize.Utils._ - -describe('Migrator', function() { - var migrator = null - , SequelizeMeta = null - - var setup = function(_options) { - Helpers.async(function(done) { - var options = Sequelize.Utils._.extend({ - path: __dirname + '/assets/migrations', - logging: false - }, _options || {}) - - migrator = new Migrator(sequelize, options) - migrator - .findOrCreateSequelizeMetaDAO({ force: true }) - .success(function(_SequelizeMeta) { - SequelizeMeta = _SequelizeMeta - done() - }) - .error(function(err) { console.log(err) }) - }) - } - - var reset = function() { - migrator = null - Helpers.dropAllTables() - } - - beforeEach(reset) - afterEach(reset) - - describe('getUndoneMigrations', function() { - it("returns no files if timestamps are after the files timestamp", function() { - setup({ from: 20120101010101 }) - - Helpers.async(function(done) { - migrator.getUndoneMigrations(function(err, migrations) { - expect(err).toBeNull() - expect(migrations.length).toEqual(0) - done() - }) - }) - }) - - it("returns only files between from and to", function() { - setup({ from: 19700101000000, to: 20111117063700 }) - - Helpers.async(function(done) { - migrator.getUndoneMigrations(function(err, migrations) { - expect(err).toBeNull() - expect(migrations.length).toEqual(1) - expect(_.last(migrations).filename).toEqual('20111117063700-createPerson.js') - done() - }) - }) - }) - - it("returns also the file which is exactly options.from or options.to", function() { - setup({ from: 20111117063700, to: 20111130161100 }) - - Helpers.async(function(done) { - migrator.getUndoneMigrations(function(err, migrations) { - expect(err).toBeNull() - expect(migrations.length).toEqual(2) - expect(migrations[0].filename).toEqual('20111117063700-createPerson.js') - expect(migrations[1].filename).toEqual('20111130161100-emptyMigration.js') - done() - }) - }) - }) - - it("returns all files to options.to if no options.from is defined", function() { - setup({ to: 20111130161100 }) - - Helpers.async(function(done) { - migrator.getUndoneMigrations(function(err, migrations) { - expect(err).toBeNull() - expect(migrations.length).toEqual(2) - done() - }) - }) - }) - - it("returns all files from last migration id stored in database", function() { - setup() - - Helpers.async(function(done) { - SequelizeMeta.create({ from: null, to: 20111117063700 }).success(function() { - migrator.getUndoneMigrations(function(err, migrations) { - expect(err).toBeNull() - expect(migrations.length).toEqual(6) - expect(migrations[0].filename).toEqual('20111130161100-emptyMigration.js') - done() - }) - }) - }) - }) - }) - - describe('migrations', function() { - beforeEach(function() { - setup({ from: 20111117063700, to: 20111117063700 }) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - }) - - describe('executions', function() { - it("executes migration #20111117063700 and correctly creates the table", function() { - Helpers.async(function(done) { - sequelize.getQueryInterface().showAllTables().success(function(tableNames) { - tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) - expect(tableNames.length).toEqual(1) - expect(tableNames[0]).toEqual('Person') - done() - }) - }) - }) - - it("executes migration #20111117063700 and correctly adds isBetaMember", function() { - Helpers.async(function(done) { - sequelize.getQueryInterface().describeTable('Person').success(function(data) { - var beta = data.filter(function(d) { return d.Field == 'isBetaMember'}) - expect(beta).toBeDefined() - done() - }) - }) - }) - - it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() { - Helpers.async(function(done) { - sequelize.getQueryInterface().showAllTables().success(function(tableNames) { - tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) - expect(tableNames.length).toEqual(1) - done() - }) - }) - - Helpers.async(function(done) { - migrator.migrate({ method: 'down' }).success(function() { - sequelize.getQueryInterface().showAllTables().success(function(tableNames) { - tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) - expect(tableNames.length).toEqual(0) - done() - }).error(function(err){ console.log(err); done() }) - }).error(function(err){ console.log(err); done() }) - }) - }) - - it("executes the empty migration #20111130161100", function() { - Helpers.async(function(done) { - setup({ from: 20111130161100, to: 20111130161100}) - done() - }) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - // this migration isn't actually testing anything but - // should not timeout - }) - }) - }) - - describe('renameTable', function() { - it("executes migration #20111205064000 and renames a table", function() { - Helpers.async(function(done) { - sequelize.getQueryInterface().showAllTables().success(function(tableNames) { - tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) - expect(tableNames.length).toEqual(1) - expect(tableNames[0]).toEqual('Person') - done() - }) - }) - - setup({from: 20111205064000, to: 20111205064000}) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - - Helpers.async(function(done) { - sequelize.getQueryInterface().showAllTables().success(function(tableNames) { - tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) - expect(tableNames.length).toEqual(1) - expect(tableNames[0]).toEqual('User') - done() - }) - }) - }) - }) - - describe('addColumn', function() { - it('adds a column to the user table', function() { - setup({from: 20111205064000, to: 20111205162700}) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - - Helpers.async(function(done) { - sequelize.getQueryInterface().describeTable('User').success(function(data) { - var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] - , isAdmin = data.filter(function(hash){ return hash.Field == 'isAdmin' })[0] - , shopId = data.filter(function(hash){ return hash.Field == 'shopId' })[0] - - expect(signature.Field).toEqual('signature') - expect(signature.Null).toEqual('NO') - - expect(isAdmin.Field).toEqual('isAdmin') - expect(isAdmin.Null).toEqual('NO') - expect(isAdmin.Default).toEqual('0') - - expect(shopId.Field).toEqual('shopId') - expect(shopId.Null).toEqual('YES') - - done() - }).error(function(err) { - console.log(err) - }) - }) - }) - }) - - describe('removeColumn', function() { - it('removes the shopId column from user', function() { - setup({from: 20111205064000, to: 20111206061400}) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - - Helpers.async(function(done) { - sequelize.getQueryInterface().describeTable('User').success(function(data) { - var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] - , isAdmin = data.filter(function(hash){ return hash.Field == 'isAdmin' })[0] - , shopId = data.filter(function(hash){ return hash.Field == 'shopId' })[0] - - expect(signature.Field).toEqual('signature') - expect(signature.Null).toEqual('NO') - - expect(isAdmin.Field).toEqual('isAdmin') - expect(isAdmin.Null).toEqual('NO') - expect(isAdmin.Default).toEqual('0') - - expect(shopId).toBeFalsy() - - done() - }).error(function(err) { - console.log(err) - }) - }) - - }) - }) - - describe('changeColumn', function() { - it('changes the signature column from user to default "signature" + notNull', function() { - setup({from: 20111205064000, to: 20111206063000}) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - - Helpers.async(function(done) { - sequelize.getQueryInterface().describeTable('User').success(function(data) { - var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] - - expect(signature.Field).toEqual('signature') - expect(signature.Type).toEqual('varchar(255)') - expect(signature.Null).toEqual('NO') - expect(signature.Default).toEqual('Signature') - - done() - }).error(function(err) { - console.log(err) - }) - }) - }) - }) - }) - - describe('renameColumn', function() { - it("renames the signature column from user to sig", function() { - setup({from: 20111117063700, to: 20111206163300}) - - Helpers.async(function(done) { - migrator.migrate().success(done).error(function(err) { console.log(err) }) - }) - - Helpers.async(function(done) { - sequelize.getQueryInterface().describeTable('User').success(function(data) { - var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] - , sig = data.filter(function(hash){ return hash.Field == 'sig' })[0] - - expect(signature).toBeFalsy() - expect(sig).toBeTruthy() - - done() - }).error(function(err) { - console.log(err) - }) - }) - }) - }) -}) - diff --git a/spec/assets/migrations/20111117063700-createPerson.js b/spec/assets/migrations/20111117063700-createPerson.js new file mode 100644 index 000000000000..241f0026e2a0 --- /dev/null +++ b/spec/assets/migrations/20111117063700-createPerson.js @@ -0,0 +1,15 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.createTable('Person', { + name: DataTypes.STRING, + isBetaMember: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + } + }) + }, + down: function(migration) { + migration.dropTable('Person') + } +} diff --git a/spec/assets/migrations/20111130161100-emptyMigration.js b/spec/assets/migrations/20111130161100-emptyMigration.js new file mode 100644 index 000000000000..ade8b7735ea9 --- /dev/null +++ b/spec/assets/migrations/20111130161100-emptyMigration.js @@ -0,0 +1,4 @@ +module.exports = { + up: function() {}, + down: function() {} +} diff --git a/spec/assets/migrations/20111205064000-renamePersonToUser.js b/spec/assets/migrations/20111205064000-renamePersonToUser.js new file mode 100644 index 000000000000..af2b8aa0546b --- /dev/null +++ b/spec/assets/migrations/20111205064000-renamePersonToUser.js @@ -0,0 +1,9 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.renameTable('Person', 'User') + }, + + down: function(migration, DataTypes) { + migration.renameTable('User', 'Person') + } +} diff --git a/spec/assets/migrations/20111205162700-addSignatureColumnToUser.js b/spec/assets/migrations/20111205162700-addSignatureColumnToUser.js new file mode 100644 index 000000000000..94c9fa6181e3 --- /dev/null +++ b/spec/assets/migrations/20111205162700-addSignatureColumnToUser.js @@ -0,0 +1,13 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.addColumn('User', 'signature', DataTypes.TEXT) + migration.addColumn('User', 'shopId', { type: DataTypes.INTEGER, allowNull: true }) + migration.addColumn('User', 'isAdmin', { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false }) + }, + + down: function(migration, DataTypes) { + migration.removeColumn('User', 'signature') + migration.removeColumn('User', 'shopId') + migration.removeColumn('User', 'isAdmin') + } +} diff --git a/spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js b/spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js new file mode 100644 index 000000000000..40eb92556b46 --- /dev/null +++ b/spec/assets/migrations/20111206061400-removeShopIdColumnFromUser.js @@ -0,0 +1,9 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.removeColumn('User', 'shopId') + }, + + down: function(migration, DataTypes) { + migration.addColumn('User', 'shopId', { type: DataTypes.INTEGER, allowNull: true }) + } +} diff --git a/spec/assets/migrations/20111206063000-changeSignatureColumnOfUserToMendatory.js b/spec/assets/migrations/20111206063000-changeSignatureColumnOfUserToMendatory.js new file mode 100644 index 000000000000..2b3726a9c1c9 --- /dev/null +++ b/spec/assets/migrations/20111206063000-changeSignatureColumnOfUserToMendatory.js @@ -0,0 +1,11 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.changeColumn('User', 'signature', { + type: DataTypes.STRING, + allowNull: false, + defaultValue: 'Signature' + }) + }, + + down: function(migration, DataTypes) {} +} diff --git a/spec/assets/migrations/20111206163300-renameSignatureColumnOfUserToSig.js b/spec/assets/migrations/20111206163300-renameSignatureColumnOfUserToSig.js new file mode 100644 index 000000000000..22184aa9d8c4 --- /dev/null +++ b/spec/assets/migrations/20111206163300-renameSignatureColumnOfUserToSig.js @@ -0,0 +1,9 @@ +module.exports = { + up: function(migration, DataTypes) { + migration.renameColumn('User', 'signature', 'sig') + }, + + down: function(migration, DataTypes) { + migration.renameColumn('User', 'sig', 'signature') + } +} diff --git a/spec/assets/project.js b/spec/assets/project.js new file mode 100644 index 000000000000..f2eeced8a1f8 --- /dev/null +++ b/spec/assets/project.js @@ -0,0 +1,5 @@ +module.exports = function(sequelize, DataTypes) { + return sequelize.define('Project' + parseInt(Math.random() * 9999999999999999), { + name: DataTypes.STRING + }) +} \ No newline at end of file diff --git a/spec/associations/belongs-to.spec.js b/spec/associations/belongs-to.spec.js index 2891cb033027..8653283f42dc 100644 --- a/spec/associations/belongs-to.spec.js +++ b/spec/associations/belongs-to.spec.js @@ -8,7 +8,7 @@ if (typeof require === 'function') { buster.spec.expose() buster.testRunner.timeout = 500 -describe("[" + Helpers.getTestDialectTeaser() + "] BelongsTo", function() { +describe(Helpers.getTestDialectTeaser("BelongsTo"), function() { before(function(done) { Helpers.initTests({ beforeComplete: function(sequelize) { diff --git a/spec/associations/has-many.spec.js b/spec/associations/has-many.spec.js index a70c4fa84a8d..f298f0c9ce1f 100644 --- a/spec/associations/has-many.spec.js +++ b/spec/associations/has-many.spec.js @@ -8,7 +8,7 @@ if (typeof require === 'function') { buster.spec.expose() buster.testRunner.timeout = 500 -describe("[" + Helpers.getTestDialectTeaser() + "] HasMany", function() { +describe(Helpers.getTestDialectTeaser("HasMany"), function() { before(function(done) { var self = this diff --git a/spec/associations/has-one.spec.js b/spec/associations/has-one.spec.js index 4ffa165466b0..0791c637881b 100644 --- a/spec/associations/has-one.spec.js +++ b/spec/associations/has-one.spec.js @@ -8,7 +8,7 @@ if (typeof require === 'function') { buster.spec.expose() buster.testRunner.timeout = 1500 -describe("[" + Helpers.getTestDialectTeaser() + "] HasOne", function() { +describe(Helpers.getTestDialectTeaser("HasOne"), function() { before(function(done) { var self = this diff --git a/spec/associations/mixin.spec.js b/spec/associations/mixin.spec.js index d8367d7c2313..b20b1171c910 100644 --- a/spec/associations/mixin.spec.js +++ b/spec/associations/mixin.spec.js @@ -7,7 +7,7 @@ if (typeof require === 'function') { buster.spec.expose() -describe("[" + Helpers.getTestDialectTeaser() + "] Mixin", function() { +describe(Helpers.getTestDialectTeaser("Mixin"), function() { before(function(done) { Helpers.initTests({ dialect: dialect, diff --git a/spec/buster-helpers.js b/spec/buster-helpers.js index 1d1a76f10b6a..545bfec4ee6f 100644 --- a/spec/buster-helpers.js +++ b/spec/buster-helpers.js @@ -10,8 +10,17 @@ var BusterHelpers = module.exports = { var sequelize = this.createSequelizeInstance(options) this.clearDatabase(sequelize, function() { - options.beforeComplete && options.beforeComplete(sequelize, DataTypes) - options.onComplete && options.onComplete(sequelize, DataTypes) + if (options.context) { + options.context.sequelize = sequelize + } + + if (options.beforeComplete) { + options.beforeComplete(sequelize, DataTypes) + } + + if (options.onComplete) { + options.onComplete(sequelize, DataTypes) + } }) }, @@ -70,14 +79,14 @@ var BusterHelpers = module.exports = { return envDialect }, - getTestDialectTeaser: function() { + getTestDialectTeaser: function(moduleName) { var dialect = this.getTestDialect() if (process.env.DIALECT === 'postgres-native') { dialect = 'postgres-native' } - return dialect.toUpperCase() + return "[" + dialect.toUpperCase() + "] " + moduleName }, checkMatchForDialects: function(dialect, value, expectations) { diff --git a/spec/dao-factory.spec.js b/spec/dao-factory.spec.js index 3e42c7634072..2d1725bddc1e 100644 --- a/spec/dao-factory.spec.js +++ b/spec/dao-factory.spec.js @@ -7,7 +7,7 @@ if(typeof require === 'function') { buster.spec.expose() -describe("[" + Helpers.getTestDialectTeaser() + "] DAOFactory", function() { +describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { before(function(done) { Helpers.initTests({ dialect: dialect, diff --git a/spec/dao.spec.js b/spec/dao.spec.js index 2703da8108f7..265b7eaf1699 100644 --- a/spec/dao.spec.js +++ b/spec/dao.spec.js @@ -6,7 +6,7 @@ if(typeof require === 'function') { buster.spec.expose() -describe("[" + Helpers.getTestDialectTeaser() + "] DAO", function() { +describe(Helpers.getTestDialectTeaser("DAO"), function() { before(function(done) { var self = this diff --git a/spec/dao.validations.spec.js b/spec/dao.validations.spec.js index 460b742555b9..4d17c2d34bf7 100644 --- a/spec/dao.validations.spec.js +++ b/spec/dao.validations.spec.js @@ -7,7 +7,7 @@ if(typeof require === 'function') { buster.spec.expose() -describe("[" + Helpers.getTestDialectTeaser() + "] DAO", function() { +describe(Helpers.getTestDialectTeaser("DAO"), function() { describe('validations', function() { before(function(done) { Helpers.initTests({ diff --git a/spec-jasmine/migration.spec.js b/spec/migration.spec.js similarity index 72% rename from spec-jasmine/migration.spec.js rename to spec/migration.spec.js index dfe659070b0e..8c018fff5a3f 100644 --- a/spec-jasmine/migration.spec.js +++ b/spec/migration.spec.js @@ -1,12 +1,17 @@ -var config = require("./config/config") - , Sequelize = require("../index") - , sequelize = new Sequelize(config.mysql.database, config.mysql.username, config.mysql.password, { logging: false }) - , Helpers = new (require("./config/helpers"))(sequelize) - , Migrator = require("../lib/migrator") - , Migration = require("../lib/migration") - , _ = Sequelize.Utils._ +if(typeof require === 'function') { + const buster = require("buster") + , QueryChainer = require("../lib/query-chainer") + , CustomEventEmitter = require("../lib/emitters/custom-event-emitter") + , Helpers = require('./buster-helpers') + , dialect = Helpers.getTestDialect() + , Migrator = require("../lib/migrator") + , Migration = require("../lib/migration") +} -describe('Migration', function() { +buster.spec.expose() +buster.testRunner.timeout = 1000 + +describe(Helpers.getTestDialectTeaser("Migration"), function() { describe('migrationHasInterfaceCalls', function() { // the syntax in the following tests are correct // don't touch them! the functions will get stringified below diff --git a/spec/migrator.spec.js b/spec/migrator.spec.js new file mode 100644 index 000000000000..b0f27cc3d019 --- /dev/null +++ b/spec/migrator.spec.js @@ -0,0 +1,278 @@ +if(typeof require === 'function') { + const buster = require("buster") + , QueryChainer = require("../lib/query-chainer") + , CustomEventEmitter = require("../lib/emitters/custom-event-emitter") + , Helpers = require('./buster-helpers') + , dialect = Helpers.getTestDialect() + , Migrator = require("../lib/migrator") +} + +buster.spec.expose() +buster.testRunner.timeout = 1000 + +describe('=>'+Helpers.getTestDialectTeaser("Migrator"), function() { + before(function(done) { + this.init = function(options, callback) { + options = Helpers.Sequelize.Utils._.extend({ + path: __dirname + '/assets/migrations', + logging: false + }, options || {}) + + var migrator = new Migrator(this.sequelize, options) + + migrator + .findOrCreateSequelizeMetaDAO({ force: true }) + .success(function(SequelizeMeta) { + callback && callback(migrator, SequelizeMeta) + }) + .error(function(err) { console.log(err) }) + }.bind(this) + + Helpers.initTests({ onComplete: done, context: this }) + }) + + it("as", function() { + expect(1).toEqual(1) + }) + + describe('getUndoneMigrations', function() { + it("returns no files if timestamps are after the files timestamp", function(done) { + this.init({ from: 20120101010101 }, function(migrator) { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(0) + done() + }.bind(this)) + }.bind(this)) + }) + + it("returns only files between from and to", function(done) { + this.init({ from: 19700101000000, to: 20111117063700 }, function(migrator) { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(1) + expect(migrations[migrations.length - 1].filename).toEqual('20111117063700-createPerson.js') + done() + }.bind(this)) + }.bind(this)) + }) + + it("returns exactly the migration which is defined in from and to", function(done) { + this.init({ from: 20111117063700, to: 20111117063700 }, function(migrator) { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(1) + expect(migrations[migrations.length - 1].filename).toEqual('20111117063700-createPerson.js') + done() + }.bind(this)) + }.bind(this)) + }) + + it("returns also the file which is exactly options.from or options.to", function(done) { + this.init({ from: 20111117063700, to: 20111130161100 }, function(migrator) { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(2) + expect(migrations[0].filename).toEqual('20111117063700-createPerson.js') + expect(migrations[1].filename).toEqual('20111130161100-emptyMigration.js') + done() + }.bind(this)) + }.bind(this)) + }) + + it("returns all files to options.to if no options.from is defined", function(done) { + this.init({ to: 20111130161100 }, function(migrator) { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(2) + done() + }.bind(this)) + }.bind(this)) + }) + + it("returns all files from last migration id stored in database", function(done) { + this.init(undefined, function(migrator, SequelizeMeta) { + SequelizeMeta.create({ from: null, to: 20111117063700 }).success(function() { + migrator.getUndoneMigrations(function(err, migrations) { + expect(err).toBeNull() + expect(migrations.length).toEqual(6) + expect(migrations[0].filename).toEqual('20111130161100-emptyMigration.js') + done() + }.bind(this)) + }.bind(this)) + }.bind(this)) + }) + }) + + describe('migrations', function() { + before(function(done) { + this.init({ from: 20111117063700, to: 20111117063700 }, function(migrator) { + this.migrator = migrator + this.migrator.migrate().success(done) + }.bind(this)) + }) + + describe('executions', function() { + it("executes migration #20111117063700 and correctly creates the table", function(done) { + this.sequelize.getQueryInterface().showAllTables().success(function(tableNames) { + tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) + expect(tableNames).toEqual([ 'Person' ]) + done() + }) + }) + + it("executes migration #20111117063700 and correctly adds isBetaMember", function(done) { + this.sequelize.getQueryInterface().describeTable('Person').success(function(data) { + var fields = data.map(function(d) { return d.Field }).sort() + expect(fields).toEqual([ 'isBetaMember', 'name' ]) + done() + }) + }) + + it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function(done) { + this.sequelize.getQueryInterface().showAllTables().success(function(tableNames) { + tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) + expect(tableNames).toEqual([ 'Person' ]) + + this.migrator.migrate({ method: 'down' }).success(function() { + this.sequelize.getQueryInterface().showAllTables().success(function(tableNames) { + tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) + expect(tableNames).toEqual([]) + done() + }.bind(this)) + }.bind(this)) + }.bind(this)) + }) + + it("executes the empty migration #20111130161100", function(done) { + this.init({ from: 20111130161100, to: 20111130161100 }, function(migrator) { + // this migration isn't actually testing anything but + // should not timeout + + expect(1).toEqual(1) + + migrator + .migrate() + .success(done) + .error(function(err) { console.log(err) }) + }) + }) + }) + + describe('renameTable', function() { + before(function(done) { + this.init({ from: 20111117063700, to: 20111117063700 }, function(migrator) { + this.migrator = migrator + this.migrator.migrate().success(done) + }.bind(this)) + }) + + it("executes migration #20111205064000 and renames a table", function(done) { + this.sequelize.getQueryInterface().showAllTables().success(function(tableNames) { + tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) + expect(tableNames).toEqual([ 'Person' ]) + + this.init({ from: 20111205064000, to: 20111205064000 }, function(migrator) { + migrator.migrate().success(function() { + this.sequelize.getQueryInterface().showAllTables().success(function(tableNames) { + tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) + expect(tableNames).toEqual([ 'User' ]) + done() + }) + }.bind(this)) + }.bind(this)) + }.bind(this)) + }) + }) + + describe('addColumn', function() { + it('//adds a column to the user table', function(done) { + this.init({ from: 20111117063700, to: 20111205162700 }, function(migrator) { + migrator.migrate().success(function() { + this.sequelize.getQueryInterface().describeTable('User').success(function(data) { + console.log(data) + var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] + , isAdmin = data.filter(function(hash){ return hash.Field == 'isAdmin' })[0] + , shopId = data.filter(function(hash){ return hash.Field == 'shopId' })[0] + + expect(signature.Field).toEqual('signature') + expect(signature.Null).toEqual('NO') + + expect(isAdmin.Field).toEqual('isAdmin') + expect(isAdmin.Null).toEqual('NO') + expect(isAdmin.Default).toEqual('0') + + expect(shopId.Field).toEqual('shopId') + expect(shopId.Null).toEqual('YES') + + done() + }) + }.bind(this)) + }.bind(this)) + }) + }) + + describe('removeColumn', function() { + it('removes the shopId column from user', function(done) { + this.init({ to: 20111206061400 }, function(migrator) { + migrator.migrate().success(function(){ + this.sequelize.getQueryInterface().describeTable('User').success(function(data) { + var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] + , isAdmin = data.filter(function(hash){ return hash.Field == 'isAdmin' })[0] + , shopId = data.filter(function(hash){ return hash.Field == 'shopId' })[0] + + expect(signature.Field).toEqual('signature') + expect(signature.Null).toEqual('NO') + + expect(isAdmin.Field).toEqual('isAdmin') + expect(isAdmin.Null).toEqual('NO') + expect(isAdmin.Default).toEqual('0') + + expect(shopId).toBeFalsy() + + done() + }) + }.bind(this)) + }.bind(this)) + }) + }) + + describe('changeColumn', function() { + it('changes the signature column from user to default "signature" + notNull', function(done) { + this.init({ to: 20111206063000 }, function(migrator) { + migrator.migrate().success(function() { + this.sequelize.getQueryInterface().describeTable('User').success(function(data) { + var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] + + expect(signature.Field).toEqual('signature') + expect(signature.Type).toEqual('varchar(255)') + expect(signature.Null).toEqual('NO') + expect(signature.Default).toEqual('Signature') + + done() + }) + }.bind(this)) + }.bind(this)) + }) + }) + }) + + describe('renameColumn', function() { + it("renames the signature column from user to sig", function(done) { + this.init({ to: 20111206163300 }, function(migrator) { + migrator.migrate().success(function(){ + this.sequelize.getQueryInterface().describeTable('User').success(function(data) { + var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0] + , sig = data.filter(function(hash){ return hash.Field == 'sig' })[0] + + expect(signature).toBeFalsy() + expect(sig).toBeTruthy() + + done() + }) + }.bind(this)) + }.bind(this)) + }) + }) +}) + diff --git a/spec/query-chainer.spec.js b/spec/query-chainer.spec.js index 07e76ca70e72..c842debd6e23 100644 --- a/spec/query-chainer.spec.js +++ b/spec/query-chainer.spec.js @@ -9,7 +9,7 @@ if(typeof require === 'function') { buster.spec.expose() buster.testRunner.timeout = 1000 -describe("[" + Helpers.getTestDialectTeaser() + "] QueryChainer", function() { +describe(Helpers.getTestDialectTeaser("QueryChainer"), function() { before(function() { this.queryChainer = new QueryChainer() }) diff --git a/spec/sequelize.spec.js b/spec/sequelize.spec.js index 11a524dd3202..bf664efbfa54 100644 --- a/spec/sequelize.spec.js +++ b/spec/sequelize.spec.js @@ -7,7 +7,7 @@ if(typeof require === 'function') { buster.spec.expose() -describe("[" + Helpers.getTestDialectTeaser() + "] Sequelize", function() { +describe(Helpers.getTestDialectTeaser("Sequelize"), function() { before(function(done) { Helpers.initTests({ beforeComplete: function(sequelize) { this.sequelize = sequelize }.bind(this),