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

Commit 2ac4a59b by Michael Schonfeld

use a custom emitter to throw the error; then test for it

1 parent 4bbd0aab
......@@ -789,6 +789,12 @@ module.exports = (function() {
options = Utils._.extend(options, fieldsOrOptions)
}
if(this.daoFactoryManager.sequelize.options.dialect === 'postgres' && options.ignoreDuplicates ) {
return new Utils.CustomEventEmitter(function(emitter) {
emitter.emit('error', new Error('Postgres does not support the \'ignoreDuplicates\' option.'))
}).run();
}
var self = this
, updatedAtAttr = Utils._.underscoredIf(self.options.updatedAt, self.options.underscored)
, createdAtAttr = Utils._.underscoredIf(self.options.createdAt, self.options.underscored)
......
......@@ -268,10 +268,6 @@ module.exports = (function() {
},
bulkInsertQuery: function(tableName, attrValueHashes, options) {
if(options && options.ignoreDuplicates) {
throw new Error("Postgres does not support the 'ignoreDuplicates' option.")
}
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES <%= tuples %> RETURNING *;"
, tuples = []
, serials = []
......
......@@ -1021,10 +1021,14 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
this.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'] }).success(function() {
data.push({ uniqueName: 'Michael', secretValue: '26' });
self.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'], ignoreDuplicates: true }).success(function() {
expect(err.message).to.match(/Postgres does not support the 'ignoreDuplicates' option./);
done()
});
self.User.bulkCreate(data, { fields: ['uniqueName', 'secretValue'], ignoreDuplicates: true }).error(function(err) {
console.log('err?', err)
expect(err).to.exist
expect(err.message).to.match(/Postgres does not support the \'ignoreDuplicates\' option./)
done();
})
})
})
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!