FIX: ZALGO test suite was causing failures in the wrong place due to

missing `async` bits.
This commit is contained in:
Robin Ward 2014-04-15 14:19:05 -04:00
parent 617b4bed41
commit fdb751296a
2 changed files with 21 additions and 11 deletions

View File

@ -62,14 +62,18 @@ Discourse.Badge = Discourse.Model.extend({
**/ **/
updateFromJson: function(json) { updateFromJson: function(json) {
var self = this; var self = this;
Object.keys(json.badge).forEach(function(key) { if (json.badge) {
self.set(key, json.badge[key]); Object.keys(json.badge).forEach(function(key) {
}); self.set(key, json.badge[key]);
json.badge_types.forEach(function(badgeType) { });
if (badgeType.id === self.get('badge_type_id')) { }
self.set('badge_type', Object.create(badgeType)); if (json.badge_types) {
} json.badge_types.forEach(function(badgeType) {
}); if (badgeType.id === self.get('badge_type_id')) {
self.set('badge_type', Object.create(badgeType));
}
});
}
}, },
/** /**

View File

@ -17,26 +17,32 @@ test('createFromJson array', function() {
equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null"); equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null");
}); });
test('findByUsername', function() { asyncTestDiscourse('findByUsername', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson)); this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
Discourse.UserBadge.findByUsername("anne3").then(function(badges) { Discourse.UserBadge.findByUsername("anne3").then(function(badges) {
ok(Array.isArray(badges), "returns an array"); ok(Array.isArray(badges), "returns an array");
start();
}); });
ok(Discourse.ajax.calledOnce, "makes an AJAX call"); ok(Discourse.ajax.calledOnce, "makes an AJAX call");
}); });
test('findByBadgeId', function() { asyncTestDiscourse('findByBadgeId', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson)); this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(multipleBadgesJson));
Discourse.UserBadge.findByBadgeId(880).then(function(badges) { Discourse.UserBadge.findByBadgeId(880).then(function(badges) {
ok(Array.isArray(badges), "returns an array"); ok(Array.isArray(badges), "returns an array");
start();
}); });
ok(Discourse.ajax.calledOnce, "makes an AJAX call"); ok(Discourse.ajax.calledOnce, "makes an AJAX call");
}); });
test('grant', function() { asyncTestDiscourse('grant', function() {
expect(2);
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(singleBadgeJson)); this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve(singleBadgeJson));
Discourse.UserBadge.grant(1, "username").then(function(userBadge) { Discourse.UserBadge.grant(1, "username").then(function(userBadge) {
ok(!Array.isArray(userBadge), "does not return an array"); ok(!Array.isArray(userBadge), "does not return an array");
start();
}); });
ok(Discourse.ajax.calledOnce, "makes an AJAX call"); ok(Discourse.ajax.calledOnce, "makes an AJAX call");
}); });