Fix 'You must choose a category' when a category is already chosen

This commit is contained in:
Neil Lalonde 2013-08-21 16:14:04 -04:00
parent 30cfa33629
commit adbb6a19bb
2 changed files with 16 additions and 0 deletions

View file

@ -334,6 +334,10 @@ Discourse.Composer = Discourse.Model.extend({
reply: opts.reply || this.get("reply") || ""
});
if (!this.get('categoryName') && !Discourse.SiteSettings.allow_uncategorized_topics && Discourse.Category.list().length > 0) {
this.set('categoryName', Discourse.Category.list()[0].get('name'));
}
if (opts.postId) {
this.set('loading', true);
Discourse.Post.load(opts.postId).then(function(result) {

View file

@ -176,3 +176,15 @@ test('clearState', function() {
blank(composer.get('title'));
});
test('initial category when uncategorized is allowed', function() {
Discourse.SiteSettings.allow_uncategorized_topics = true;
var composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
equal(composer.get('categoryName'),undefined,"Uncategorized by default");
});
test('initial category when uncategorized is not allowed', function() {
Discourse.SiteSettings.allow_uncategorized_topics = false;
var composer = Discourse.Composer.open({action: 'createTopic', draftKey: 'asfd', draftSequence: 1});
ok(composer.get('categoryName') !== undefined, "Not uncategorized by default");
});