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

Commit fad4b39b by Daniel Durante

Postgres association tests should pass properly now.

1 parent 71c40d61
Showing with 38 additions and 24 deletions
...@@ -46,7 +46,10 @@ if (dialect.match(/^postgres/)) { ...@@ -46,7 +46,10 @@ if (dialect.match(/^postgres/)) {
}) })
describe('HasMany', function() { describe('HasMany', function() {
describe('addDAO / getDAO', function() {
beforeEach(function(done) { beforeEach(function(done) {
var self = this
//prevent periods from occurring in the table name since they are used to delimit (table.column) //prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define('User' + config.rand(), { name: DataTypes.STRING }) this.User = this.sequelize.define('User' + config.rand(), { name: DataTypes.STRING })
this.Task = this.sequelize.define('Task' + config.rand(), { name: DataTypes.STRING }) this.Task = this.sequelize.define('Task' + config.rand(), { name: DataTypes.STRING })
...@@ -73,6 +76,10 @@ if (dialect.match(/^postgres/)) { ...@@ -73,6 +76,10 @@ if (dialect.match(/^postgres/)) {
self.Task.sync({ force: true }).success(function() { self.Task.sync({ force: true }).success(function() {
self.User.bulkCreate(users).success(function() { self.User.bulkCreate(users).success(function() {
self.Task.bulkCreate(tasks).success(function() { self.Task.bulkCreate(tasks).success(function() {
self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) {
self.user = _users[0]
self.task = _tasks[0]
done() done()
}) })
}) })
...@@ -80,20 +87,6 @@ if (dialect.match(/^postgres/)) { ...@@ -80,20 +87,6 @@ if (dialect.match(/^postgres/)) {
}) })
}) })
}) })
describe('addDAO / getDAO', function() {
beforeEach(function(done) {
var self = this
self.user = null
self.task = null
self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) {
self.user = _users[0]
self.task = _tasks[0]
done()
})
}) })
}) })
...@@ -113,23 +106,38 @@ if (dialect.match(/^postgres/)) { ...@@ -113,23 +106,38 @@ if (dialect.match(/^postgres/)) {
}) })
describe('removeDAO', function() { describe('removeDAO', function() {
beforeEach(function(done) { it("should correctly remove associated objects", function(done) {
var self = this var self = this
, users = []
, tasks = []
self.user = null //prevent periods from occurring in the table name since they are used to delimit (table.column)
self.tasks = null this.User = this.sequelize.define('User' + config.rand(), { name: DataTypes.STRING })
this.Task = this.sequelize.define('Task' + config.rand(), { name: DataTypes.STRING })
this.users = null
this.tasks = null
this.User.hasMany(this.Task, {as:'Tasks'})
this.Task.hasMany(this.User, {as:'Users'})
for (var i = 0; i < 5; ++i) {
users[users.length] = {id: i, name: 'User' + Math.random()}
}
for (var x = 0; x < 5; ++x) {
tasks[tasks.length] = {id: i, name: 'Task' + Math.random()}
}
self.User.sync({ force: true }).success(function() {
self.Task.sync({ force: true }).success(function() {
self.User.bulkCreate(users).success(function() {
self.Task.bulkCreate(tasks).success(function() {
self.User.all().success(function(_users) { self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) { self.Task.all().success(function(_tasks) {
self.user = _users[0] self.user = _users[0]
self.task = _tasks[0]
self.users = _users
self.tasks = _tasks self.tasks = _tasks
done()
})
})
})
it("should correctly remove associated objects", function(done) {
var self = this
self.user.getTasks().on('success', function(__tasks) { self.user.getTasks().on('success', function(__tasks) {
expect(__tasks).to.have.length(0) expect(__tasks).to.have.length(0)
...@@ -149,4 +157,10 @@ if (dialect.match(/^postgres/)) { ...@@ -149,4 +157,10 @@ if (dialect.match(/^postgres/)) {
}) })
}) })
}) })
})
})
})
})
})
})
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!