2013-07-27 05:09:54 +08:00
|
|
|
module("Discourse.User");
|
|
|
|
|
|
|
|
test('staff', function(){
|
|
|
|
var user = Discourse.User.create({id: 1, username: 'eviltrout'});
|
|
|
|
|
|
|
|
ok(!user.get('staff'), "user is not staff");
|
|
|
|
|
|
|
|
user.toggleProperty('moderator');
|
|
|
|
ok(user.get('staff'), "moderators are staff");
|
|
|
|
|
|
|
|
user.setProperties({moderator: false, admin: true});
|
|
|
|
ok(user.get('staff'), "admins are staff");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('searchContext', function() {
|
|
|
|
var user = Discourse.User.create({id: 1, username: 'EvilTrout'});
|
|
|
|
|
|
|
|
deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context");
|
2013-09-07 16:49:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isAllowedToUploadAFile", function() {
|
|
|
|
var user = Discourse.User.create({ trust_level: 0, admin: true });
|
|
|
|
ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file");
|
|
|
|
|
|
|
|
user.setProperties({ admin: false, moderator: true });
|
|
|
|
ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file");
|
|
|
|
});
|
2014-05-27 12:40:46 +08:00
|
|
|
|
|
|
|
test("avatarTemplate", function(){
|
|
|
|
var oldCDN = Discourse.CDN;
|
2014-05-27 21:39:02 +08:00
|
|
|
var oldBase = Discourse.BaseUrl;
|
|
|
|
Discourse.BaseUrl = "frogs.com";
|
|
|
|
|
|
|
|
equal(Discourse.User.avatarTemplate("sam", 1), "/user_avatar/frogs.com/sam/{size}/1.png");
|
2014-05-27 12:40:46 +08:00
|
|
|
Discourse.CDN = "http://awesome.cdn.com";
|
2014-05-27 21:39:02 +08:00
|
|
|
equal(Discourse.User.avatarTemplate("sam", 1), "http://awesome.cdn.com/user_avatar/frogs.com/sam/{size}/1.png");
|
2014-05-27 12:51:04 +08:00
|
|
|
Discourse.CDN = oldCDN;
|
2014-05-27 21:39:02 +08:00
|
|
|
Discourse.BaseUrl = oldBase;
|
2014-05-27 12:40:46 +08:00
|
|
|
});
|