不要怂,就是干,撸起袖子干!

Commit 8f84cc19 by sdepold

migrationHasInterfaceCalls is now static function

1 parent 72c524c9
Showing with 20 additions and 23 deletions
...@@ -36,10 +36,28 @@ module.exports = (function() { ...@@ -36,10 +36,28 @@ module.exports = (function() {
return moment(Migration.getFormattedDateString(s), "YYYYMMDDHHmmss") return moment(Migration.getFormattedDateString(s), "YYYYMMDDHHmmss")
} }
Migration.migrationHasInterfaceCalls = function(func) {
var functionString = Utils.removeCommentsFromFunctionString(func.toString())
, hasCalls = false
for(var method in QueryInterface.prototype) {
var regex = new RegExp('[\\s\\n\\r]*\\.[\\s\\n\\r]*' + method)
hasCalls = hasCalls || regex.test(functionString)
}
return hasCalls
}
/////////////// ///////////////
// member ///// // member /////
/////////////// ///////////////
Object.defineProperty(Migration.prototype, 'migration', {
get: function() {
return require(this.path)
}
})
Migration.prototype.execute = function(options) { Migration.prototype.execute = function(options) {
var self = this var self = this
...@@ -54,29 +72,11 @@ module.exports = (function() { ...@@ -54,29 +72,11 @@ module.exports = (function() {
extendMigrationWithQueryInterfaceMethods.call(self, onSuccess) extendMigrationWithQueryInterfaceMethods.call(self, onSuccess)
func.call(null, self, DataTypes) func.call(null, self, DataTypes)
if(!self.migrationHasInterfaceCalls(func)) if(!Migration.migrationHasInterfaceCalls(func))
onSuccess() onSuccess()
}).run() }).run()
} }
Object.defineProperty(Migration.prototype, 'migration', {
get: function() {
return require(this.path)
}
})
Migration.prototype.migrationHasInterfaceCalls = function(func) {
var functionString = Utils.removeCommentsFromFunctionString(func.toString())
, hasCalls = false
for(var method in QueryInterface.prototype) {
var regex = new RegExp('[\\s\\n\\r]*\\.[\\s\\n\\r]*' + method)
hasCalls = hasCalls || regex.test(functionString)
}
return hasCalls
}
Migration.prototype.isBefore = function(dateString, options) { Migration.prototype.isBefore = function(dateString, options) {
options = Utils._.extend({ options = Utils._.extend({
withoutEquals: false withoutEquals: false
......
...@@ -8,9 +8,6 @@ var config = require("./config/config") ...@@ -8,9 +8,6 @@ var config = require("./config/config")
describe('Migration', function() { describe('Migration', function() {
describe('migrationHasInterfaceCalls', function() { describe('migrationHasInterfaceCalls', function() {
var migrator = new Migrator(sequelize)
, migration = new Migration(migrator, '/var/lib/20111117063700-asd.js')
// the syntax in the following tests are correct // the syntax in the following tests are correct
// don't touch them! the functions will get stringified below // don't touch them! the functions will get stringified below
var tests = [ var tests = [
...@@ -64,7 +61,7 @@ describe('Migration', function() { ...@@ -64,7 +61,7 @@ describe('Migration', function() {
tests.forEach(function(test) { tests.forEach(function(test) {
it('correctly result in ' + test.expectation + ' for ' + test.topic.toString(), function() { it('correctly result in ' + test.expectation + ' for ' + test.topic.toString(), function() {
expect(migration.migrationHasInterfaceCalls(test.topic)).toEqual(test.expectation) expect(Migration.migrationHasInterfaceCalls(test.topic)).toEqual(test.expectation)
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!