diff --git a/app/models/category.rb b/app/models/category.rb
index 9f1c7be..5bd02b0 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -47,7 +47,13 @@ class Category < ActiveRecord::Base
end
def total_items
+ # FIXME this can be SLOW (??)
articles.count + comments.count + enterprises.count + people.count + communities.count + products.count
end
+ def display_in_menu?
+ # FIXME don't hardcode like this. Should be a setting of the environment, maybe
+ total_items >= 10
+ end
+
end
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 793a5c6..b331bd4 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -14,8 +14,6 @@
<%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') %>
- <%= file_manager_button(_('My Interests'), 'icons-app/categories.png', :controller => 'profile_editor', :action => 'edit_categories') %>
-
<%= file_manager_button(_('Change Password'), 'icons-app/change-password.png', :controller => 'account', :action => 'change_password') if profile.person? %>
<%= file_manager_button(_('Manage friends'), 'icons-app/friends.png', :controller => 'friends', :action => 'index') if profile.person? %>
diff --git a/app/views/shared/categories_menu.rhtml b/app/views/shared/categories_menu.rhtml
index 624975d..a79b10c 100644
--- a/app/views/shared/categories_menu.rhtml
+++ b/app/views/shared/categories_menu.rhtml
@@ -4,7 +4,7 @@
>
<%= item.name %>
- <% item.all_children.each do |child| %>
+ <% item.all_children.select{|i| i.display_in_menu?}.each do |child| %>
<% if (@controller.controller_name == 'search') && (@controller.action_name == 'assets') %>
- <%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'assets', :asset => params[:asset], :category_path => child.explode_path) %>
<% else %>
diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb
index 4feef02..8d1e7a3 100644
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -127,4 +127,16 @@ class ApplicationControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' }
end
+ # FIXME why this not work???
+ should 'display categories in menu' do
+ c1 = Category.create!(:name => 'category 1', :environment => Environment.default)
+ c2 = Category.create!(:name => 'category 2', :environment => Environment.default, :parent => c1)
+ c3 = Category.create!(:name => 'category 3', :environment => Environment.default, :parent => c1)
+ c2.expects(:display_in_menu?).returns(true)
+ c3.expects(:display_in_menu?).returns(false)
+ get :index
+ assert_tag :tag => 'a', :attributes => { :content => /category 2/ }
+ assert_no_tag :tag => 'a', :attributes => { :content => /category 3/ }
+ end
+
end
diff --git a/test/unit/category_test.rb b/test/unit/category_test.rb
index 8de49e3..ac049dd 100644
--- a/test/unit/category_test.rb
+++ b/test/unit/category_test.rb
@@ -385,4 +385,16 @@ class CategoryTest < Test::Unit::TestCase
end
end
+ should 'display in menu' do
+ c = Category.create!(:name => 'test category1', :environment => Environment.default)
+ c.expects(:total_items).returns(10)
+ assert c.display_in_menu?
+ end
+
+ should 'not display in menu' do
+ c = Category.create!(:name => 'test category1', :environment => Environment.default)
+ c.expects(:total_items).returns(1)
+ assert !c.display_in_menu?
+ end
+
end
--
libgit2 0.21.2