mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Show empty categories to those who can create them (admins/mods)
This commit is contained in:
parent
560411eece
commit
42d996aae1
2 changed files with 19 additions and 6 deletions
|
@ -45,8 +45,10 @@ class CategoryList
|
||||||
@categories.insert(insert_at || @categories.size, uncategorized)
|
@categories.insert(insert_at || @categories.size, uncategorized)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove categories with no featured topics
|
# Remove categories with no featured topics unless we have the ability to edit one
|
||||||
@categories.delete_if {|c| c.featured_topics.blank? }
|
unless Guardian.new(current_user).can_create?(Category)
|
||||||
|
@categories.delete_if {|c| c.featured_topics.blank? }
|
||||||
|
end
|
||||||
|
|
||||||
# Get forum topic user records if appropriate
|
# Get forum topic user records if appropriate
|
||||||
if current_user.present?
|
if current_user.present?
|
||||||
|
|
|
@ -42,12 +42,23 @@ describe CategoryList do
|
||||||
|
|
||||||
context "with a category" do
|
context "with a category" do
|
||||||
|
|
||||||
let(:topic_category) { Fabricate(:category) }
|
let!(:topic_category) { Fabricate(:category) }
|
||||||
|
|
||||||
|
context "without a featured topic" do
|
||||||
|
|
||||||
|
it "should not return empty categories" do
|
||||||
|
category_list.categories.should be_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns empty categories for those who can create them" do
|
||||||
|
Guardian.any_instance.expects(:can_create?).with(Category).returns(true)
|
||||||
|
category_list.categories.should be_present
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
it "should not return empty categories (no featured topics)" do
|
|
||||||
category_list.categories.should be_blank
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context "with a topic in a category" do
|
context "with a topic in a category" do
|
||||||
let!(:topic) { Fabricate(:topic, category: topic_category)}
|
let!(:topic) { Fabricate(:topic, category: topic_category)}
|
||||||
let(:category) { category_list.categories.first }
|
let(:category) { category_list.categories.first }
|
||||||
|
|
Loading…
Reference in a new issue