Skip to content

Commit 5d1694c

Browse files
committed
dont force controllers capitalization to fix brunotavares#8
As described in Sencha guidelines (http://docs.sencha.com/ext-js/4-1/#!/guide/command_code), class files can be organized in several subfolders that are not necessarly capitalized. Don't force this anymore. Fixed current jasmine tests and add related tests. (explicit is better than implicit)
1 parent 96e1a2f commit 5d1694c

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

Router.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Ext.define('Ext.ux.Router', {
159159
routeObj = {
160160
route : route,
161161
regex : rules.regex,
162-
controller : Ext.String.capitalize(rules.controller),
162+
controller : rules.controller,
163163
action : rules.action
164164
};
165165

@@ -183,13 +183,13 @@ Ext.define('Ext.ux.Router', {
183183
if (Ext.isString(rules)) {
184184
action = rules.split('#');
185185

186-
routeObj.controller = Ext.String.capitalize(action[0]);
186+
routeObj.controller = action[0];
187187
routeObj.action = action[1];
188188
routeObj.rules = undefined;
189189
}
190190
else {
191191

192-
routeObj.controller = Ext.String.capitalize(rules.controller);
192+
routeObj.controller = rules.controller;
193193
routeObj.action = rules.action;
194194

195195
delete rules.controller;
@@ -310,6 +310,7 @@ Ext.define('Ext.ux.Router', {
310310

311311
if (!controller && Ext.isDefined(Ext.global.console)) {
312312
Ext.global.console.error("[Ext.ux.Router] Controller not found ", route.controller);
313+
return false;
313314
}
314315
//</debug>
315316

@@ -318,6 +319,7 @@ Ext.define('Ext.ux.Router', {
318319
//<debug error>
319320
if (!controller[route.action] && Ext.isDefined(Ext.global.console)) {
320321
Ext.global.console.error("[Ext.ux.Router] Controller action not found ", route.controller, route.action);
322+
return false;
321323
}
322324
//</debug>
323325

@@ -359,4 +361,4 @@ function() {
359361
}
360362
}
361363
});
362-
});
364+
});

test/index.html

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@
2525
show: Ext.emptyFn,
2626
showAll: Ext.emptyFn
2727
});
28-
28+
29+
Ext.define('TestApp.controller.subfolder.Users', {
30+
extend: 'Ext.app.Controller',
31+
show: Ext.emptyFn,
32+
hide: Ext.emptyFn,
33+
});
34+
2935
function initApp(routes) {
3036

3137
app = Ext.create('Ext.app.Application',{
3238
name: 'TestApp',
33-
controllers: ['Users'],
39+
controllers: [
40+
'Users',
41+
'subfolder.Users'
42+
],
3443
routes: routes
3544
});
3645
}
@@ -53,7 +62,7 @@
5362

5463
beforeEach(function() {
5564
initApp({
56-
'users': 'users#index'
65+
'users': 'Users#index'
5766
});
5867
});
5968

@@ -80,8 +89,8 @@
8089

8190
beforeEach(function() {
8291
initApp({
83-
'' : 'users#index',
84-
'users/:id' : 'users#index'
92+
'' : 'Users#index',
93+
'users/:id' : 'Users#index'
8594
});
8695
});
8796

@@ -107,8 +116,8 @@
107116

108117
beforeEach(function() {
109118
initApp({
110-
'/' : 'users#index',
111-
'users/:id' : 'users#index'
119+
'/' : 'Users#index',
120+
'users/:id' : 'Users#index'
112121
});
113122
});
114123

@@ -136,7 +145,7 @@
136145
initApp({
137146
"users": {
138147
regex: /^(users?)(?:\/(\d+)(?:\.\.(\d+))?)?/,
139-
controller: 'users',
148+
controller: 'Users',
140149
action: 'index'
141150
}
142151
});
@@ -169,7 +178,7 @@
169178

170179
beforeEach(function() {
171180
initApp({
172-
'users/:id': 'users#show'
181+
'users/:id': 'Users#show'
173182
});
174183
});
175184

@@ -196,7 +205,7 @@
196205

197206
beforeEach(function() {
198207
initApp({
199-
'users/:id/:login': 'users#show'
208+
'users/:id/:login': 'Users#show'
200209
});
201210
});
202211

@@ -219,7 +228,7 @@
219228

220229
beforeEach(function() {
221230
initApp({
222-
'users/*names': 'users#showAll'
231+
'users/*names': 'Users#showAll'
223232
});
224233
});
225234

@@ -246,7 +255,7 @@
246255

247256
beforeEach(function() {
248257
initApp({
249-
'users/*ids/*names': 'users#showAll'
258+
'users/*ids/*names': 'Users#showAll'
250259
});
251260
});
252261

@@ -289,7 +298,7 @@
289298

290299
beforeEach(function() {
291300
initApp({
292-
'users/:id/*roles/:name/*groups': 'users#show'
301+
'users/:id/*roles/:name/*groups': 'Users#show'
293302
});
294303
});
295304

@@ -309,7 +318,7 @@
309318

310319
beforeEach(function() {
311320
initApp({
312-
'users/:id/:name/*roles/*groups': 'users#show'
321+
'users/:id/:name/*roles/*groups': 'Users#show'
313322
});
314323
});
315324

@@ -329,7 +338,7 @@
329338

330339
beforeEach(function() {
331340
initApp({
332-
'search/:query/p:page': 'users#index'
341+
'search/:query/p:page': 'Users#index'
333342
});
334343
});
335344

@@ -347,7 +356,7 @@
347356

348357
beforeEach(function() {
349358
initApp({
350-
'*first/complex-:part/*rest': 'users#index'
359+
'*first/complex-:part/*rest': 'Users#index'
351360
});
352361
});
353362

@@ -366,7 +375,7 @@
366375

367376
beforeEach(function() {
368377
initApp({
369-
':entity?*args': 'users#index'
378+
':entity?*args': 'Users#index'
370379
});
371380
});
372381

@@ -384,7 +393,7 @@
384393

385394
beforeEach(function() {
386395
initApp({
387-
'*anything': 'users#index'
396+
'*anything': 'Users#index'
388397
});
389398
});
390399

@@ -402,7 +411,7 @@
402411
beforeEach(function() {
403412
initApp({
404413
'users/:id': {
405-
controller: 'users',
414+
controller: 'Users',
406415
action: 'show',
407416
id: /^\d+$/
408417
}
@@ -439,7 +448,7 @@
439448
beforeEach(function() {
440449
initApp({
441450
'users/:id': {
442-
controller: 'users',
451+
controller: 'Users',
443452
action: 'show',
444453
id: function(value) {
445454
return value.match(/^\d+$/);
@@ -478,7 +487,7 @@
478487
beforeEach(function() {
479488
initApp({
480489
'users/:id': {
481-
controller: 'users',
490+
controller: 'Users',
482491
action: 'show',
483492
id: '456'
484493
}
@@ -503,7 +512,7 @@
503512
beforeEach(function() {
504513
initApp({
505514
'users/:id/:index': {
506-
controller: 'users',
515+
controller: 'Users',
507516
action: 'show',
508517
id: /^\d+$/,
509518
index: function(value) {
@@ -533,6 +542,27 @@
533542
});
534543

535544
});
545+
546+
describe("Routes with non-capitalized classes", function() {
547+
548+
beforeEach(function() {
549+
initApp({
550+
'users/show/:id' : 'subfolder.users#show',
551+
'users/hide/:id' : 'subfolder.Users#hide'
552+
});
553+
});
554+
555+
it("shouldn't match bad cased controller 'users/show/123'", function() {
556+
expect(Router.parse('users/show/123')).toBe(false);
557+
});
558+
559+
it("should match lowercase controller 'users/hide/123'", function() {
560+
expect(Router.parse('users/hide/123')).toEqual({
561+
id: "123"
562+
});
563+
});
564+
565+
});
536566

537567
});
538568

@@ -543,7 +573,7 @@
543573

544574
beforeEach(function() {
545575
initApp({
546-
'users/:id': 'users#show'
576+
'users/:id': 'Users#show'
547577
});
548578
});
549579

@@ -620,8 +650,8 @@
620650

621651
beforeEach(function() {
622652
initApp({
623-
'users/:id' : 'users#index',
624-
'users/:action' : 'users#show'
653+
'users/:id' : 'Users#index',
654+
'users/:action' : 'Users#show'
625655
});
626656
});
627657

@@ -663,7 +693,7 @@
663693

664694
it("should dispatch route 'users/:id' with 'users/1", function() {
665695
initApp({
666-
'users/:id': 'users#index'
696+
'users/:id': 'Users#index'
667697
});
668698

669699
Router.parse('users/1');
@@ -710,4 +740,4 @@
710740
</head>
711741
<body>
712742
</body>
713-
</html>
743+
</html>

0 commit comments

Comments
 (0)