Convert Discourse.User to use Discourse.Singleton

This commit is contained in:
Robin Ward
2013-08-08 12:42:08 -04:00
parent 8e1fae0459
commit 51f5cf77fb
23 changed files with 90 additions and 57 deletions

View File

@ -85,12 +85,12 @@ var badgeClickCount = function(id, expected) {
};
test("does not update badge clicks on my own link", function() {
this.stub(Discourse.User, 'current').returns(314);
this.stub(Discourse.User, 'currentProp').withArgs('id').returns(314);
badgeClickCount('with-badge', 1);
});
test("does not update badge clicks in my own post", function() {
this.stub(Discourse.User, 'current').returns(3141);
this.stub(Discourse.User, 'currentProp').withArgs('id').returns(3141);
badgeClickCount('with-badge-but-not-mine', 1);
});
@ -167,7 +167,7 @@ test("does not track via AJAX for attachments", function() {
test("tracks custom urls when opening in another window", function() {
var clickEvent = generateClickEventOn('a');
this.stub(Discourse.User, "current").returns(true);
this.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true);
ok(!track(clickEvent));
ok(this.windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42', '_blank'));
});

View File

@ -24,7 +24,7 @@ test("uploading one file", function() {
test("new user cannot upload images", function() {
Discourse.SiteSettings.newuser_max_images = 0;
this.stub(Discourse.User, 'current').withArgs("trust_level").returns(0);
this.stub(Discourse.User, 'currentProp').withArgs("trust_level").returns(0);
this.stub(bootbox, "alert");
ok(!validUpload([{name: "image.png"}]));
@ -33,7 +33,7 @@ test("new user cannot upload images", function() {
test("new user cannot upload attachments", function() {
Discourse.SiteSettings.newuser_max_attachments = 0;
this.stub(Discourse.User, 'current').withArgs("trust_level").returns(0);
this.stub(Discourse.User, 'currentProp').withArgs("trust_level").returns(0);
this.stub(bootbox, "alert");
ok(!validUpload([{name: "roman.txt"}]));

View File

@ -17,7 +17,7 @@ module("Discourse.FlagController canDeleteSpammer");
test("canDeleteSpammer not staff", function(){
var flagController = controllerFor('flag', buildPost());
this.stub(Discourse.User, 'current').returns(false); // Discourse.User.current('staff') returns false
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(false);
flagController.set('selected', Discourse.PostActionType.create({name_key: 'spam'}));
equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
});
@ -28,7 +28,7 @@ var canDeleteSpammer = function(test, postActionType, expected, testName) {
};
test("canDeleteSpammer spam not selected", function(){
this.stub(Discourse.User, 'current').returns(true); // Discourse.User.current('staff') returns true
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
this.flagController = controllerFor('flag', buildPost());
this.flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
canDeleteSpammer(this, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
@ -38,7 +38,7 @@ test("canDeleteSpammer spam not selected", function(){
});
test("canDeleteSpammer spam selected", function(){
this.stub(Discourse.User, 'current').returns(true);
this.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
this.flagController = controllerFor('flag', buildPost());
this.flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));

View File

@ -124,6 +124,7 @@ var jsHintOpts = {
"controllerFor",
"containsInstance",
"deepEqual",
"notEqual",
"Blob",
"File"],
"node" : false,

View File

@ -34,4 +34,28 @@ test("currentProp writing", function() {
DummyModel.currentProp('adventure', null);
equal(DummyModel.currentProp('adventure'), null, 'we can set the value to null');
});
test("createCurrent", function() {
var Shoe = Ember.Object.extend({});
Shoe.reopenClass(Discourse.Singleton, {
createCurrent: function() {
return Shoe.create({toes: 5});
}
});
equal(Shoe.currentProp('toes'), 5, 'it created the class using `createCurrent`');
});
test("createCurrent that returns null", function() {
var Missing = Ember.Object.extend({});
Missing.reopenClass(Discourse.Singleton, {
createCurrent: function() {
return null;
}
});
blank(Missing.current(), "it doesn't return an instance");
blank(Missing.currentProp('madeup'), "it won't raise an error asking for a property. Will just return null.");
});