Skip to content

Commit 9bc4e3d

Browse files
committed
Apply cfformat changes
1 parent 2ad44e4 commit 9bc4e3d

File tree

4 files changed

+185
-168
lines changed

4 files changed

+185
-168
lines changed

system/web/routing/Router.cfc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,21 +848,21 @@ component
848848
var actions = {};
849849
var matchingActions = isStruct( matchingRoute.action ) ? matchingRoute.action : {};
850850
structAppend( actions, matchingActions, true );
851-
if ( matchingRoute.event != "" ) {
852-
for ( var verb in matchingRoute.verbs ) {
853-
structInsert( actions, verb, matchingRoute.event );
854-
}
855-
}
851+
if ( matchingRoute.event != "" ) {
852+
for ( var verb in matchingRoute.verbs ) {
853+
structInsert( actions, verb, matchingRoute.event );
854+
}
855+
}
856856
var thisRouteActions = isStruct( thisRoute.action ) ? thisRoute.action : {};
857857
structAppend( actions, thisRouteActions, true );
858-
if ( thisRoute.event != "" ) {
859-
for ( var verb in thisRoute.verbs ) {
860-
structInsert( actions, verb, thisRoute.event );
861-
}
862-
}
858+
if ( thisRoute.event != "" ) {
859+
for ( var verb in thisRoute.verbs ) {
860+
structInsert( actions, verb, thisRoute.event );
861+
}
862+
}
863863
matchingRoute.action = actions;
864864
matchingRoute.verbs = structKeyList( actions );
865-
matchingRoute.event = "";
865+
matchingRoute.event = "";
866866
return this;
867867
}
868868

system/web/services/RoutingService.cfc

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -307,50 +307,50 @@ component extends="coldbox.system.web.services.BaseService" accessors="true" {
307307
if ( routeResults.route.module.len() ) {
308308
discoveredEvent = routeResults.route.module & ":" & discoveredEvent;
309309
}
310-
}
311-
312-
// Process HTTP Verbs
313-
if (
314-
routeResults.route.verbs.len()
315-
and
316-
!routeResults.route.verbs.listFindNoCase( httpMethod )
317-
) {
318-
// Mark as invalid HTTP Exception
319-
arguments.event.setIsInvalidHTTPMethod( true );
320-
if ( variables.log.canDebug() ) {
321-
variables.log.debug( "Invalid HTTP Method detected: #httpMethod#", routeResults.route );
322-
}
323-
}
324-
325-
// If the struct is empty, reset it to an empty string so it goes down the correct code path later on.
326-
if ( isStruct( routeResults.route.action ) && structIsEmpty( routeResults.route.action ) ) {
327-
routeResults.route.action = "";
328-
}
329-
330-
// Check if using HTTP method actions via struct
331-
if ( isStruct( routeResults.route.action ) ) {
332-
// Verify HTTP method used is valid
333-
if ( structKeyExists( routeResults.route.action, httpMethod ) ) {
334-
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action[ httpMethod ]#";
335-
// Send for logging in debug mode
336-
if ( variables.log.canDebug() ) {
337-
variables.log.debug(
338-
"Matched HTTP Method (#HTTPMethod#) to routed action: #routeResults.route.action[ httpMethod ]#"
339-
);
340-
}
341-
} else {
342-
// Mark as invalid HTTP Exception
343-
discoveredEvent &= ".onInvalidHTTPMethod";
344-
arguments.event.setIsInvalidHTTPMethod( true );
345-
if ( variables.log.canDebug() ) {
346-
variables.log.debug( "Invalid HTTP Method detected: #httpMethod#", routeResults.route );
347-
}
348-
}
349-
}
350-
// Simple value action
351-
else if ( !isStruct( routeREsults.route.action ) && routeResults.route.action.len() ) {
352-
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action#";
353-
}
310+
}
311+
312+
// Process HTTP Verbs
313+
if (
314+
routeResults.route.verbs.len()
315+
and
316+
!routeResults.route.verbs.listFindNoCase( httpMethod )
317+
) {
318+
// Mark as invalid HTTP Exception
319+
arguments.event.setIsInvalidHTTPMethod( true );
320+
if ( variables.log.canDebug() ) {
321+
variables.log.debug( "Invalid HTTP Method detected: #httpMethod#", routeResults.route );
322+
}
323+
}
324+
325+
// If the struct is empty, reset it to an empty string so it goes down the correct code path later on.
326+
if ( isStruct( routeResults.route.action ) && structIsEmpty( routeResults.route.action ) ) {
327+
routeResults.route.action = "";
328+
}
329+
330+
// Check if using HTTP method actions via struct
331+
if ( isStruct( routeResults.route.action ) ) {
332+
// Verify HTTP method used is valid
333+
if ( structKeyExists( routeResults.route.action, httpMethod ) ) {
334+
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action[ httpMethod ]#";
335+
// Send for logging in debug mode
336+
if ( variables.log.canDebug() ) {
337+
variables.log.debug(
338+
"Matched HTTP Method (#HTTPMethod#) to routed action: #routeResults.route.action[ httpMethod ]#"
339+
);
340+
}
341+
} else {
342+
// Mark as invalid HTTP Exception
343+
discoveredEvent &= ".onInvalidHTTPMethod";
344+
arguments.event.setIsInvalidHTTPMethod( true );
345+
if ( variables.log.canDebug() ) {
346+
variables.log.debug( "Invalid HTTP Method detected: #httpMethod#", routeResults.route );
347+
}
348+
}
349+
}
350+
// Simple value action
351+
else if ( !isStruct( routeREsults.route.action ) && routeResults.route.action.len() ) {
352+
discoveredEvent &= ( discoveredEvent == "" ? "" : "." ) & "#routeResults.route.action#";
353+
}
354354
// end if action exists
355355

