-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add intégration test for migration creation.
- Loading branch information
Jeff Kunkle
committed
Jan 2, 2012
1 parent
a04d86a
commit 45e6fa6
Showing
4 changed files
with
88 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |||
} | |||
}); | |||
}); | |||
} | |||
}); | |||
} | |||
}); | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |