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

Commit b42d8a02 by sdepold

spec for addColumn

1 parent 0e3c0c19
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')
}
}
...@@ -22,6 +22,7 @@ describe('Migrator', function() { ...@@ -22,6 +22,7 @@ describe('Migrator', function() {
SequelizeMeta = _SequelizeMeta SequelizeMeta = _SequelizeMeta
done() done()
}) })
.error(function(err) { console.log(err) })
}) })
} }
...@@ -92,7 +93,7 @@ describe('Migrator', function() { ...@@ -92,7 +93,7 @@ describe('Migrator', function() {
SequelizeMeta.create({ lastMigrationId: '20111117063700' }).success(function() { SequelizeMeta.create({ lastMigrationId: '20111117063700' }).success(function() {
migrator.getUndoneMigrations(function(err, migrations) { migrator.getUndoneMigrations(function(err, migrations) {
expect(err).toBeFalsy() expect(err).toBeFalsy()
expect(migrations.length).toEqual(3) expect(migrations.length).toEqual(4)
expect(migrations[0].filename).toEqual('20111123060700-addBirthdateToPerson.js') expect(migrations[0].filename).toEqual('20111123060700-addBirthdateToPerson.js')
done() done()
}) })
...@@ -101,7 +102,7 @@ describe('Migrator', function() { ...@@ -101,7 +102,7 @@ describe('Migrator', function() {
}) })
}) })
describe('migrate', function() { describe('migrations', function() {
beforeEach(function() { beforeEach(function() {
setup({ from: 20111117063700, to: 20111117063700 }) setup({ from: 20111117063700, to: 20111117063700 })
...@@ -110,6 +111,7 @@ describe('Migrator', function() { ...@@ -110,6 +111,7 @@ describe('Migrator', function() {
}) })
}) })
describe('executions', function() {
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) {
...@@ -153,7 +155,9 @@ describe('Migrator', function() { ...@@ -153,7 +155,9 @@ describe('Migrator', function() {
// should not timeout // should not timeout
}) })
}) })
})
describe('renameTable', function() {
it("executes migration #20111205064000 and renames a table", function() { it("executes migration #20111205064000 and renames a table", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
...@@ -180,4 +184,38 @@ describe('Migrator', function() { ...@@ -180,4 +184,38 @@ describe('Migrator', function() {
}) })
}) })
}) })
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)
})
})
})
})
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!