356356
// See if View is Dispatched

tests/specs/web/routing/RouterTest.cfc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,18 @@ component extends="coldbox.system.testing.BaseModelTest" {
191191
3,
192192
"The registered route should have two actions"
193193
);
194-
expect( routes[ 1 ].event ).toBe( "", "The event must be empty for multiple HTTP verbs" );
195-
expect( routes[ 1 ].handler ).toBe( "", "No handler should be defined so the actions can define one" );
196-
expect( routes[ 1 ].action ).toBe( { "GET" : "Photos.index", "POST" : "Photos.create", "DELETE": "BulkPhotos.delete" } );
197-
var verbs = routes[ 1 ].verbs;
198-
listSort( verbs, "textnocase", "asc" );
194+
expect( routes[ 1 ].event ).toBe( "", "The event must be empty for multiple HTTP verbs" );
195+
expect( routes[ 1 ].handler ).toBe(
196+
"",
197+
"No handler should be defined so the actions can define one"
198+
);
199+
expect( routes[ 1 ].action ).toBe( {
200+
"GET" : "Photos.index",
201+
"POST" : "Photos.create",
202+
"DELETE" : "BulkPhotos.delete"
203+
} );
204+
var verbs = routes[ 1 ].verbs;
205+
listSort( verbs, "textnocase", "asc" );
199206
expect( verbs ).toBe( "DELETE,GET,POST" );
200207
} );
201208
} );

tests/specs/web/routing/RoutingServiceTest.cfc

Lines changed: 118 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -145,129 +145,139 @@
145145
} );
146146
} );
147147

