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

Commit b71da976 by joao.bortolozzo

FindOrCreate with CLS not using stored transaction

1 parent c708e857
...@@ -1641,6 +1641,10 @@ Model.prototype.findOrCreate = function(options) { ...@@ -1641,6 +1641,10 @@ Model.prototype.findOrCreate = function(options) {
); );
} }
if(this.sequelize.constructor.cls){
options.transaction = this.sequelize.constructor.cls.get('transaction');
}
var self = this var self = this
, internalTransaction = !options.transaction , internalTransaction = !options.transaction
, values , values
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, cls = require('continuation-local-storage')
, sinon = require('sinon')
, stub = sinon.stub
, Promise = require('bluebird');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findOrCreate', function () {
before(function () {
current.constructor.cls = cls.createNamespace('sequelize');
});
after(function () {
delete current.constructor.cls;
});
beforeEach(function(){
this.User = current.define('User', {}, {
name: 'John'
});
this.stub = stub(this.User.sequelize, 'transaction');
this.stub.returns(new Promise(function(){}));
});
afterEach(function(){
this.stub.restore();
});
it('should use transaction from cls if available', function () {
var options = {
where : {
name : '123'
}
};
this.User.findOrCreate(options);
expect(options).to.have.any.keys('transaction');
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!