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

Commit 1091f202 by Jan Aagaard Meier

Added dropping all tables to sync when force is true, and removed sync statement…

…s from n:m constraint tests
1 parent 982d2060
...@@ -387,6 +387,10 @@ module.exports = (function() { ...@@ -387,6 +387,10 @@ module.exports = (function() {
// Topologically sort by foreign key constraints to give us an appropriate // Topologically sort by foreign key constraints to give us an appropriate
// creation order // creation order
if (this.options.force) {
chainer.add(this, 'drop')
}
this.daoFactoryManager.forEachDAO(function(dao) { this.daoFactoryManager.forEachDAO(function(dao) {
if (dao) { if (dao) {
chainer.add(dao, 'sync', [options]) chainer.add(dao, 'sync', [options])
......
...@@ -44,20 +44,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -44,20 +44,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Article.hasMany(Label) Article.hasMany(Label)
sequelize.drop().success(function () { sequelize.sync({ force: true }).success(function() {
sequelize.sync({ force: true }).success(function() { Article.create({ title: 'foo' }).success(function(article) {
Article.create({ title: 'foo' }).success(function(article) { Label.create({ text: 'bar' }).success(function(label) {
Label.create({ text: 'bar' }).success(function(label) { sequelize.transaction(function(t) {
sequelize.transaction(function(t) { article.setLabels([ label ], { transaction: t }).success(function() {
article.setLabels([ label ], { transaction: t }).success(function() { Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].hasLabel(label).success(function(hasLabel) {
articles[0].hasLabel(label).success(function(hasLabel) { expect(hasLabel).to.be.false
expect(hasLabel).to.be.false Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].hasLabel(label, { transaction: t }).success(function(hasLabel) {
articles[0].hasLabel(label, { transaction: t }).success(function(hasLabel) { expect(hasLabel).to.be.true
expect(hasLabel).to.be.true t.rollback().success(function() { done() })
t.rollback().success(function() { done() })
})
}) })
}) })
}) })
...@@ -139,20 +137,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -139,20 +137,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Article.hasMany(Label) Article.hasMany(Label)
sequelize.drop().success(function () { sequelize.sync({ force: true }).success(function() {
sequelize.sync({ force: true }).success(function() { Article.create({ title: 'foo' }).success(function(article) {
Article.create({ title: 'foo' }).success(function(article) { Label.create({ text: 'bar' }).success(function(label) {
Label.create({ text: 'bar' }).success(function(label) { sequelize.transaction(function(t) {
sequelize.transaction(function(t) { article.setLabels([ label ], { transaction: t }).success(function() {
article.setLabels([ label ], { transaction: t }).success(function() { Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].hasLabels([ label ]).success(function(hasLabel) {
articles[0].hasLabels([ label ]).success(function(hasLabel) { expect(hasLabel).to.be.false
expect(hasLabel).to.be.false Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].hasLabels([ label ], { transaction: t }).success(function(hasLabel) {
articles[0].hasLabels([ label ], { transaction: t }).success(function(hasLabel) { expect(hasLabel).to.be.true
expect(hasLabel).to.be.true t.rollback().success(function() { done() })
t.rollback().success(function() { done() })
})
}) })
}) })
}) })
...@@ -411,22 +407,20 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -411,22 +407,20 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
this.Article.hasMany(this.Label) this.Article.hasMany(this.Label)
this.sequelize.drop().success(function () { self.sequelize.sync({ force: true }).success(function() {
self.sequelize.sync({ force: true }).success(function() { var chainer = new Sequelize.Utils.QueryChainer([
var chainer = new Sequelize.Utils.QueryChainer([ self.Article.create({ title: 'Article' }),
self.Article.create({ title: 'Article' }), self.Label.create({ text: 'Awesomeness', until: '2014-01-01 01:00:00' }),
self.Label.create({ text: 'Awesomeness', until: '2014-01-01 01:00:00' }), self.Label.create({ text: 'Epicness', until: '2014-01-03 01:00:00' })
self.Label.create({ text: 'Epicness', until: '2014-01-03 01:00:00' }) ])
])
chainer.run().success(function(results, article, label1, label2) {
chainer.run().success(function(results, article, label1, label2) { article.setLabels([label1, label2]).success(function() {
article.setLabels([label1, label2]).success(function() { article.getLabels({where: ['until > ?', moment('2014-01-02').toDate()]}).success(function(labels) {
article.getLabels({where: ['until > ?', moment('2014-01-02').toDate()]}).success(function(labels) { expect(labels).to.be.instanceof(Array)
expect(labels).to.be.instanceof(Array) expect(labels).to.have.length(1)
expect(labels).to.have.length(1) expect(labels[0].text).to.equal('Epicness')
expect(labels[0].text).to.equal('Epicness') done()
done()
})
}) })
}) })
}) })
...@@ -566,20 +560,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -566,20 +560,18 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
Article.hasMany(Label) Article.hasMany(Label)
Label.hasMany(Article) Label.hasMany(Article)
sequelize.drop().success(function () { sequelize.sync({ force: true }).success(function() {
sequelize.sync({ force: true }).success(function() { Article.create({ title: 'foo' }).success(function(article) {
Article.create({ title: 'foo' }).success(function(article) { Label.create({ text: 'bar' }).success(function(label) {
Label.create({ text: 'bar' }).success(function(label) { sequelize.transaction(function(t) {
sequelize.transaction(function(t) { article.setLabels([ label ], { transaction: t }).success(function() {
article.setLabels([ label ], { transaction: t }).success(function() { Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].getLabels().success(function(labels) {
articles[0].getLabels().success(function(labels) { expect(labels).to.have.length(0)
expect(labels).to.have.length(0) Article.all({ transaction: t }).success(function(articles) {
Article.all({ transaction: t }).success(function(articles) { articles[0].getLabels({ transaction: t }).success(function(labels) {
articles[0].getLabels({ transaction: t }).success(function(labels) { expect(labels).to.have.length(1)
expect(labels).to.have.length(1) t.rollback().success(function() { done() })
t.rollback().success(function() { done() })
})
}) })
}) })
}) })
......
...@@ -277,15 +277,12 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -277,15 +277,12 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.Worker = self.sequelize.define('Worker', { name: Sequelize.STRING }) self.Worker = self.sequelize.define('Worker', { name: Sequelize.STRING })
this.init = function(callback) { this.init = function(callback) {
self.sequelize.drop().success(function () { self.sequelize.sync({ force: true }).success(function() {
self.sequelize.sync({ force: true }).success(function() { self.Worker.create({ name: 'worker' }).success(function(worker) {
self.Worker.create({ name: 'worker' }).success(function(worker) { self.Task.create({ title: 'homework' }).success(function(task) {
self.Task.create({ title: 'homework' }).success(function(task) { self.worker = worker
self.worker = worker self.task = task
self.task = task callback()
callback()
})
}) })
}) })
}) })
...@@ -519,22 +516,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -519,22 +516,20 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
self.Group.hasOne(self.User) self.Group.hasOne(self.User)
self.sequelize.drop().success(function () { self.sequelize.sync({ force: true }).success(function() {
self.sequelize.sync({ force: true }).success(function() { self.Group.create({ name: 'people' }).success(function() {
self.Group.create({ name: 'people' }).success(function() { self.User.create({ username: 'someone', GroupPKeageroneName: 'people' }).success(function() {
self.User.create({ username: 'someone', GroupPKeageroneName: 'people' }).success(function() { self.Group.find({
self.Group.find({ where: {
where: { name: 'people'
name: 'people' },
}, include: [self.User]
include: [self.User] }).complete(function (err, someGroup) {
}).complete(function (err, someGroup) { expect(err).to.be.null
expect(err).to.be.null expect(someGroup).to.exist
expect(someGroup).to.exist expect(someGroup.name).to.equal('people')
expect(someGroup.name).to.equal('people') expect(someGroup.userPKeagerone.username).to.equal('someone')
expect(someGroup.userPKeagerone.username).to.equal('someone') done()
done()
})
}) })
}) })
}) })
...@@ -654,27 +649,25 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -654,27 +649,25 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.Contact.hasMany(self.Photo, { as: 'Photos' }) self.Contact.hasMany(self.Photo, { as: 'Photos' })
self.Contact.hasMany(self.PhoneNumber) self.Contact.hasMany(self.PhoneNumber)
self.sequelize.drop().success(function () { self.sequelize.sync({ force: true }).success(function() {
self.sequelize.sync({ force: true }).success(function() { self.Contact.create({ name: 'Boris' }).success(function(someContact) {
self.Contact.create({ name: 'Boris' }).success(function(someContact) { self.Photo.create({ img: 'img.jpg' }).success(function(somePhoto) {
self.Photo.create({ img: 'img.jpg' }).success(function(somePhoto) { self.PhoneNumber.create({ phone: '000000' }).success(function(somePhone1) {
self.PhoneNumber.create({ phone: '000000' }).success(function(somePhone1) { self.PhoneNumber.create({ phone: '111111' }).success(function(somePhone2) {
self.PhoneNumber.create({ phone: '111111' }).success(function(somePhone2) { someContact.setPhotos([somePhoto]).complete(function (err, data) {
someContact.setPhotos([somePhoto]).complete(function (err, data) { expect(err).to.be.null
expect(err).to.be.null someContact.setPhoneNumbers([somePhone1, somePhone2]).complete(function (err, data) {
someContact.setPhoneNumbers([somePhone1, somePhone2]).complete(function (err, data) { self.Contact.find({
self.Contact.find({ where: {
where: { name: 'Boris'
name: 'Boris' },
}, include: [self.PhoneNumber, { daoFactory: self.Photo, as: 'Photos' }]
include: [self.PhoneNumber, { daoFactory: self.Photo, as: 'Photos' }] }).complete(function (err, fetchedContact) {
}).complete(function (err, fetchedContact) { expect(err).to.be.null
expect(err).to.be.null expect(fetchedContact).to.exist
expect(fetchedContact).to.exist expect(fetchedContact.photos.length).to.equal(1)
expect(fetchedContact.photos.length).to.equal(1) expect(fetchedContact.phoneNumbers.length).to.equal(2)
expect(fetchedContact.phoneNumbers.length).to.equal(2) done()
done()
})
}) })
}) })
}) })
...@@ -702,24 +695,22 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -702,24 +695,22 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.Group.hasMany(self.User) self.Group.hasMany(self.User)
self.User.hasMany(self.Group) self.User.hasMany(self.Group)
self.sequelize.drop().success(function () { self.sequelize.sync({ force: true }).success(function() {
self.sequelize.sync({ force: true }).success(function() { self.User.create({ username: 'someone' }).success(function(someUser) {
self.User.create({ username: 'someone' }).success(function(someUser) { self.Group.create({ name: 'people' }).success(function(someGroup) {
self.Group.create({ name: 'people' }).success(function(someGroup) { someUser.setGroupPKeagerones([someGroup]).complete(function (err, data) {
someUser.setGroupPKeagerones([someGroup]).complete(function (err, data) { expect(err).to.be.null
self.User.find({
where: {
username: 'someone'
},
include: [self.Group]
}).complete(function (err, someUser) {
expect(err).to.be.null expect(err).to.be.null
self.User.find({ expect(someUser).to.exist
where: { expect(someUser.username).to.equal('someone')
username: 'someone' expect(someUser.groupPKeagerones[0].name).to.equal('people')
}, done()
include: [self.Group]
}).complete(function (err, someUser) {
expect(err).to.be.null
expect(someUser).to.exist
expect(someUser.username).to.equal('someone')
expect(someUser.groupPKeagerones[0].name).to.equal('people')
done()
})
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!