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

Commit f878edbc by Sascha Depold

Model#all is now a function

1 parent d1456c7d
......@@ -18,7 +18,7 @@ describe('ModelDefinition', function() {
it("should return all users", function() {
Helpers.async(function(done) {
User.all.on('success', function(users) {
User.all().on('success', function(users) {
done()
expect(users.length).toEqual(2)
}).on('failure', function(err) { console.log(err) })
......
......@@ -33,8 +33,8 @@ var initialize = function(options, callback) {
module.exports = {
'it should correctly add an association to the model': function(exit) {
initialize({taskCount:5, userCount:2}, function(Task, User) {
User.all.on('success', function(users) {
Task.all.on('success', function(tasks) {
User.all().on('success', function(users) {
Task.all().on('success', function(tasks) {
var user = users[0]
user.getTasks().on('success', function(_tasks) {
......@@ -53,8 +53,8 @@ module.exports = {
},
'it should correctly remove associated objects': function(exit) {
initialize({taskCount:5, userCount:2}, function(Task, User) {
User.all.on('success', function(users) {
Task.all.on('success', function(tasks) {
User.all().on('success', function(users) {
Task.all().on('success', function(tasks) {
var user = users[0]
user.getTasks().on('success', function(_tasks) {
......
......@@ -17,7 +17,7 @@ module.exports = {
'build should not create database entries': function(exit) {
initUsers(10, function(users, User) {
assert.eql(users.length, 10)
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 0)
exit(function(){})
})
......
......@@ -8,10 +8,10 @@ module.exports = {
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
User.create({name: 'hallo', bio: 'welt'}).on('success', function(u) {
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 1)
u.destroy().on('success', function() {
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 0)
exit(function(){})
})
......
......@@ -20,7 +20,7 @@ var initUsers = function(num, callback) {
module.exports = {
'all should return all created models': function(exit) {
initUsers(2, function(_, User) {
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 2)
exit(function(){})
})
......
......@@ -9,10 +9,10 @@ module.exports = {
User.sync({force: true}).on('success', function() {
var u = User.build({name: 'hallo', bio: 'welt'})
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 0)
u.save().on('success', function() {
User.all.on('success', function(users) {
User.all().on('success', function(users) {
assert.eql(users.length, 1)
assert.eql(users[0].name, 'hallo')
exit(function(){})
......
......@@ -44,7 +44,7 @@ module.exports = {
'it should add updatedAt and createdAt if timestamps is undefined or true': function() {
var User1 = sequelize.define('User' + config.rand(), {})
var User2 = sequelize.define('User' + config.rand(), {}, { timestamps: true })
assert.eql(User1.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
assert.eql(User2.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
},
......@@ -72,7 +72,7 @@ module.exports = {
assert.isDefined(User.doSmth)
assert.eql(User.doSmth(), 1)
assert.isUndefined(User.makeItSo)
assert.isDefined(User.build().makeItSo)
assert.eql(User.build().makeItSo(), 2)
},
......@@ -84,4 +84,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!