FIX: Discourse.Presence was broken on arrays. The flag button was showing for anonymous users.

This commit is contained in:
Robin Ward 2013-06-18 11:35:51 -04:00
parent 7544e231c5
commit 8e96299653
3 changed files with 39 additions and 22 deletions

View file

@ -18,16 +18,7 @@ Discourse.Presence = Em.Mixin.create({
@return {Boolean}
*/
blank: function(name) {
var prop = this[name] || this.get(name);
if (!prop) return true;
switch (typeof prop) {
case "string":
return prop.trim().length === 0;
case "object":
return $.isEmptyObject(prop);
}
return false;
return Ember.isEmpty(this[name] || this.get(name));
},
/**

View file

@ -2,40 +2,38 @@
module("Discourse.BBCode");
test('format', function(){
var format = function(input, expected, text) {
equal(Discourse.BBCode.format(input), expected, text);
}
var format = function(input, expected, text) {
equal(Discourse.BBCode.format(input), expected, text);
}
test('basic bbcode', function() {
format("[b]strong[/b]", "<span class='bbcode-b'>strong</span>", "bolds text");
format("[i]emphasis[/i]", "<span class='bbcode-i'>emphasis</span>", "italics text");
format("[u]underlined[/u]", "<span class='bbcode-u'>underlined</span>", "underlines text");
format("[s]strikethrough[/s]", "<span class='bbcode-s'>strikethrough</span>", "strikes-through text");
format("[code]\nx++\n[/code]", "<pre>\nx++\n</pre>", "makes code into pre");
format("[spoiler]it's a sled[/spoiler]", "<span class=\"spoiler\">it's a sled</span>", "supports spoiler tags");
format("[img]http://eviltrout.com/eviltrout.png[/img]", "<img src=\"http://eviltrout.com/eviltrout.png\">", "links images");
format("[url]http://bettercallsaul.com[/url]", "<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>", "supports [url] without a title");
format("[email]eviltrout@mailinator.com[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>", "supports [email] without a title");
});
// Lists
test('lists', function() {
format("[ul][li]option one[/li][/ul]", "<ul><li>option one</li></ul>", "creates an ul");
format("[ol][li]option one[/li][/ol]", "<ol><li>option one</li></ol>", "creates an ol");
});
// Color
test('color', function() {
format("[color=#00f]blue[/color]", "<span style=\"color: #00f\">blue</span>", "supports [color=] with a short hex value");
format("[color=#ffff00]yellow[/color]", "<span style=\"color: #ffff00\">yellow</span>", "supports [color=] with a long hex value");
format("[color=red]red[/color]", "<span style=\"color: red\">red</span>", "supports [color=] with an html color");
format("[color=javascript:alert('wat')]noop[/color]", "noop", "it performs a noop on invalid input");
});
// Tags with arguments
test('tags with arguments', function() {
format("[size=35]BIG[/size]", "<span class=\"bbcode-size-35\">BIG</span>", "supports [size=]");
format("[url=http://bettercallsaul.com]better call![/url]", "<a href=\"http://bettercallsaul.com\">better call!</a>", "supports [url] with a title");
format("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
format("[u][i]abc[/i][/u]", "<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>", "can nest tags");
format("[b]first[/b] [b]second[/b]", "<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>", "can bold two things on the same line");
});

View file

@ -0,0 +1,28 @@
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
module("Discourse.Presence");
var testObj = Em.Object.createWithMixins(Discourse.Presence, {
emptyString: "",
nonEmptyString: "Evil Trout",
emptyArray: [],
nonEmptyArray: [1, 2, 3],
age: 34,
});
test("present", function() {
ok(testObj.present('nonEmptyString'), "Non empty strings are present");
ok(!testObj.present('emptyString'), "Empty strings are not present");
ok(testObj.present('nonEmptyArray'), "Non Empty Arrays are present");
ok(!testObj.present('emptyArray'), "Empty arrays are not present");
ok(testObj.present('age'), "integers are present");
});
test("blank", function() {
ok(testObj.blank('emptyString'), "Empty strings are blank");
ok(!testObj.blank('nonEmptyString'), "Non empty strings are not blank");
ok(testObj.blank('emptyArray'), "Empty arrays are blank");
ok(!testObj.blank('nonEmptyArray'), "Non empty arrays are not blank");
ok(testObj.blank('missing'), "Missing properties are blank");
});