Skip to content

Commit 9fcb16a

Browse files
Merge pull request #45 from jfturcot/token_destroy_event
Broadcast event oauth:tokenDestroy after a logout
2 parents 22296b9 + 7cbfdc7 commit 9fcb16a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

app/scripts/directives/oauth.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ directives.directive('oauth', function(AccessToken, Endpoint, Profile, $location
7676

7777
scope.logout = function() {
7878
AccessToken.destroy(scope);
79+
$rootScope.$broadcast('oauth:logout');
7980
loggedOut();
8081
};
8182

@@ -92,7 +93,7 @@ directives.directive('oauth', function(AccessToken, Endpoint, Profile, $location
9293

9394
// set the oauth directive to the logged-out status
9495
var loggedOut = function() {
95-
$rootScope.$broadcast('oauth:logout');
96+
$rootScope.$broadcast('oauth:loggedOut');
9697
scope.show = 'logged-out';
9798
};
9899

dist/oauth-ng.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ directives.directive('oauth', function(AccessToken, Endpoint, Profile, $location
371371

372372
scope.logout = function() {
373373
AccessToken.destroy(scope);
374+
$rootScope.$broadcast('oauth:logout');
374375
loggedOut();
375376
};
376377

@@ -387,7 +388,7 @@ directives.directive('oauth', function(AccessToken, Endpoint, Profile, $location
387388

388389
// set the oauth directive to the logged-out status
389390
var loggedOut = function() {
390-
$rootScope.$broadcast('oauth:logout');
391+
$rootScope.$broadcast('oauth:loggedOut');
391392
scope.show = 'logged-out';
392393
};
393394

test/spec/directives/oauth.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ describe('oauth', function() {
141141
$rootScope.$on('oauth:logout', callback);
142142
});
143143

144+
beforeEach(function() {
145+
$rootScope.$on('oauth:loggedOut', callback);
146+
});
147+
144148
beforeEach(function() {
145149
element.find('.logged-in').click();
146150
});
@@ -150,9 +154,10 @@ describe('oauth', function() {
150154
expect(element.find('.logged-in').attr('class')).toMatch('ng-hide');
151155
});
152156

153-
it('fires the oauth:logout event', function() {
157+
it('fires the oauth:logout and oauth:loggedOut event', function() {
154158
var event = jasmine.any(Object);
155159
expect(callback).toHaveBeenCalledWith(event);
160+
expect(callback.calls.count()).toBe(2);
156161
});
157162
});
158163
});
@@ -165,7 +170,7 @@ describe('oauth', function() {
165170
});
166171

167172
beforeEach(function() {
168-
$rootScope.$on('oauth:logout', callback);
173+
$rootScope.$on('oauth:loggedOut', callback);
169174
});
170175

171176
beforeEach(function() {
@@ -195,10 +200,14 @@ describe('oauth', function() {
195200
expect(element.find('.logged-in').attr('class')).toMatch('ng-hide');
196201
});
197202

198-
it('fires the oauth:logout event', function() {
203+
it('fires the oauth:loggedOut event', function() {
199204
var event = jasmine.any(Object);
200205
expect(callback).toHaveBeenCalledWith(event);
201206
});
207+
208+
it('does not fire the oauth:logout event', function() {
209+
expect(callback.calls.count()).toBe(1);
210+
});
202211
});
203212

204213

0 commit comments

Comments
 (0)