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

Commit e5f6adf8 by Daniel Durante

Fixed references in dao-factory.

1 parent 234c3d60
Showing with 27 additions and 36 deletions
...@@ -2368,30 +2368,27 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2368,30 +2368,27 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
describe('references', function() { describe('references', function() {
before(function(done) { before(function(done) {
this.Author = this.sequelize.define('author', { firstName: Sequelize.STRING }) this.sequelize = sequelize
done() done()
}) })
describe("use of existing dao factory", function() { it('uses an existing dao factory and references the author table', function(done) {
before(function(done) { var self = this
this.Post = this.sequelize.define('post', { , Author = self.sequelize.define('author', { firstName: Sequelize.STRING })
, Post = self.sequelize.define('post', {
title: Sequelize.STRING, title: Sequelize.STRING,
authorId: { authorId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
references: this.Author, references: Author,
referencesKey: "id" referencesKey: "id"
} }
}) })
this.Author.hasMany(this.Post) Author.hasMany(Post)
this.Post.belongsTo(this.Author) Post.belongsTo(Author)
done()
})
it('references the author table', function(done) { Author.sync({ force: true }).success(function() {
var self = this Post.sync({ force: true }).on('sql', function(sql) {
this.Author.sync({ force: true }).success(function() {
self.Post.sync({ force: true }).on('sql', function(sql) {
if (dialect === 'postgres') { if (dialect === 'postgres') {
expect(sql).toMatch(/"authorId" INTEGER REFERENCES "authors" \("id"\)/) expect(sql).toMatch(/"authorId" INTEGER REFERENCES "authors" \("id"\)/)
} else if (dialect === 'mysql') { } else if (dialect === 'mysql') {
...@@ -2406,11 +2403,12 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2406,11 +2403,12 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
}) })
})
describe('use of table name as string', function() { it('uses a table name as a string and references the author table', function(done) {
before(function(done) { this.timeout = 2500
this.Post = this.sequelize.define('post', { var self = this
, Author = self.sequelize.define('author', { firstName: Sequelize.STRING })
, Post = self.sequelize.define('post', {
title: Sequelize.STRING, title: Sequelize.STRING,
authorId: { authorId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
...@@ -2419,15 +2417,11 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2419,15 +2417,11 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
} }
}) })
this.Author.hasMany(this.Post) Author.hasMany(Post)
this.Post.belongsTo(this.Author) Post.belongsTo(Author)
done()
})
it('references the author table', function(done) { Author.sync( {force: true }).success(function() {
var self = this Post.sync({ force: true }).on('sql', function(sql) {
this.Author.sync({ force: true }).success(function() {
self.Post.sync({ force: true }).on('sql', function(sql) {
if (dialect === 'postgres') { if (dialect === 'postgres') {
expect(sql).toMatch(/"authorId" INTEGER REFERENCES "authors" \("id"\)/) expect(sql).toMatch(/"authorId" INTEGER REFERENCES "authors" \("id"\)/)
} else if (dialect === 'mysql') { } else if (dialect === 'mysql') {
...@@ -2442,14 +2436,12 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2442,14 +2436,12 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
}) })
})
describe('use of invalid table name', function() { it("emits an error event as the referenced table name is invalid", function(done) {
it("emits the error event as the referenced table name is invalid", function(done) { this.timeout = 2500
this.timeout = 3500
var self = this var self = this
, Author = self.sequelize.define('author', { firstName: Sequelize.STRING })
self.Post = self.sequelize.define('post', { , Post = self.sequelize.define('post', {
title: Sequelize.STRING, title: Sequelize.STRING,
authorId: { authorId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
...@@ -2458,11 +2450,11 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2458,11 +2450,11 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
} }
}) })
self.Author.hasMany(self.Post) Author.hasMany(Post)
self.Post.belongsTo(self.Author) Post.belongsTo(Author)
self.Author.sync({ force: true }).success(function() { Author.sync({ force: true }).success(function() {
self.Post.sync({ force: true }).success(function() { Post.sync({ force: true }).success(function() {
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
// sorry ... but sqlite is too stupid to understand whats going on ... // sorry ... but sqlite is too stupid to understand whats going on ...
expect(1).toEqual(1) expect(1).toEqual(1)
...@@ -2488,5 +2480,4 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -2488,5 +2480,4 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) })
}) })
}) })
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!