@@ -493,4 +493,224 @@ describe('Commands:', function() {
493
493
. and . calledWith ( 'commandTwo' ) ;
494
494
} ) ;
495
495
} ) ;
496
+
497
+ describe ( 'when registering a command with `complyFor`, then executing it' , function ( ) {
498
+ beforeEach ( function ( ) {
499
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
500
+ this . callback = stub ( ) ;
501
+ this . Commands . complyFor ( this . CommandsTwo , 'myCommand' , this . callback ) ;
502
+ this . CommandsTwo . command ( 'myCommand' ) ;
503
+ } ) ;
504
+
505
+ it ( 'should execute the callback with the correct context' , function ( ) {
506
+ expect ( this . callback )
507
+ . to . have . been . calledOnce
508
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
509
+ } ) ;
510
+ } ) ;
511
+
512
+ describe ( 'when registering a command with `complyFor` and an event map, and then executing one of the commands' , function ( ) {
513
+ beforeEach ( function ( ) {
514
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
515
+ this . callbackOne = stub ( ) ;
516
+ this . callbackTwo = stub ( ) ;
517
+ this . Commands . complyFor ( this . CommandsTwo , {
518
+ commandOne : this . callbackOne ,
519
+ commandTwo : this . callbackTwo
520
+ } ) ;
521
+ this . CommandsTwo . command ( 'commandOne' ) ;
522
+ } ) ;
523
+
524
+ it ( 'should execute the callback with the correct context' , function ( ) {
525
+ expect ( this . callbackOne )
526
+ . to . have . been . calledOnce
527
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
528
+ } ) ;
529
+
530
+ it ( 'should not execute the callbacks not specified' , function ( ) {
531
+ expect ( this . callbackTwo ) . to . not . have . been . called ;
532
+ } ) ;
533
+ } ) ;
534
+
535
+ describe ( '`complyForOnce`' , function ( ) {
536
+ beforeEach ( function ( ) {
537
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
538
+ this . callback = stub ( ) ;
539
+ this . Commands . complyForOnce ( this . CommandsTwo , 'myCommand' , this . callback ) ;
540
+ this . CommandsTwo . command ( 'myCommand' ) ;
541
+ } ) ;
542
+
543
+ it ( 'should execute the callback with the correct context' , function ( ) {
544
+ expect ( this . callback )
545
+ . to . have . been . calledOnce
546
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
547
+ } ) ;
548
+
549
+ it ( 'should remove the reference from the original object' , function ( ) {
550
+ expect ( this . CommandsTwo . _commands ) . to . deep . equal ( { } ) ;
551
+ } ) ;
552
+ } ) ;
553
+
554
+ describe ( '`complyForOnce` with an event map' , function ( ) {
555
+ beforeEach ( function ( ) {
556
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
557
+ this . callbackOne = stub ( ) ;
558
+ this . callbackTwo = stub ( ) ;
559
+ this . Commands . complyForOnce ( this . CommandsTwo , {
560
+ commandOne : this . callbackOne ,
561
+ commandTwo : this . callbackTwo
562
+ } ) ;
563
+ this . CommandsTwo . command ( 'commandOne' ) ;
564
+ } ) ;
565
+
566
+ it ( 'should execute the callback with the correct context' , function ( ) {
567
+ expect ( this . callbackOne )
568
+ . to . have . been . calledOnce
569
+ . and . to . have . always . been . calledOn ( this . Commands ) ;
570
+ } ) ;
571
+
572
+ it ( 'should not execute the callbacks not specified' , function ( ) {
573
+ expect ( this . callbackTwo ) . to . not . have . been . called ;
574
+ } ) ;
575
+
576
+ it ( 'should remove the key for a' , function ( ) {
577
+ expect ( this . CommandsTwo . _commands ) . to . not . have . key ( 'commandOne' ) ;
578
+ } ) ;
579
+
580
+ it ( 'should keep the key for b' , function ( ) {
581
+ expect ( this . CommandsTwo . _commands ) . to . have . key ( 'commandTwo' ) ;
582
+ } ) ;
583
+ } ) ;
584
+
585
+ describe ( '`stopComplyingFor` with the first argument' , function ( ) {
586
+ beforeEach ( function ( ) {
587
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
588
+ this . CommandsThree = _ . clone ( Backbone . Radio . Commands ) ;
589
+ this . callbackOne = stub ( ) ;
590
+ this . callbackTwo = stub ( ) ;
591
+ this . callbackThree = stub ( ) ;
592
+ this . Commands . complyFor ( this . CommandsTwo , {
593
+ commandOne : this . callbackOne ,
594
+ commandTwo : this . callbackTwo
595
+ } ) ;
596
+ this . Commands . complyFor ( this . CommandsThree , 'commandThree' , this . callbackThree ) ;
597
+ this . Commands . stopComplyingFor ( this . CommandsTwo ) ;
598
+ } ) ;
599
+
600
+ it ( 'should only remove the callbacks on CommandsTwo' , function ( ) {
601
+ expect ( this . CommandsTwo . _commands ) . to . deep . equal ( { } ) ;
602
+ } ) ;
603
+
604
+ it ( 'should leave the callback on CommandThree' , function ( ) {
605
+ expect ( this . CommandsThree . _commands ) . to . have . key ( 'commandThree' ) ;
606
+ } ) ;
607
+ } ) ;
608
+
609
+ describe ( '`stopComplyingFor` with the first two arguments' , function ( ) {
610
+ beforeEach ( function ( ) {
611
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
612
+ this . CommandsThree = _ . clone ( Backbone . Radio . Commands ) ;
613
+ this . callbackOne = stub ( ) ;
614
+ this . callbackTwo = stub ( ) ;
615
+ this . callbackThree = stub ( ) ;
616
+ this . Commands . complyFor ( this . CommandsTwo , {
617
+ commandOne : this . callbackOne ,
618
+ commandTwo : this . callbackTwo
619
+ } ) ;
620
+ this . Commands . complyFor ( this . CommandsThree , 'commandThree' , this . callbackThree ) ;
621
+ this . Commands . stopComplyingFor ( this . CommandsTwo , 'commandOne' ) ;
622
+ } ) ;
623
+
624
+ it ( 'should only remove the proper callback on CommandsTwo' , function ( ) {
625
+ expect ( this . CommandsTwo . _commands ) . to . not . have . key ( 'commandOne' ) ;
626
+ } ) ;
627
+
628
+ it ( 'should not touch the other callback on CommandsTwo' , function ( ) {
629
+ expect ( this . CommandsTwo . _commands ) . to . have . key ( 'commandTwo' ) ;
630
+ } ) ;
631
+
632
+ it ( 'should leave the callback on CommandThree' , function ( ) {
633
+ expect ( this . CommandsThree . _commands ) . to . have . key ( 'commandThree' ) ;
634
+ } ) ;
635
+ } ) ;
636
+
637
+ describe ( '`stopComplyingFor` with the all three arguments' , function ( ) {
638
+ beforeEach ( function ( ) {
639
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
640
+ this . CommandsThree = _ . clone ( Backbone . Radio . Commands ) ;
641
+ this . callbackOne = stub ( ) ;
642
+ this . callbackTwo = stub ( ) ;
643
+ this . callbackThree = stub ( ) ;
644
+ this . Commands . complyFor ( this . CommandsTwo , {
645
+ commandOne : this . callbackOne ,
646
+ commandTwo : this . callbackTwo
647
+ } ) ;
648
+ this . Commands . complyFor ( this . CommandsThree , 'commandThree' , this . callbackThree ) ;
649
+ this . Commands . stopComplyingFor ( this . CommandsTwo , 'commandOne' , this . callbackOne ) ;
650
+ } ) ;
651
+
652
+ it ( 'should only remove the proper callback on CommandsTwo' , function ( ) {
653
+ expect ( this . CommandsTwo . _commands ) . to . not . have . key ( 'commandOne' ) ;
654
+ } ) ;
655
+
656
+ it ( 'should not touch the other callback on CommandsTwo' , function ( ) {
657
+ expect ( this . CommandsTwo . _commands ) . to . have . key ( 'commandTwo' ) ;
658
+ } ) ;
659
+
660
+ it ( 'should leave the callback on CommandThree' , function ( ) {
661
+ expect ( this . CommandsThree . _commands ) . to . have . key ( 'commandThree' ) ;
662
+ } ) ;
663
+ } ) ;
664
+
665
+ describe ( '`stopComplyingFor` with just the second argument' , function ( ) {
666
+ beforeEach ( function ( ) {
667
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
668
+ this . CommandsThree = _ . clone ( Backbone . Radio . Commands ) ;
669
+ this . callbackOne = stub ( ) ;
670
+ this . callbackTwo = stub ( ) ;
671
+ this . callbackThree = stub ( ) ;
672
+ this . Commands . complyFor ( this . CommandsTwo , {
673
+ commandOne : this . callbackOne ,
674
+ commandTwo : this . callbackOne
675
+ } ) ;
676
+ this . Commands . complyFor ( this . CommandsThree , {
677
+ commandTwo : this . callbackThree ,
678
+ commandThree : this . callbackThree
679
+ } ) ;
680
+ this . Commands . stopComplyingFor ( undefined , 'commandTwo' ) ;
681
+ } ) ;
682
+
683
+ it ( 'should only remove the proper callback on CommandsTwo' , function ( ) {
684
+ expect ( this . CommandsTwo . _commands ) . to . not . have . key ( 'commandTwo' ) ;
685
+ expect ( this . CommandsTwo . _commands ) . to . have . key ( 'commandOne' ) ;
686
+ } ) ;
687
+
688
+ it ( 'should not touch the other callback on CommandsTwo' , function ( ) {
689
+ expect ( this . CommandsThree . _commands ) . to . not . have . key ( 'commandTwo' ) ;
690
+ expect ( this . CommandsThree . _commands ) . to . have . key ( 'commandThree' ) ;
691
+ } ) ;
692
+ } ) ;
693
+
694
+ describe ( '`stopComplyingFor` with just the third argument' , function ( ) {
695
+ beforeEach ( function ( ) {
696
+ this . CommandsTwo = _ . clone ( Backbone . Radio . Commands ) ;
697
+ this . CommandsThree = _ . clone ( Backbone . Radio . Commands ) ;
698
+ this . callbackOne = stub ( ) ;
699
+ this . callbackTwo = stub ( ) ;
700
+ this . Commands . complyFor ( this . CommandsTwo , {
701
+ commandOne : this . callbackOne ,
702
+ commandTwo : this . callbackOne
703
+ } ) ;
704
+ this . Commands . complyFor ( this . CommandsThree , 'commandThree' , this . callbackTwo ) ;
705
+ this . Commands . stopComplyingFor ( undefined , undefined , this . callbackOne ) ;
706
+ } ) ;
707
+
708
+ it ( 'should only remove the proper callback on CommandsTwo' , function ( ) {
709
+ expect ( this . CommandsTwo . _commands ) . to . deep . equal ( { } ) ;
710
+ } ) ;
711
+
712
+ it ( 'should not touch the other callback on CommandsTwo' , function ( ) {
713
+ expect ( this . CommandsThree . _commands ) . to . have . key ( 'commandThree' ) ;
714
+ } ) ;
715
+ } ) ;
496
716
} ) ;
0 commit comments