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

Commit 161c429e by sdepold

spec fix

1 parent e7b06830
...@@ -102,19 +102,23 @@ module.exports = (function() { ...@@ -102,19 +102,23 @@ module.exports = (function() {
var self = this var self = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
var SequelizeMeta = self.sequelize.modelManager.getModel('SequelizeMeta') var storedModel = self.sequelize.modelManager.getModel('SequelizeMeta')
, SequelizeMeta = storedModel
if(SequelizeMeta) { if(!storedModel) {
emitter.emit('success', SequelizeMeta)
} else {
SequelizeMeta = self.sequelize.define('SequelizeMeta', { SequelizeMeta = self.sequelize.define('SequelizeMeta', {
lastMigrationId: DataTypes.STRING lastMigrationId: DataTypes.STRING
}) })
}
// force sync when model has newly created or if syncOptions are passed
if(!storedModel || syncOptions) {
SequelizeMeta SequelizeMeta
.sync(syncOptions || {}) .sync(syncOptions || {})
.success(function() { emitter.emit('success', SequelizeMeta) }) .success(function() { emitter.emit('success', SequelizeMeta) })
.error(function(err) { emitter.emit('failure', err) }) .error(function(err) { emitter.emit('failure', err) })
} else {
emitter.emit('success', SequelizeMeta)
} }
}).run() }).run()
} }
......
...@@ -25,6 +25,18 @@ Helpers.prototype.drop = function() { ...@@ -25,6 +25,18 @@ Helpers.prototype.drop = function() {
}) })
} }
Helpers.prototype.dropAllTables = function() {
var self = this
this.async(function(done) {
self.sequelize
.getQueryInterface()
.dropAllTables()
.success(done)
.error(function(err) { console.log(err) })
})
}
Helpers.prototype.async = function(fct) { Helpers.prototype.async = function(fct) {
var done = false var done = false
runs(function() { runs(function() {
......
...@@ -26,21 +26,19 @@ describe('Migration', function() { ...@@ -26,21 +26,19 @@ describe('Migration', function() {
}, },
{ {
topic: function(migration, DataTypes) { topic: function(migration, DataTypes) {
migration migration.createTable()
.createTable()
}, },
expectation: true expectation: true
}, },
{ {
topic: function(migration, DataTypes) { topic: function(migration, DataTypes) {
migration. migration.createTable()
createTable()
}, },
expectation: true expectation: true
}, },
{ {
topic: function(migration, DataTypes) { topic: function(migration, DataTypes) {
migration . createTable () migration.createTable()
}, },
expectation: true expectation: true
} }
......
...@@ -16,15 +16,22 @@ describe('Migrator', function() { ...@@ -16,15 +16,22 @@ describe('Migrator', function() {
}, _options || {}) }, _options || {})
migrator = new Migrator(sequelize, options) migrator = new Migrator(sequelize, options)
migrator.findOrCreateSequelizeMetaModel({ force: true }).success(function(_SequelizeMeta) { migrator
SequelizeMeta = _SequelizeMeta .findOrCreateSequelizeMetaModel({ force: true })
done() .success(function(_SequelizeMeta) {
}) SequelizeMeta = _SequelizeMeta
done()
})
}) })
} }
beforeEach(function() { migrator = null }) var reset = function() {
afterEach(function() { migrator = null }) migrator = null
Helpers.dropAllTables()
}
beforeEach(reset)
afterEach(reset)
describe('getUndoneMigrations', function() { describe('getUndoneMigrations', function() {
it("returns no files if timestamps are after the files timestamp", function() { it("returns no files if timestamps are after the files timestamp", function() {
...@@ -103,17 +110,10 @@ describe('Migrator', function() { ...@@ -103,17 +110,10 @@ describe('Migrator', function() {
}) })
}) })
afterEach(function() {
migrator = null
Helpers.async(function(done) {
sequelize.getQueryInterface().dropAllTables().success(done).error(function(err) { console.log(err) })
})
})
it("executes migration #20111117063700 and correctly creates the table", function() { it("executes migration #20111117063700 and correctly creates the table", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.slice('SequelizeMeta', 1) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(1) expect(tableNames.length).toEqual(1)
expect(tableNames[0]).toEqual('Person') expect(tableNames[0]).toEqual('Person')
done() done()
...@@ -124,7 +124,7 @@ describe('Migrator', function() { ...@@ -124,7 +124,7 @@ describe('Migrator', function() {
it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() { it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.slice('SequelizeMeta', 1) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(1) expect(tableNames.length).toEqual(1)
done() done()
}) })
...@@ -133,7 +133,7 @@ describe('Migrator', function() { ...@@ -133,7 +133,7 @@ describe('Migrator', function() {
Helpers.async(function(done) { Helpers.async(function(done) {
migrator.migrate({ method: 'down' }).success(function() { migrator.migrate({ method: 'down' }).success(function() {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.slice('SequelizeMeta', 1) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(0) expect(tableNames.length).toEqual(0)
done() done()
}).error(function(err){ console.log(err); done() }) }).error(function(err){ console.log(err); done() })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!