|
145 | 145 | } ); |
146 | 146 | } ); |
147 | 147 |
|
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 | + ); |
167 | 158 |
|
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 | + }; |
174 | 172 |
|
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 | + ); |
176 | 179 |
|
177 | | - mockEvent.$( "getHTTPMethod", "POST" ); |
| 180 | + expect( discoveredEventGET ).toBe( "MyHandler.index" ); |
178 | 181 |
|
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" ); |
185 | 183 |
|
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 | + ); |
188 | 190 |
|
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 | + } ); |
199 | 193 |
|
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 | + ); |
209 | 204 |
|
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 | + }; |
216 | 215 |
|
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 | + ); |
218 | 222 |
|
219 | | - mockEvent.$( "getHTTPMethod", "PUT" ); |
| 223 | + expect( discoveredEventGET ).toBe( "MyHandler.index" ); |
220 | 224 |
|
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" ); |
227 | 226 |
|
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 | + ); |
230 | 233 |
|
| 234 | + expect( discoveredEventPOST ).toBe( "MyHandler.update" ); |
| 235 | + } ); |
231 | 236 | } ); |
232 | 237 | } |
233 | 238 |
|
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; |
272 | 281 | } |
| 282 | + |
273 | 283 | } |
0 commit comments