diff --git a/test/integration/migrate/index.js b/test/integration/migrate/index.js index 2aaa28074e..6dc373955c 100644 --- a/test/integration/migrate/index.js +++ b/test/integration/migrate/index.js @@ -582,6 +582,72 @@ module.exports = function(knex) { }); }); + describe('knex.migrate.down', () => { + beforeEach(() => { + return knex.migrate.latest({ + directory: ['test/integration/migrate/test'], + }); + }); + + afterEach(() => { + return knex.migrate.rollback( + { directory: ['test/integration/migrate/test'] }, + true + ); + }); + + it('should only undo the last migration that was run if all migrations have run', function() { + return knex.migrate + .down({ + directory: ['test/integration/migrate/test'], + }) + .then(() => { + return knex('knex_migrations') + .select('*') + .then((data) => { + expect(data).to.have.length(1); + expect(path.basename(data[0].name)).to.equal( + '20131019235242_migration_1.js' + ); + }); + }); + }); + + it('should only undo the last migration that was run if there are other migrations that have not yet run', function() { + return knex.migrate + .down({ + directory: ['test/integration/migrate/test'], + }) + .then(() => { + return knex.migrate + .down({ + directory: ['test/integration/migrate/test'], + }) + .then(() => { + return knex('knex_migrations') + .select('*') + .then((data) => { + expect(data).to.have.length(0); + }); + }); + }); + }); + + it('should not error if all migrations have already been undone', function() { + return knex.migrate + .rollback({ directory: ['test/integration/migrate/test'] }, true) + .then(() => { + return knex.migrate + .down({ + directory: ['test/integration/migrate/test'], + }) + .then((data) => { + expect(data).to.be.an('array'); + }); + }); + }); + }); + after(function() { rimraf.sync(path.join(__dirname, './migration')); });