Skip to content

Commit

Permalink
Show empty categories to those who can create them (admins/mods)
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Feb 21, 2013
1 parent 560411e commit 42d996a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/models/category_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(current_user)
.includes(:featured_users)
.order('topics_week desc, topics_month desc, topics_year desc')
.to_a

# Support for uncategorized topics
uncategorized_topics = Topic
.listable_topics
Expand Down Expand Up @@ -45,8 +45,10 @@ def initialize(current_user)
@categories.insert(insert_at || @categories.size, uncategorized)
end

# Remove categories with no featured topics
@categories.delete_if {|c| c.featured_topics.blank? }
# Remove categories with no featured topics unless we have the ability to edit one
unless Guardian.new(current_user).can_create?(Category)
@categories.delete_if {|c| c.featured_topics.blank? }
end

# Get forum topic user records if appropriate
if current_user.present?
Expand Down
17 changes: 14 additions & 3 deletions spec/components/category_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@

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


context "with a topic in a category" do
let!(:topic) { Fabricate(:topic, category: topic_category)}
let(:category) { category_list.categories.first }
Expand Down

0 comments on commit 42d996a

Please sign in to comment.