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

Commit f878edbc by Sascha Depold

Model#all is now a function

1 parent d1456c7d
...@@ -18,7 +18,7 @@ describe('ModelDefinition', function() { ...@@ -18,7 +18,7 @@ describe('ModelDefinition', function() {
it("should return all users", function() { it("should return all users", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
User.all.on('success', function(users) { User.all().on('success', function(users) {
done() done()
expect(users.length).toEqual(2) expect(users.length).toEqual(2)
}).on('failure', function(err) { console.log(err) }) }).on('failure', function(err) { console.log(err) })
......
...@@ -33,8 +33,8 @@ var initialize = function(options, callback) { ...@@ -33,8 +33,8 @@ var initialize = function(options, callback) {
module.exports = { module.exports = {
'it should correctly add an association to the model': function(exit) { 'it should correctly add an association to the model': function(exit) {
initialize({taskCount:5, userCount:2}, function(Task, User) { initialize({taskCount:5, userCount:2}, function(Task, User) {
User.all.on('success', function(users) { User.all().on('success', function(users) {
Task.all.on('success', function(tasks) { Task.all().on('success', function(tasks) {
var user = users[0] var user = users[0]
user.getTasks().on('success', function(_tasks) { user.getTasks().on('success', function(_tasks) {
...@@ -53,8 +53,8 @@ module.exports = { ...@@ -53,8 +53,8 @@ module.exports = {
}, },
'it should correctly remove associated objects': function(exit) { 'it should correctly remove associated objects': function(exit) {
initialize({taskCount:5, userCount:2}, function(Task, User) { initialize({taskCount:5, userCount:2}, function(Task, User) {
User.all.on('success', function(users) { User.all().on('success', function(users) {
Task.all.on('success', function(tasks) { Task.all().on('success', function(tasks) {
var user = users[0] var user = users[0]
user.getTasks().on('success', function(_tasks) { user.getTasks().on('success', function(_tasks) {
......
...@@ -17,7 +17,7 @@ module.exports = { ...@@ -17,7 +17,7 @@ module.exports = {
'build should not create database entries': function(exit) { 'build should not create database entries': function(exit) {
initUsers(10, function(users, User) { initUsers(10, function(users, User) {
assert.eql(users.length, 10) assert.eql(users.length, 10)
User.all.on('success', function(users) { User.all().on('success', function(users) {
assert.eql(users.length, 0) assert.eql(users.length, 0)
exit(function(){}) exit(function(){})
}) })
......
...@@ -8,10 +8,10 @@ module.exports = { ...@@ -8,10 +8,10 @@ module.exports = {
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT }) var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() { User.sync({force: true}).on('success', function() {
User.create({name: 'hallo', bio: 'welt'}).on('success', function(u) { 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) assert.eql(users.length, 1)
u.destroy().on('success', function() { u.destroy().on('success', function() {
User.all.on('success', function(users) { User.all().on('success', function(users) {
assert.eql(users.length, 0) assert.eql(users.length, 0)
exit(function(){}) exit(function(){})
}) })
......
...@@ -20,7 +20,7 @@ var initUsers = function(num, callback) { ...@@ -20,7 +20,7 @@ var initUsers = function(num, callback) {
module.exports = { module.exports = {
'all should return all created models': function(exit) { 'all should return all created models': function(exit) {
initUsers(2, function(_, User) { initUsers(2, function(_, User) {
User.all.on('success', function(users) { User.all().on('success', function(users) {
assert.eql(users.length, 2) assert.eql(users.length, 2)
exit(function(){}) exit(function(){})
}) })
......
...@@ -9,10 +9,10 @@ module.exports = { ...@@ -9,10 +9,10 @@ module.exports = {
User.sync({force: true}).on('success', function() { User.sync({force: true}).on('success', function() {
var u = User.build({name: 'hallo', bio: 'welt'}) 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) assert.eql(users.length, 0)
u.save().on('success', function() { 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.length, 1)
assert.eql(users[0].name, 'hallo') assert.eql(users[0].name, 'hallo')
exit(function(){}) exit(function(){})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!