diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5fc6f04..626d3e1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -460,6 +460,7 @@ module ApplicationHelper attr_reader :environment def select_categories(object_name, title=nil, title_size=4) + return nil if environment.enabled?(:disable_categories) if title.nil? title = _('Categories') end diff --git a/app/models/environment.rb b/app/models/environment.rb index e53fe0e..841e492 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -29,6 +29,7 @@ class Environment < ActiveRecord::Base 'disable_asset_products' => _('Disable search for products'), 'disable_asset_events' => _('Disable search for events'), 'disable_products_for_enterprises' => _('Disable products for enterprises'), + 'disable_categories' => _('Disable categories'), } end diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index cc6ba33..c4398cf 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -104,8 +104,10 @@ { :controller=>"home" }, :id=>"menu_link_to_envhome", :title=>@environment.name %> - <% cache(:controller => 'public', :action => 'categories_menu') do %> - <%= render :file => 'shared/categories_menu' %> + <% unless environment.enabled?(:disable_categories) %> + <% cache(:controller => 'public', :action => 'categories_menu') do %> + <%= render :file => 'shared/categories_menu' %> + <% end %> <% end %> <%= render :file => 'shared/assets_menu' %> diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index fd2201a..1d88b8b 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -305,4 +305,12 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_response :success end + should 'not display categories menu if categories feature disabled' do + Environment.any_instance.stubs(:enabled?).with(anything).returns(true) + c1 = Environment.default.categories.create!(:name => 'Category 1', :display_color => 1, :parent => nil, :display_in_menu => true ) + c2 = Environment.default.categories.create!(:name => 'Category 2', :display_color => nil, :parent => c1, :display_in_menu => true ) + get :index + assert_no_tag :tag => 'a', :content => /Category 2/ + end + end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 057ff39..3dbc2d9 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -616,4 +616,18 @@ class CmsControllerTest < Test::Unit::TestCase assert_redirected_to :protocol => 'https://' end + should 'display categories if environment disable_categories disabled' do + Environment.any_instance.stubs(:enabled?).with(anything).returns(false) + a = profile.articles.create!(:name => 'test') + get :edit, :profile => profile.identifier, :id => a.id + assert_tag :tag => 'div', :descendant => { :tag => 'h4', :content => 'Categorize your article' } + end + + should 'not display categories if environment disable_categories enabled' do + Environment.any_instance.stubs(:enabled?).with(anything).returns(true) + a = profile.articles.create!(:name => 'test') + get :edit, :profile => profile.identifier, :id => a.id + assert_no_tag :tag => 'div', :descendant => { :tag => 'h4', :content => 'Categorize your article' } + end + end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index edc296c..9498d2e 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -236,7 +236,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'show edit profile button' do person = create_user('testuser').person get :index, :profile => 'testuser' - assert_tag :tag => 'a', :content => 'Edit Profile' + assert_tag :tag => 'div', :attributes => { :class => 'file-manager-button' }, :child => { :tag => 'a', :attributes => { :href => '/myprofile/testuser/profile_editor/edit' } } end should 'show image field on edit profile' do @@ -495,4 +495,18 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'span', :content => 'Manage Products and Services' end + should 'display categories if environment disable_categories disabled' do + Environment.any_instance.stubs(:enabled?).with(anything).returns(false) + person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person + get :edit, :profile => person.identifier + assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } + end + + should 'not display categories if environment disable_categories enabled' do + Environment.any_instance.stubs(:enabled?).with(anything).returns(true) + person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person + get :edit, :profile => person.identifier + assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index a8f0132..880fe31 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -231,6 +231,15 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_equal "LALALA", login_url end + should 'return nil if disable_categories is enabled' do + env = Environment.create!(:name => 'env test') + stubs(:environment).returns(env) + assert_not_nil env + env.enable(:disable_categories) + assert env.enabled?(:disable_categories) + assert_nil select_categories(mock) + end + protected def content_tag(tag, content, options = {}) -- libgit2 0.21.2