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

Commit 5b2bbf4f by Meg Sharkey

Merge remote-tracking branch 'sequelize/master'

2 parents 0ccbc17e 6d1bd3fc
......@@ -76,7 +76,7 @@ if(program.migrate) {
options = _.extend(options, { logging: false })
var sequelize = new Sequelize(config.database, config.username, config.password, options)
, migratorOptions = { path: __dirname + '/../migrations' }
, migratorOptions = { path: migrationsPath }
, migrator = sequelize.getMigrator(migratorOptions)
if(program.undo) {
......
......@@ -4,7 +4,7 @@ module.exports = (function() {
var Query = function(database, callee, options) {
throw new Error('Constructor was not overwritten!')
}
Utils.addEventEmitter(Query)
Utils._.extend(Query.prototype, require("../emitters/custom-event-emitter").prototype)
Query.prototype.run = function(sql) {
throw new Error("The run method wasn't overwritten!")
......
......@@ -2,8 +2,6 @@ var Utils = require("../../utils")
module.exports = (function() {
var Query = function(database, callee, options) {
var self = this
this.database = database
this.callee = callee
this.options = Utils._.extend({
......
......@@ -13,12 +13,14 @@ module.exports = (function() {
// delay the function call and return the emitter
setTimeout(function(){
self.fct.call(self, self)
}, 5)
}, 1)
return this
}
CustomEventEmitter.prototype.success = CustomEventEmitter.prototype.ok = function(fct) {
CustomEventEmitter.prototype.success =
CustomEventEmitter.prototype.ok =
function(fct) {
this.on('success', fct)
return this
}
......
......@@ -15,7 +15,6 @@ module.exports = (function() {
emitters = emitters || []
emitters.forEach(function(emitter) { self.add(emitter) })
}
Utils.addEventEmitter(QueryChainer)
QueryChainer.prototype.add = function(emitterOrKlass, method, params, options) {
if(!!method) {
......
......@@ -37,7 +37,7 @@ module.exports = (function() {
self.showAllTables().success(function(tableNames) {
tableNames.forEach(function(tableName) {
chainer.add(self.sequelize.getQueryInterface().dropTable(tableName))
chainer.add(self.dropTable(tableName))
})
chainer
.run()
......
......@@ -343,10 +343,45 @@ describe('ModelFactory', function() {
})
})
it("sorts the results", function() {
it("sorts the results via id", function() {
Helpers.Factories.User({name: 'user', bio: 'foobar'}, function(_users) {
users = _users
}, 2)
Helpers.async(function(done) {
setTimeout(function() {
User.create({name: 'user', bio: 'foobar'}).success(function(user) {
users.push(user)
done()
})
}, 2000)
})
Helpers.async(function(done) {
User.findAll({ order: "id DESC" }).success(function(users) {
expect(users[0].id).toBeGreaterThan(users[1].id)
expect(users[0].id).toBeGreaterThan(users[2].id)
done()
})
})
})
it("sorts the results via createdAt", function() {
Helpers.Factories.User({name: 'user', bio: 'foobar'}, function(_users) {
users = _users
}, 2)
Helpers.async(function(done) {
setTimeout(function() {
User.create({name: 'user', bio: 'foobar'}).success(function(user) {
users.push(user)
done()
})
}, 2000)
})
Helpers.async(function(done) {
User.findAll({ order: 'createdAt DESC' }).success(function(users) {
expect(users[0].id).toBeGreaterThan(users[2].id)
done()
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!