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

Commit e22ba8ea by Sascha Depold

Merge branch 'mocha' of github.com:sequelize/sequelize into mocha

2 parents 72a25637 fbd05339
......@@ -112,7 +112,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it("doesn't create database entries", function(done) {
this.User.build({ username: 'John Wayne' })
this.User.all().success(function(users) {
expect(users.length).to.equal(0)
expect(users).to.have.length(0)
done()
})
})
......
......@@ -9,6 +9,11 @@ chai.Assertion.includeStack = true
if (dialect.match(/^postgres/)) {
describe('[POSTGRES Specific] associations', function() {
beforeEach(function(done) {
this.sequelize.options.quoteIdentifier = true
done()
})
describe('many-to-many', function() {
describe('where tables have the same prefix', function() {
it("should create a table wp_table1wp_table2s", function(done) {
......@@ -46,7 +51,10 @@ if (dialect.match(/^postgres/)) {
})
describe('HasMany', function() {
describe('addDAO / getDAO', function() {
beforeEach(function(done) {
var self = this
//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.Task = this.sequelize.define('Task' + config.rand(), { name: DataTypes.STRING })
......@@ -73,6 +81,10 @@ if (dialect.match(/^postgres/)) {
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.Task.all().success(function(_tasks) {
self.user = _users[0]
self.task = _tasks[0]
done()
})
})
......@@ -80,20 +92,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 +111,38 @@ if (dialect.match(/^postgres/)) {
})
describe('removeDAO', function() {
beforeEach(function(done) {
it("should correctly remove associated objects", function(done) {
var self = this
, users = []
, tasks = []
self.user = null
self.tasks = null
//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.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.Task.all().success(function(_tasks) {
self.user = _users[0]
self.task = _tasks[0]
self.users = _users
self.tasks = _tasks
done()
})
})
})
it("should correctly remove associated objects", function(done) {
var self = this
self.user.getTasks().on('success', function(__tasks) {
expect(__tasks).to.have.length(0)
......@@ -149,4 +162,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!