From adbb6a19bb5a30855d9f9e84bed085760d750007 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 21 Aug 2013 16:14:04 -0400 Subject: [PATCH] Fix 'You must choose a category' when a category is already chosen --- app/assets/javascripts/discourse/models/composer.js | 4 ++++ test/javascripts/models/composer_test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 6f8e7a600..4b6046ba6 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -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) { diff --git a/test/javascripts/models/composer_test.js b/test/javascripts/models/composer_test.js index dac2b0d7e..001fc230c 100644 --- a/test/javascripts/models/composer_test.js +++ b/test/javascripts/models/composer_test.js @@ -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"); +}); \ No newline at end of file