Skip to content

Commit

Permalink
Fix a bug with camelCasing default segment names
Browse files Browse the repository at this point in the history
  • Loading branch information
artch committed Mar 12, 2015
1 parent 834a34f commit 60bf2ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/route-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod.provider( '$routeSegment',
* @returns {Object} The same level pointer.
*/
segment: function(name, params) {
segment[camelCase(name)] = {params: params};
segment[camelCase(name)] = {name: name, params: params};
lastAddedName = name;
return this;
},
Expand Down Expand Up @@ -296,7 +296,7 @@ mod.provider( '$routeSegment',
(function(i, children, index) {
if (children[i].params['default']) {
defaultChildUpdatePromise = defaultChildUpdatePromise.then(function () {
return updateSegment(index, {name: i, params: children[i].params})
return updateSegment(index, {name: children[i].name, params: children[i].params})
.then(function (result) {
if (result.success) broadcast(result.success);
});
Expand Down
32 changes: 16 additions & 16 deletions test/unit/route-segment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,28 +352,28 @@ describe('route segment', function() {
describe('default=true', function() {
beforeEach(function () {
$routeSegmentProvider.when('/3', 'section3');
$routeSegmentProvider.when('/3/1', 'section3.section31');
$routeSegmentProvider.when('/3/1/1', 'section3.section31.section311');
$routeSegmentProvider.when('/3/1/2', 'section3.section31.section312');
$routeSegmentProvider.when('/3/1', 'section3.section31-default');
$routeSegmentProvider.when('/3/1/1', 'section3.section31-default.section311');
$routeSegmentProvider.when('/3/1/2', 'section3.section31-default.section312-default');
$routeSegmentProvider.when('/3/2', 'section3.section32');
$routeSegmentProvider.segment('section3', {});
$routeSegmentProvider.within('section3').segment('section31', {default: true});
$routeSegmentProvider.within('section3').within('section31').segment('section311', {});
$routeSegmentProvider.within('section3').within('section31').segment('section312', {default: true});
$routeSegmentProvider.within('section3').segment('section31-default', {default: true});
$routeSegmentProvider.within('section3').within('section31-default').segment('section311', {});
$routeSegmentProvider.within('section3').within('section31-default').segment('section312-default', {default: true});
$routeSegmentProvider.within('section3').segment('section32', {});
});

it('should auto-select a child with default=true', function () {
$location.path('/3');

$rootScope.$digest();
expect($routeSegment.name).toBe('section3.section31.section312');
expect($routeSegment.name).toBe('section3.section31-default.section312-default');
expect($routeSegment.chain[0].name).toBe('section3');
expect($routeSegment.chain[1].name).toBe('section31');
expect($routeSegment.chain[2].name).toBe('section312');
expect($routeSegment.chain[1].name).toBe('section31-default');
expect($routeSegment.chain[2].name).toBe('section312-default');
expect(callback.calls[0].args[1].segment.name).toBe('section3');
expect(callback.calls[1].args[1].segment.name).toBe('section31');
expect(callback.calls[2].args[1].segment.name).toBe('section312');
expect(callback.calls[1].args[1].segment.name).toBe('section31-default');
expect(callback.calls[2].args[1].segment.name).toBe('section312-default');
});

it('should auto-select a child with default=true when coming from another child at the same level', function () {
Expand All @@ -382,15 +382,15 @@ describe('route segment', function() {
$location.path('/3');

$rootScope.$digest();
expect($routeSegment.name).toBe('section3.section31.section312');
expect($routeSegment.name).toBe('section3.section31-default.section312-default');
expect($routeSegment.chain[0].name).toBe('section3');
expect($routeSegment.chain[1].name).toBe('section31');
expect($routeSegment.chain[2].name).toBe('section312');
expect($routeSegment.chain[1].name).toBe('section31-default');
expect($routeSegment.chain[2].name).toBe('section312-default');
expect(callback.calls[0].args[1].segment.name).toBe('section3');
expect(callback.calls[1].args[1].segment.name).toBe('section32');
expect(callback.calls[2].args[1].segment).toBe(null);
expect(callback.calls[3].args[1].segment.name).toBe('section31');
expect(callback.calls[4].args[1].segment.name).toBe('section312');
expect(callback.calls[3].args[1].segment.name).toBe('section31-default');
expect(callback.calls[4].args[1].segment.name).toBe('section312-default');
})
});

Expand Down

0 comments on commit 60bf2ec

Please sign in to comment.