148-
it( "can use a full event from the action block if no event or handler is defined", function() {
149-
var mockEvent = createMock( "coldbox.system.web.context.RequestContext" ).init(
150-
controller = getController(),
151-
properties = {
152-
defaultLayout : "Main.cfm",
153-
defaultView : "",
154-
eventName : "event",
155-
modules : {}
156-
}
157-
);
158-
159-
var routeResults = { "route": initRouteDefinition( overrides = {
160-
"handler": "",
161-
"event": "",
162-
"action": {
163-
"GET": "MyHandler.index",
164-
"POST": "MyOtherHandler.create"
165-
}
166-
} ), "params": {} };
148+
it( "can use a full event from the action block if no event or handler is defined", function(){
149+
var mockEvent = createMock( "coldbox.system.web.context.RequestContext" ).init(
150+
controller = getController(),
151+
properties = {
152+
defaultLayout : "Main.cfm",
153+
defaultView : "",
154+
eventName : "event",
155+
modules : {}
156+
}
157+
);
167158

168-
var discoveredEventGET = variables.routingService.processRoute(
169-
routeResults = routeResults,
170-
event = mockEvent,
171-
rc = mockEvent.getCollection(),
172-
prc = mockEvent.getPrivateCollection()
173-
);
159+
var routeResults = {
160+
"route" : initRouteDefinition(
161+
overrides = {
162+
"handler" : "",
163+
"event" : "",
164+
"action" : {
165+
"GET" : "MyHandler.index",
166+
"POST" : "MyOtherHandler.create"
167+
}
168+
}
169+
),
170+
"params" : {}
171+
};
174172

175-
expect( discoveredEventGET ).toBe( "MyHandler.index" );
173+
var discoveredEventGET = variables.routingService.processRoute(
174+
routeResults = routeResults,
175+
event = mockEvent,
176+
rc = mockEvent.getCollection(),
177+
prc = mockEvent.getPrivateCollection()
178+
);
176179

177-
mockEvent.$( "getHTTPMethod", "POST" );
180+
expect( discoveredEventGET ).toBe( "MyHandler.index" );
178181

179-
var discoveredEventPOST = variables.routingService.processRoute(
180-
routeResults = routeResults,
181-
event = mockEvent,
182-
rc = mockEvent.getCollection(),
183-
prc = mockEvent.getPrivateCollection()
184-
);
182+
mockEvent.$( "getHTTPMethod", "POST" );
185183

186-
expect( discoveredEventPOST ).toBe( "MyOtherHandler.create" );
187-
} );
184+
var discoveredEventPOST = variables.routingService.processRoute(
185+
routeResults = routeResults,
186+
event = mockEvent,
187+
rc = mockEvent.getCollection(),
188+
prc = mockEvent.getPrivateCollection()
189+
);
188190

189-
it( "appends a handler from a route definition if it exists", function() {
190-
var mockEvent = createMock( "coldbox.system.web.context.RequestContext" ).init(
191-
controller = getController(),
192-
properties = {
193-
defaultLayout : "Main.cfm",
194-
defaultView : "",
195-
eventName : "event",
196-
modules : {}
197-
}
198-
);
191+
expect( discoveredEventPOST ).toBe( "MyOtherHandler.create" );
192+
} );
199193

200-
var routeResults = { "route": initRouteDefinition( overrides = {
201-
"handler": "MyHandler",
202-
"event": "",
203-
"action": {
204-
"GET": "index",
205-
"POST": "create",
206-
"PUT": "update"
207-
}
208-
} ), "params": {} };
194+
it( "appends a handler from a route definition if it exists", function(){
195+
var mockEvent = createMock( "coldbox.system.web.context.RequestContext" ).init(
196+
controller = getController(),
197+
properties = {
198+
defaultLayout : "Main.cfm",
199+
defaultView : "",
200+
eventName : "event",
201+
modules : {}
202+
}
203+
);
209204

210-
var discoveredEventGET = variables.routingService.processRoute(
211-
routeResults = routeResults,
212-
event = mockEvent,
213-
rc = mockEvent.getCollection(),
214-
prc = mockEvent.getPrivateCollection()
215-
);
205+
var routeResults = {
206+
"route" : initRouteDefinition(
207+
overrides = {
208+
"handler" : "MyHandler",
209+
"event" : "",
210+
"action" : { "GET" : "index", "POST" : "create", "PUT" : "update" }
211+
}
212+
),
213+
"params" : {}
214+
};
216215

217-
expect( discoveredEventGET ).toBe( "MyHandler.index" );
216+
var discoveredEventGET = variables.routingService.processRoute(
217+
routeResults = routeResults,
218+
event = mockEvent,
219+
rc = mockEvent.getCollection(),
220+
prc = mockEvent.getPrivateCollection()
221+
);
218222

219-
mockEvent.$( "getHTTPMethod", "PUT" );
223+
expect( discoveredEventGET ).toBe( "MyHandler.index" );
220224

221-
var discoveredEventPOST = variables.routingService.processRoute(
222-
routeResults = routeResults,
223-
event = mockEvent,
224-
rc = mockEvent.getCollection(),
225-
prc = mockEvent.getPrivateCollection()
226-
);
225+
mockEvent.$( "getHTTPMethod", "PUT" );
227226

228-
expect( discoveredEventPOST ).toBe( "MyHandler.update" );
229-
} );
227+
var discoveredEventPOST = variables.routingService.processRoute(
228+
routeResults = routeResults,
229+
event = mockEvent,
230+
rc = mockEvent.getCollection(),
231+
prc = mockEvent.getPrivateCollection()
232+
);
230233

234+
expect( discoveredEventPOST ).toBe( "MyHandler.update" );
235+
} );
231236
} );
232237
}
233238

