Skip to content

Commit

Permalink
Make configurator more robust
Browse files Browse the repository at this point in the history
When an array of services of a plugin is undefined, return an empty
array when getServices() is called.
  • Loading branch information
LFDM committed May 10, 2014
1 parent bb5242a commit 6e47c6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/js/arethusa.core/configurator.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ angular.module('arethusa.core').service('configurator', function($injector) {
};

this.getServices = function(serviceNames) {
var that = this;
return arethusaUtil.map(serviceNames, function(name) {
return that.getService(name);
});
if (serviceNames) {
var that = this;
return arethusaUtil.map(serviceNames, function(name) {
return that.getService(name);
});
} else {
return [];
}
};

// this.configuration is set from outside on page load
Expand Down
6 changes: 6 additions & 0 deletions spec/arethusa.core/configurator.service_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ describe('configurator', function() {
expect(services).toContain(mock1);
expect(services).toContain(mock2);
}));

it('returns an empty array when no service names are given', inject(function(configurator) {
var names = undefined;
var services = configurator.getServices(names);
expect(services).toEqual([]);
}));
});
});

0 comments on commit 6e47c6d

Please sign in to comment.