Skip to content

Commit

Permalink
Reject migration if umzug can't find the migration method
Browse files Browse the repository at this point in the history
  • Loading branch information
leviathanbadger authored and jukkah committed Apr 20, 2017
1 parent 14a3bb7 commit 1163c1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ module.exports = redefine.Class(/** @lends Migration.prototype */{
*/
_exec: function (method, args) {
var migration = this.migration();
var fun = migration[method] || Bluebird.resolve;
var fun = migration[method];
if (!fun) return Bluebird.reject('Could not find migration method: ' + method);
var wrappedFun = this.options.migrations.wrap(fun);

return wrappedFun.apply(migration, args);
Expand Down
20 changes: 20 additions & 0 deletions test/index/execute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ describe('execute', function () {
expect(this.upStub.getCall(0).args).to.eql([1, 2, 3]);
});
});

describe('when the migration does not contain a migration method', function () {
beforeEach(function () {
this.oldup = this.migration.up;
delete this.migration.up;
});

it('rejects the promise', function () {
return this.migrate('up').bind(this).then(function () {
return Bluebird.reject('We should not end up here...');
}, function (err) {
expect(err).to.equal('Could not find migration method: up');
});
});

afterEach(function () {
this.migration.up = this.oldup;
delete this.oldup;
});
});
});

describe('migrations.wrap', function () {
Expand Down

0 comments on commit 1163c1b

Please sign in to comment.