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

Commit 8a9f3626 by Mick Hansen

refactor: change sql spys to logging spys

1 parent 2b342e2c
...@@ -75,7 +75,7 @@ module.exports = (function() { ...@@ -75,7 +75,7 @@ module.exports = (function() {
, promises = [] , promises = []
, unassociatedObjects; , unassociatedObjects;
defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields']); // Don't try to insert the transaction as an attribute in the through table defaultAttributes = Utils._.omit(defaultAttributes, ['transaction', 'hooks', 'individualHooks', 'ignoreDuplicates', 'validate', 'fields', 'logging']); // Don't try to insert the transaction as an attribute in the through table
unassociatedObjects = newAssociations.filter(function(obj) { unassociatedObjects = newAssociations.filter(function(obj) {
return !Utils._.find(oldAssociations, function(old) { return !Utils._.find(oldAssociations, function(old) {
......
...@@ -421,7 +421,8 @@ module.exports = (function() { ...@@ -421,7 +421,8 @@ module.exports = (function() {
var instance = this; var instance = this;
return instance[association.accessors.get]({}, { return instance[association.accessors.get]({}, {
transaction: (additionalAttributes || {}).transaction transaction: (additionalAttributes || {}).transaction,
logging: (additionalAttributes || {}).logging
}).then(function(oldAssociatedObjects) { }).then(function(oldAssociatedObjects) {
var Class = Object(association.through.model) === association.through.model ? HasManyDoubleLinked : HasManySingleLinked; var Class = Object(association.through.model) === association.through.model ? HasManyDoubleLinked : HasManySingleLinked;
return new Class(association, instance).injectSetter(oldAssociatedObjects, newAssociatedObjects, additionalAttributes); return new Class(association, instance).injectSetter(oldAssociatedObjects, newAssociatedObjects, additionalAttributes);
......
...@@ -523,7 +523,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -523,7 +523,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
return Article.create({ title: 'foo' }); return Article.create({ title: 'foo' });
}).bind({}).then(function(article) { }).bind({}).then(function(article) {
this.article = article; this.article = article;
return article.createLabel({ text: 'bar' }).on('sql', spy); return article.createLabel({ text: 'bar' }, {logging: spy});
}).then(function(label) { }).then(function(label) {
expect(spy.calledOnce).to.be.true; expect(spy.calledOnce).to.be.true;
expect(label.ArticleId).to.equal(this.article.id); expect(label.ArticleId).to.equal(this.article.id);
...@@ -689,11 +689,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -689,11 +689,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
return self.Task.create({ title: 'task2' }); return self.Task.create({ title: 'task2' });
}).then(function(task2) { }).then(function(task2) {
this.task2 = task2; this.task2 = task2;
return this.user.setTasks([this.task1, this.task2]).on('sql', spy).on('sql', _.after(2, function(sql) { return this.user.setTasks([this.task1, this.task2], {logging: spy});
// We don't care about SELECT, only UPDATE
expect(sql).to.have.string('UPDATE');
expect(sql).to.have.string('IN (1, 2)');
}));
}).then(function() { }).then(function() {
expect(spy).to.have.been.calledTwice; // Once for SELECT, once for UPDATE expect(spy).to.have.been.calledTwice; // Once for SELECT, once for UPDATE
}); });
...@@ -712,11 +708,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -712,11 +708,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
}).then(function(task2) { }).then(function(task2) {
return this.user.setTasks([this.task1, task2]); return this.user.setTasks([this.task1, task2]);
}).then(function() { }).then(function() {
return this.user.setTasks(null).on('sql', spy).on('sql', _.after(2, function(sql) { return this.user.setTasks(null, {logging: spy});
// We don't care about SELECT, only UPDATE
expect(sql).to.have.string('UPDATE');
expect(sql).to.have.string('IN (1, 2)');
}));
}).then(function() { }).then(function() {
expect(spy).to.have.been.calledTwice; // Once for SELECT, once for UPDATE expect(spy).to.have.been.calledTwice; // Once for SELECT, once for UPDATE
}); });
...@@ -1430,14 +1422,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -1430,14 +1422,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
this.Task.create({ id: 12, title: 'task1' }), this.Task.create({ id: 12, title: 'task1' }),
this.Task.create({ id: 15, title: 'task2' }) this.Task.create({ id: 15, title: 'task2' })
]).spread(function(user, task1, task2) { ]).spread(function(user, task1, task2) {
return user.setTasks([task1, task2]).on('sql', spy).on('sql', _.after(2, function(sql) { return user.setTasks([task1, task2], {logging: spy});
if (dialect === 'mssql') {
expect(sql).to.have.string('INSERT INTO [TasksUsers] ([TaskId],[UserId]) VALUES (12,1),(15,1)');
} else {
var tickChar = (Support.getTestDialect() === 'postgres') ? '"' : '`';
expect(sql).to.have.string('INSERT INTO %TasksUsers% (%TaskId%,%UserId%) VALUES (12,1),(15,1)'.replace(/%/g, tickChar));
}
}));
}).then(function() { }).then(function() {
expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for INSERT expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for INSERT
}); });
...@@ -1454,10 +1439,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -1454,10 +1439,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
]).spread(function(user, task1, task2) { ]).spread(function(user, task1, task2) {
return user.setTasks([task1, task2]).return (user); return user.setTasks([task1, task2]).return (user);
}).then(function(user) { }).then(function(user) {
return user.setTasks(null).on('sql', spy).on('sql', _.after(2, function(sql) { return user.setTasks(null, {logging: spy});
expect(sql).to.have.string('DELETE FROM');
expect(sql).to.match(/IN \(1, 2\)|IN \(2, 1\)/);
}));
}).then(function() { }).then(function() {
expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for DELETE expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for DELETE
}); });
...@@ -1663,8 +1645,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() { ...@@ -1663,8 +1645,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
var project = projects[0]; var project = projects[0];
expect(project).to.be.defined; expect(project).to.be.defined;
return self.user.removeProject(project).on('sql', function(sql) { return self.user.removeProject(project).return(project);
}).return (project);
}).then(function(project) { }).then(function(project) {
return self.user.setProjects([project]); return self.user.setProjects([project]);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!