FIX: Only enabled badges can be granted

FIX: Sort badges by displayName
This commit is contained in:
Gerhard Schlager 2015-09-24 01:20:44 +02:00
parent 4d6c99cb3d
commit 7d5e2d46c5
2 changed files with 9 additions and 6 deletions

View File

@ -56,12 +56,12 @@ export default Ember.ArrayController.extend({
var badges = [];
this.get('badges').forEach(function(badge) {
if (badge.get('multiple_grant') || !granted[badge.get('id')]) {
if (badge.get('enabled') && (badge.get('multiple_grant') || !granted[badge.get('id')])) {
badges.push(badge);
}
});
return _.sortBy(badges, "name");
return _.sortBy(badges, badge => badge.get('displayName'));
}.property('badges.@each', 'model.@each'),
/**

View File

@ -5,14 +5,17 @@ moduleFor('controller:admin-user-badges', {
});
test("grantableBadges", function() {
const badgeFirst = Badge.create({id: 3, name: "A Badge"});
const badgeMiddle = Badge.create({id: 1, name: "My Badge"});
const badgeLast = Badge.create({id: 2, name: "Zoo Badge"});
const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle] });
const badgeFirst = Badge.create({id: 3, name: "A Badge", enabled: true});
const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true});
const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true});
const badgeDisabled = Badge.create({id: 4, name: "Disabled Badge", enabled: false});
const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] });
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
const badgeNames = controller.get('grantableBadges').map(function(badge) {
return badge.name;
});
not(badgeNames.contains(badgeDisabled), "excludes disabled badges");
deepEqual(badgeNames, sortedNames, "sorts badges by name");
});