1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

Spec for Paloma.BeforeCallbackPeformer

This commit is contained in:
kbparagua 2016-03-18 00:53:28 +08:00
parent 662bbc8bff
commit ce3b147173
2 changed files with 74 additions and 3 deletions

View file

@ -0,0 +1,71 @@
describe('Paloma.BeforeCallbackPerformer', function(){
describe('#perform(action)', function(){
var Controller = Paloma.controller('MyController', {
before: [
'all -> doThat',
'singleCallback unknown -> doSomething',
'multiCallback -> doSomething doAnotherThing'
],
didThat: false,
didSomething: false,
didAnotherThing: false,
noCallback: function(){ console.log('I have no callback.'); },
singleCallback: function(){ console.log('Single callback.'); },
multiCallback: function(){ console.log('Multiple callbacks.')},
doThat: function(){ this.didThat = true; },
doSomething: function(){ this.didSomething = true; },
doAnotherThing: function(){ this.didAnotherThing = true; }
});
function itPerformsCallbackForAll(controller){
it('performs callback for all', function(){
expect(controller.didThat).toBeTruthy();
});
};
describe('when there is no matched callback', function(){
var controller = new Controller(),
performer = new Paloma.BeforeCallbackPerformer(controller);
performer.perform('noCallback');
it('will not perform any callback', function(){
expect(controller.didSomething).toBeFalsy();
});
itPerformsCallbackForAll(controller);
});
describe('when there is one matched callback', function(){
var controller = new Controller(),
performer = new Paloma.BeforeCallbackPerformer(controller);
performer.perform('singleCallback');
it('will perform the matched callback', function(){
expect(controller.didSomething).toBeTruthy();
});
itPerformsCallbackForAll(controller);
});
describe('when there is more than one matched callbacks', function(){
var controller = new Controller(),
performer = new Paloma.BeforeCallbackPerformer(controller);
performer.perform('multiCallback');
it('will perform all the matched callbacks', function(){
expect(controller.didSomething && controller.didAnotherThing).
toBeTruthy();
});
itPerformsCallbackForAll(controller);
});
});
});

View file

@ -12,8 +12,8 @@ Paloma.BeforeCallbackPerformer.prototype = {
},
_executeCallbacks: function(){
for (var i = 0, n = this._callbacks.length; i < n; i++)
this._executeCallback( this._callbacks[i] );
for (var i = 0, n = this._callbacks().length; i < n; i++)
this._executeCallback( this._callbacks()[i] );
},
_executeCallback: function(name){
@ -43,7 +43,7 @@ Paloma.BeforeCallbackPerformer.prototype = {
this._actionIsOn(parsedEntry.actions) ||
this._allIsOn(parsedEntry.actions)
)
return entry.callbacks;
return parsedEntry.callbacks;
return [];
},