Skip to content

Commit

Permalink
added "migration" event
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 22, 2011
1 parent 491c432 commit 54b0b79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/set.js
Expand Up @@ -146,6 +146,7 @@ Set.prototype._migrate = function(direction, fn){
return;
}

self.emit('migration', migration, direction);
migration[direction](function(err){
next(err, migrations.shift());
});
Expand Down
17 changes: 17 additions & 0 deletions test/test.migrate.js
Expand Up @@ -120,9 +120,26 @@ function testMigrationEvents() {
next();
});

var migrations = []
, expectedMigrations = [
'add guy ferrets'
, 'add girl ferrets'
, 'add emails'
, 'add dogs'
, 'adjust emails'];

set.on('migration', function(migration, direction){
migrations.push(migration.title);
direction.should.be.a('string');
});

set.up(function(){
db.pets[0].email.should.equal('tobi@lb.com');
migrations.should.eql(expectedMigrations);

migrations = [];
set.down(function(){
migrations.should.eql(expectedMigrations.reverse());
assertNoPets();
});
});
Expand Down

0 comments on commit 54b0b79

Please sign in to comment.