Skip to content

Commit 0cc41c2

Browse files
committed
Ensure modules are applied to routing action structs when necessary
1 parent 7e2b86d commit 0cc41c2

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

system/web/routing/Router.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ component
2222
****************************************************************/
2323

2424
property
25-
name ="cachebox"
25+
name ="cachebox"
2626
inject ="cachebox"
2727
delegate="getCache";
2828
property
2929
name ="controller"
30-
inject ="coldbox"
30+
inject ="coldbox"
3131
delegate="relocate,runEvent,runRoute";
3232
property name="flash" inject="coldbox:flash";
3333
property name="logBox" inject="logbox";

system/web/services/RoutingService.cfc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,23 @@ component extends="coldbox.system.web.services.BaseService" accessors="true" {
295295
if ( isStruct( routeResults.route.action ) ) {
296296
// Verify HTTP method used is valid
297297
if ( structKeyExists( routeResults.route.action, httpMethod ) ) {
298-
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action[ httpMethod ]#";
298+
discoveredEvent &= ( discoveredEvent == "" ? "" : "." );
299+
// Do we have a module? If so, prefix it
300+
if ( routeResults.route.module.len() ) {
301+
discoveredEvent = routeResults.route.module & ":" & discoveredEvent;
302+
}
303+
discoveredEvent &= "#routeResults.route.action[ httpMethod ]#";
299304
// Send for logging in debug mode
300305
if ( variables.log.canDebug() ) {
301306
variables.log.debug(
302307
"Matched HTTP Method (#HTTPMethod#) to routed action: #routeResults.route.action[ httpMethod ]#"
303308
);
304309
}
305310
} else {
311+
// Do we have a module? If so, prefix it
312+
if ( routeResults.route.module.len() ) {
313+
discoveredEvent = routeResults.route.module & ":" & discoveredEvent;
314+
}
306315
// Mark as invalid HTTP Exception
307316
discoveredEvent &= ".onInvalidHTTPMethod";
308317
arguments.event.setIsInvalidHTTPMethod( true );
@@ -313,7 +322,12 @@ component extends="coldbox.system.web.services.BaseService" accessors="true" {
313322
}
314323
// Simple value action
315324
else if ( !isStruct( routeREsults.route.action ) && routeResults.route.action.len() ) {
316-
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action#";
325+
discoveredEvent &= ( discoveredEvent == "" ? "" : "." );
326+
// Do we have a module? If so, prefix it
327+
if ( routeResults.route.module.len() ) {
328+
discoveredEvent = routeResults.route.module & ":" & discoveredEvent;
329+
}
330+
discoveredEvent &= "#routeResults.route.action#";
317331
}
318332
// end if action exists
319333

tests/specs/web/routing/RoutingServiceTest.cfc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,53 @@
234234

235235
expect( discoveredEventPOST ).toBe( "MyHandler.update" );
236236
} );
237+
238+
it( "appends the module to the action struct if needed", function(){
239+
var mockEvent = createMock( "coldbox.system.web.context.RequestContext" ).init(
240+
controller = getController(),
241+
properties = {
242+
defaultLayout : "Main.cfm",
243+
defaultView : "",
244+
eventName : "event",
245+
modules : {}
246+
}
247+
);
248+
249+
var routeResults = {
250+
"route" : initRouteDefinition(
251+
overrides = {
252+
"handler" : "",
253+
"event" : "",
254+
"module" : "api-v1",
255+
"action" : {
256+
"GET" : "MyHandler.index",
257+
"POST" : "MyOtherHandler.create"
258+
}
259+
}
260+
),
261+
"params" : {}
262+
};
263+
264+
var discoveredEventGET = variables.routingService.processRoute(
265+
routeResults = routeResults,
266+
event = mockEvent,
267+
rc = mockEvent.getCollection(),
268+
prc = mockEvent.getPrivateCollection()
269+
);
270+
271+
expect( discoveredEventGET ).toBe( "api-v1:MyHandler.index" );
272+
273+
mockEvent.$( "getHTTPMethod", "POST" );
274+
275+
var discoveredEventPOST = variables.routingService.processRoute(
276+
routeResults = routeResults,
277+
event = mockEvent,
278+
rc = mockEvent.getCollection(),
279+
prc = mockEvent.getPrivateCollection()
280+
);
281+
282+
expect( discoveredEventPOST ).toBe( "api-v1:MyOtherHandler.create" );
283+
} );
237284
} );
238285
}
239286

0 commit comments

Comments
 (0)