234-
/**
235-
* Returns a new route definition
236-
*/
237-
private struct function initRouteDefinition( struct overrides = {} ) {
238-
structAppend( arguments.overrides, {
239-
"action" : "", // The action to execute
240-
"append" : true, // Was this route appended or pre/prended
241-
"condition" : "", // The condition closure which must be true for the route to match
242-
// TODO: Consider deprecating this since now we have a `-regex()` placeholder
243-
"constraints" : {}, // If we have any regex constraints on placeholders.
244-
"domain" : "", // The domain attached to the route
245-
"event" : "", // The full event syntax to execute
246-
"handler" : "", // The handler to execute
247-
"headers" : {}, // The HTTP response headers to respond with
248-
"layout" : "", // The layout to proxy to
249-
"layoutModule" : "", // If the layout comes from a module
250-
"meta" : {}, // Route metadata if any
251-
"module" : "", // The module event we must execute
252-
"moduleRouting" : "", // This routes to a module
253-
"name" : "", // The named route
254-
"namespace" : "", // The namespace this route belongs to
255-
"namespaceRouting" : "", // This routes to a namespace
256-
"packageResolverExempt" : false, // If true, it does not resolve packages by convention, by default we do
257-
"pattern" : "", // The regex pattern used for matching
258-
"prc" : {}, // The PRC params to add incorporate if matched
259-
"rc" : {}, // The RC params to add incorporate if matched
260-
"redirect" : "", // The redirection location
261-
"response" : "", // Do we have an inline response closure
262-
"ssl" : false, // Are we forcing SSL
263-
"statusCode" : 200, // The response status code
264-
"statusText" : "Ok", // The response status text
265-
"valuePairTranslation" : true, // If we translate name-value pairs in the URL by convention
266-
"verbs" : "", // The HTTP Verbs allowed
267-
"view" : "", // The view to proxy to
268-
"viewModule" : "", // If the view comes from a module
269-
"viewNoLayout" : false // If we use a layout or not
270-
}, false );
271-
return arguments.overrides;
239+
/**
240+
* Returns a new route definition
241+
*/
242+
private struct function initRouteDefinition( struct overrides = {} ){
243+
structAppend(
244+
arguments.overrides,
245+
{
246+
"action" : "", // The action to execute
247+
"append" : true, // Was this route appended or pre/prended
248+
"condition" : "", // The condition closure which must be true for the route to match
249+
// TODO: Consider deprecating this since now we have a `-regex()` placeholder
250+
"constraints" : {}, // If we have any regex constraints on placeholders.
251+
"domain" : "", // The domain attached to the route
252+
"event" : "", // The full event syntax to execute
253+
"handler" : "", // The handler to execute
254+
"headers" : {}, // The HTTP response headers to respond with
255+
"layout" : "", // The layout to proxy to
256+
"layoutModule" : "", // If the layout comes from a module
257+
"meta" : {}, // Route metadata if any
258+
"module" : "", // The module event we must execute
259+
"moduleRouting" : "", // This routes to a module
260+
"name" : "", // The named route
261+
"namespace" : "", // The namespace this route belongs to
262+
"namespaceRouting" : "", // This routes to a namespace
263+
"packageResolverExempt" : false, // If true, it does not resolve packages by convention, by default we do
264+
"pattern" : "", // The regex pattern used for matching
265+
"prc" : {}, // The PRC params to add incorporate if matched
266+
"rc" : {}, // The RC params to add incorporate if matched
267+
"redirect" : "", // The redirection location
268+
"response" : "", // Do we have an inline response closure
269+
"ssl" : false, // Are we forcing SSL
270+
"statusCode" : 200, // The response status code
271+
"statusText" : "Ok", // The response status text
272+
"valuePairTranslation" : true, // If we translate name-value pairs in the URL by convention
273+
"verbs" : "", // The HTTP Verbs allowed
274+
"view" : "", // The view to proxy to
275+
"viewModule" : "", // If the view comes from a module
276+
"viewNoLayout" : false // If we use a layout or not
277+
},
278+
false
279+
);
280+
return arguments.overrides;
272281
}
282+
273283
}

0 commit comments

Comments
 (0)