From 8e24a608b0d0ffab3910bf31a28416ac2e7e1248 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 7 May 2013 15:31:49 -0400 Subject: [PATCH] Show empty categories on categories page to people people who can edit and delete categories --- app/models/category_list.rb | 5 ++++- spec/components/category_list_spec.rb | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 9883767c7aa..4d4d4c2546e 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -48,9 +48,12 @@ class CategoryList @categories.insert(insert_at || @categories.size, uncategorized) end - # Remove categories with no featured topics unless we have the ability to edit one unless Guardian.new(current_user).can_create?(Category) + # Remove categories with no featured topics unless we have the ability to edit one @categories.delete_if { |c| c.featured_topics.blank? } + else + # Show all categories to people who have the ability to edit and delete categories + @categories.insert(@categories.size, *Category.where('id not in (?)', @categories.map(&:id).compact).to_a) end # Get forum topic user records if appropriate diff --git a/spec/components/category_list_spec.rb b/spec/components/category_list_spec.rb index 540e607429a..4b224254c12 100644 --- a/spec/components/category_list_spec.rb +++ b/spec/components/category_list_spec.rb @@ -52,10 +52,9 @@ describe CategoryList do 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_blank + category_list.categories.should_not be_blank end - end