Skip to content

Commit

Permalink
Added tests for .pooled
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalieWolfe committed Jul 9, 2015
1 parent 740d05c commit 818adc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/PromisePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,10 @@ PromisePool.prototype.pooled = function(decorated, priority){
var slice = Array.prototype.slice;
return function(){
var args = slice.call(arguments);
var wrappedSelf = this;
return self.acquire(function(client){
args.shift(client);
return decorated.apply(null, args);
args.unshift(client);
return decorated.apply(wrappedSelf, args);
}, priority);
};
};
Expand Down
36 changes: 34 additions & 2 deletions tests/unit/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,40 @@ describe('PromisePool', function(){
});

describe('#pooled', function(){
it('should wrap the function with an acquisition');
it('should call the wrapped function in the wrapper\'s context');
it('should wrap the function with an acquisition', function(){
var conn = null;
var func = pool.pooled(function(_conn, foo, bar){
conn = _conn;
foo.should.eql('foo');
bar.should.eql('bar');
return Promise.resolve('foobar');
});

func.should.be.a.function;
should.not.exist(conn);

return func('foo', 'bar').then(function(res){
res.should.eql('foobar');
should.exist(conn);
});
});

it('should call the wrapped function in the wrapper\'s context', function(){
var conn = null;
var obj = {
thisIsIt: true,
func: pool.pooled(function(_conn){
conn = _conn;
should.exist(this);
this.thisIsIt.should.be.true;
return Promise.resolve();
})
};

return obj.func('foo', 'bar').then(function(){
should.exist(conn);
});
});
});

describe('#length', function(){
Expand Down

0 comments on commit 818adc3

Please sign in to comment.