@@ -666,6 +666,60 @@ component extends="coldbox.system.testing.BaseModelTest" {
666666 } );
667667 } );
668668 } );
669+
670+ describe ( " Response placeholder pre-parsing" , function (){
671+ beforeEach ( function ( currentSpec ){
672+ router = createMock ( " coldbox.system.web.routing.Router" )
673+ .init ()
674+ .setController ( controller )
675+ .setLogBox ( controller .getLogBox () )
676+ .setLog ( controller .getLogBox ().getLogger ( this ) )
677+ .setCacheBox ( controller .getCacheBox () )
678+ .setWireBox ( controller .getWireBox () );
679+ } );
680+
681+ it ( " a route with a static string response pre-parses placeholders at registration" , function (){
682+ router .addRoute ( pattern = " /hello/:name" , response = " Hello {name}!" );
683+ var routes = router .getRoutes ();
684+ expect ( routes ).toHaveLength ( 1 );
685+ expect ( routes [ 1 ] ).toHaveKey ( " responsePlaceholders" );
686+ expect ( routes [ 1 ].responsePlaceholders ).toHaveLength ( 1 );
687+ expect ( routes [ 1 ].responsePlaceholders [ 1 ].token ).toBe ( " {name}" );
688+ expect ( routes [ 1 ].responsePlaceholders [ 1 ].key ).toBe ( " name" );
689+ } );
690+
691+ it ( " a route with multiple placeholders pre-parses all of them" , function (){
692+ router .addRoute ( pattern = " /greet/:name/:mod" , response = " Hello {name} from {mod}" );
693+ var routes = router .getRoutes ();
694+ expect ( routes [ 1 ].responsePlaceholders ).toHaveLength ( 2 );
695+ expect ( routes [ 1 ].responsePlaceholders [ 1 ].key ).toBe ( " name" );
696+ expect ( routes [ 1 ].responsePlaceholders [ 2 ].key ).toBe ( " mod" );
697+ } );
698+
699+ it ( " a route with no placeholders has an empty responsePlaceholders array" , function (){
700+ router .addRoute ( pattern = " /static" , response = " No placeholders here" );
701+ var routes = router .getRoutes ();
702+ expect ( routes [ 1 ].responsePlaceholders ).toBeArray ();
703+ expect ( routes [ 1 ].responsePlaceholders ).toHaveLength ( 0 );
704+ } );
705+
706+ it ( " a route with a closure response has an empty responsePlaceholders array" , function (){
707+ router .addRoute (
708+ pattern = " /closure" ,
709+ response = function ( event , rc , prc ){ return " hi" ; }
710+ );
711+ var routes = router .getRoutes ();
712+ expect ( routes [ 1 ].responsePlaceholders ).toBeArray ();
713+ expect ( routes [ 1 ].responsePlaceholders ).toHaveLength ( 0 );
714+ } );
715+
716+ it ( " a route with no response has an empty responsePlaceholders array" , function (){
717+ router .addRoute ( pattern = " /noop" , event = " main.index" );
718+ var routes = router .getRoutes ();
719+ expect ( routes [ 1 ].responsePlaceholders ).toBeArray ();
720+ expect ( routes [ 1 ].responsePlaceholders ).toHaveLength ( 0 );
721+ } );
722+ } );
669723 }
670724
671725}
0 commit comments