diff --git a/test_app/spec/javascripts/before_callback_performer_spec.js b/test_app/spec/javascripts/before_callback_performer_spec.js index 7054aea..2de9565 100644 --- a/test_app/spec/javascripts/before_callback_performer_spec.js +++ b/test_app/spec/javascripts/before_callback_performer_spec.js @@ -3,27 +3,29 @@ describe('Paloma.BeforeCallbackPerformer', function(){ var Controller = Paloma.controller('MyController', { before: [ - 'all -> doThat', + 'all -> initialize doThat', 'singleCallback unknown -> doSomething', 'multiCallback -> doSomething doAnotherThing' ], - didThat: false, - didSomething: false, - didAnotherThing: false, + initialize: function(){ + this.didWhat = []; + }, + + did: function(what){ return this.didWhat.indexOf(what) >= 0; }, 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; } + doThat: function(){ this.didWhat.push('that'); }, + doSomething: function(){ this.didWhat.push('something'); }, + doAnotherThing: function(){ this.didWhat.push('anotherThing') } }); function itPerformsCallbackForAll(controller){ it('performs callback for all', function(){ - expect(controller.didThat).toBeTruthy(); + expect( controller.did('that') ).toBeTruthy(); }); }; @@ -34,7 +36,7 @@ describe('Paloma.BeforeCallbackPerformer', function(){ performer.perform('noCallback'); it('will not perform any callback', function(){ - expect(controller.didSomething).toBeFalsy(); + expect( controller.did('something') ).toBeFalsy(); }); itPerformsCallbackForAll(controller); @@ -47,7 +49,7 @@ describe('Paloma.BeforeCallbackPerformer', function(){ performer.perform('singleCallback'); it('will perform the matched callback', function(){ - expect(controller.didSomething).toBeTruthy(); + expect( controller.did('something') ).toBeTruthy(); }); itPerformsCallbackForAll(controller); @@ -60,10 +62,16 @@ describe('Paloma.BeforeCallbackPerformer', function(){ performer.perform('multiCallback'); it('will perform all the matched callbacks', function(){ - expect(controller.didSomething && controller.didAnotherThing). + expect( controller.did('something') && controller.did('anotherThing') ). toBeTruthy(); }); + it('will perform the callbacks in order of definition', function(){ + expect(controller.didWhat).toEqual([ + 'that', 'something', 'anotherThing' + ]); + }); + itPerformsCallbackForAll(controller); });