Skip to content

Commit

Permalink
fixes artch#7
Browse files Browse the repository at this point in the history
  • Loading branch information
artch committed Aug 25, 2013
1 parent ce34169 commit 7d17472
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/view-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

return function($scope) {

var currentScope, currentElement, onloadExp = tAttrs.onload || '', animate,
var currentScope, currentElement, currentSegment, onloadExp = tAttrs.onload || '', animate,
viewSegmentIndex = parseInt(tAttrs.appViewSegment);

try {
Expand All @@ -44,7 +44,7 @@

// Watching for the specified route segment and updating contents
$scope.$on('routeSegmentChange', function(event, args) {
if(args.index == viewSegmentIndex)
if(args.index == viewSegmentIndex && currentSegment != args.segment)
update(args.segment);
});

Expand All @@ -64,6 +64,8 @@

function update(segment) {

currentSegment = segment;

if(isDefault) {
isDefault = false;
tElement.replaceWith(anchor);
Expand Down
36 changes: 36 additions & 0 deletions test/unit/view-segment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,42 @@ describe('view-segment', function() {
expect(elm.find('> div').scope().ctrl).toBeDefined();
expect(elm.find('> div').scope().ctrl).toBe(elm.find('> div').controller());
})

it('should call the controller of a sub-segment only once', inject(function() {

var spy = jasmine.createSpy('controller');

$routeSegmentProvider.when('/3', 'section3.section31');
$routeSegmentProvider.segment('section3', {
template: '<div app:view-segment="1"></div>'
}).within().segment('section31', {
template: '<div></div>',
controller: spy
})

$location.path('/3');

$rootScope.$digest();
expect(spy.calls.length).toBe(1);
}))

it('should call the controller twice after reload', inject(function() {

var spy = jasmine.createSpy('controller');

$routeSegmentProvider.when('/3', 'section3');
$routeSegmentProvider.segment('section3', {
template: '<div></div>',
controller: spy
});
$location.path('/3');
$rootScope.$digest();

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

$rootScope.$digest();
expect(spy.calls.length).toBe(2);
}))


});
Expand Down

0 comments on commit 7d17472

Please sign in to comment.