Skip to content

Commit

Permalink
Fix a bug when reloading a segment does not recover after resolving e…
Browse files Browse the repository at this point in the history
…rror has gone
  • Loading branch information
artch committed May 13, 2014
1 parent 65a5463 commit ed11d58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/route-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ angular.module( 'route-segment', [] ).provider( '$routeSegment',
params: params,
locals: resolvedLocals,
reload: function() {
updateSegment(index, this).then(function(result) {
var originalSegment = getSegmentInChain(index, $routeSegment.name.split("."));
updateSegment(index, originalSegment).then(function(result) {
if(result.success != undefined)
broadcast(index);
})
Expand Down
21 changes: 21 additions & 0 deletions test/unit/route-segment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,27 @@ describe('route segment', function() {
expect(callback.calls[0].args[1].segment.params.stage).toBe('ERROR');
expect(callback.calls[0].args[1].segment.locals.error).toEqual('foo');
}))

it('should return to successful params after fail when error has gone', inject(function($q) {
resolve.param1 = function() { return $q.reject('foo'); }

$location.path('/3');

$rootScope.$digest();
expect(callback.calls[0].args[1].segment.params.stage).toBe('ERROR');

$routeSegment.chain[0].reload();

$rootScope.$digest();
expect(callback.calls[1].args[1].segment.params.stage).toBe('ERROR');

// Error has gone
resolve.param1 = function() { return $q.when(); }
$routeSegment.chain[0].reload();

$rootScope.$digest();
expect(callback.calls[2].args[1].segment.params.stage).toBe('OK');
}))

it('should auto-fetch failing templateUrl if resolving is failed', inject(function($q) {
resolve.param1 = function() { return $q.reject('foo'); }
Expand Down

0 comments on commit ed11d58

Please sign in to comment.