Merge "Added safety check to initActions so unregistered types pass"

This commit is contained in:
Jenkins 2016-06-14 03:18:56 +00:00 committed by Gerrit Code Review
commit 947b9f5b42
2 changed files with 13 additions and 4 deletions

View File

@ -602,10 +602,13 @@
* for the given type. This requires the proper scope be passed. * for the given type. This requires the proper scope be passed.
* If an action does not have an initScope() function, it is ignored. * If an action does not have an initScope() function, it is ignored.
*/ */
function initActions(type, scope) { function initActions(typeName, scope) {
angular.forEach(resourceTypes[type].itemActions, setActionScope); var type = resourceTypes[typeName];
angular.forEach(resourceTypes[type].batchActions, setActionScope); if (type) {
angular.forEach(resourceTypes[type].globalActions, setActionScope); angular.forEach(type.itemActions, setActionScope);
angular.forEach(type.batchActions, setActionScope);
angular.forEach(type.globalActions, setActionScope);
}
function setActionScope(action) { function setActionScope(action) {
if (action.service.initScope) { if (action.service.initScope) {

View File

@ -54,6 +54,12 @@
expect(returned).toBeUndefined(); expect(returned).toBeUndefined();
}); });
it('init ignores initScope when not type is not present', function() {
var returned = service.initActions('was-never-registered', {} );
// but we got here
expect(returned).toBeUndefined();
});
describe('getResourceType', function() { describe('getResourceType', function() {
it('returns a new resource type object even without a config', function() { it('returns a new resource type object even without a config', function() {
var value = service.getResourceType('something'); var value = service.getResourceType('something');