Skip to content

Commit

Permalink
Add intégration test for migration creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Kunkle committed Jan 2, 2012
1 parent a04d86a commit 45e6fa6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ The above will run all migrations that haven't yet been run in the prod environm


## Defaults ## Defaults


## Migrations ## Migrations API


Below are examples of all the different migrations supported by db-migrate. Please note that not all migrations are supported by all databases. For example, SQLite does not support dropping columns. Below are examples of all the different migrations supported by db-migrate. Please note that not all migrations are supported by all databases. For example, SQLite does not support dropping columns.


Expand Down
88 changes: 0 additions & 88 deletions test/create.js

This file was deleted.

33 changes: 33 additions & 0 deletions test/helper/fsext.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
var fs = require('fs');
var fspath = require('path');

exports.rm_r = function rm_r(path, callback) {
fs.stat(path, function(err, stats) {
if (err) {
if (err.errno == 34) {
callback(null);
} else {
callback(err);
}
return;
}

if (stats.isFile()) {
fs.unlink(path, callback);
} else if (stats.isDirectory()) {
fs.readdir(path, function(err, files) {
if (files.length == 0) {
fs.rmdir(path, callback);
} else {
files.forEach(function(file, index) {
rm_r(fspath.join(path, file), function(err) {
if (index == files.length - 1) {
fs.rmdir(path, callback);
}
});
});
}
});
}
});
};
54 changes: 54 additions & 0 deletions test/integration/create.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,54 @@
var vows = require('vows');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var cp = require('child_process');
var fsext = require('../helper/fsext');
var dbmUtil = require('../../lib/util');


function wipeMigrations(callback) {
var dir = path.join(__dirname, 'migrations');
fsext.rm_r(dir, callback);
}

function dbMigrate() {
var args = dbmUtil.toArray(arguments);
var dbm = path.join(__dirname, '..', '..', 'bin', 'db-migrate');
args.unshift(dbm);
return cp.spawn('node', args, { cwd: __dirname });
}

vows.describe('create').addBatch({
'without a migration directory': {
topic: function() {
wipeMigrations(function(err) {
assert.isNull(err);
dbMigrate('create', 'first migration').on('exit', this.callback);
}.bind(this));
},

'does not cause an error': function(code) {
assert.isNull(code);
},

'will create a new migration directory': function(code) {
fs.stat(path.join(__dirname, 'migrations'), function(err, stats) {
assert.isNull(err);
assert.isTrue(stats.isDirectory());
});
},

'will create a new migration': function(code) {
fs.readdir(path.join(__dirname, 'migrations'), function(err, files) {
assert.isNull(err);
assert.isEqual(files.length, 1);
assert.match(file, /first-migration\.js$/);

var migration = require(path.join(__dirname, 'migrations', file));
assert.isNotNull(migration.up);
assert.isNotNull(migration.down);
});
}
}
}).export(module);

0 comments on commit 45e6fa6

Please sign in to comment.