diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index f4619b9..a940344 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -13,7 +13,7 @@ class SearchController < ApplicationController protected def load_search_assets - @search_in = SEARCH_IN + @search_in = where_to_search @searching = {} @search_in.each do |key, name| @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s) @@ -36,7 +36,7 @@ class SearchController < ApplicationController def check_valid_assets @asset = params[:asset].to_sym - if !SEARCH_IN.map(&:first).include?(@asset) + if !where_to_search.map(&:first).include?(@asset) render :text => 'go away', :status => 403 return end @@ -129,14 +129,16 @@ class SearchController < ApplicationController ###################################################### - SEARCH_IN = [ - [ :articles, N_('Articles') ], - [ :enterprises, N_('Enterprises') ], - [ :people, N_('People') ], - [ :communities, N_('Communities') ], - [ :products, N_('Products') ], - [ :events, N_('Events') ] - ] + def where_to_search + [ + [ :articles, N_('Articles') ], + [ :enterprises, N_('Enterprises') ], + [ :people, N_('People') ], + [ :communities, N_('Communities') ], + [ :products, N_('Products') ], + [ :events, N_('Events') ] + ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } + end def cities @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]]) @@ -163,7 +165,7 @@ class SearchController < ApplicationController @order = [] @names = {} - SEARCH_IN.select { |key,description| @searching[key] }.each do |key, description| + where_to_search.select { |key,description| @searching[key] }.each do |key, description| @order << key @results[key] = @finder.find(key, @filtered_query, calculate_find_options(key, limit, params[:page], @product_category, @region, params[:radius], params[:year], params[:month])) @names[key] = gettext(description) diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb index 1f6651c..d63eb7c 100644 --- a/app/helpers/assets_helper.rb +++ b/app/helpers/assets_helper.rb @@ -11,7 +11,9 @@ module AssetsHelper [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], - ].map do |target,css_class,name| + ].select do |target, css_class, name| + !environment.enabled?('disable_asset_' + target[:asset]) + end.map do |target,css_class,name| content_tag('li', link_to( content_tag('span', '', :class => css_class) + diff --git a/app/models/environment.rb b/app/models/environment.rb index c169a46..1729eba 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -22,8 +22,12 @@ class Environment < ActiveRecord::Base # hash, with pairs in the form 'feature_name' => 'Feature name'. def self.available_features { - 'some_feature' => _('Some feature'), - 'other_feature' => _('Other feature'), + 'disable_asset_articles' => _('Disable search for articles '), + 'disable_asset_enterprises' => _('Disable search for enterprises'), + 'disable_asset_people' => _('Disable search for people'), + 'disable_asset_communities' => _('Disable search for communities'), + 'disable_asset_products' => _('Disable search for products'), + 'disable_asset_events' => _('Disable search for events'), } end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 6f86795..b9e7567 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -899,6 +899,20 @@ class SearchControllerTest < Test::Unit::TestCase assert_includes assigns(:results)[:articles], art end + should 'know about disabled assets' do + env = mock + %w[ articles enterprises people communities events].each do |item| + env.expects(:enabled?).with('disable_asset_' + item).returns(false).at_least_once + end + env.expects(:enabled?).with('disable_asset_products').returns(true).at_least_once + @controller.stubs(:environment).returns(env) + + %w[ articles enterprises people communities events].each do |item| + assert_includes @controller.where_to_search.map(&:first), item.to_sym + end + assert_not_includes @controller.where_to_search.map(&:first), :products + end + ################################################################## ################################################################## diff --git a/test/unit/assets_helper_test.rb b/test/unit/assets_helper_test.rb index 39a678d..d483c89 100644 --- a/test/unit/assets_helper_test.rb +++ b/test/unit/assets_helper_test.rb @@ -5,6 +5,9 @@ class AssetsHelperTest < Test::Unit::TestCase include AssetsHelper should 'generate link to assets' do + env = mock; env.stubs(:enabled?).with(anything).returns(false) + stubs(:environment).returns(env) + %w[ articles people products @@ -21,6 +24,9 @@ class AssetsHelperTest < Test::Unit::TestCase end should 'generate link to assets with current category' do + env = mock; env.stubs(:enabled?).with(anything).returns(false) + stubs(:environment).returns(env) + %w[ articles people products @@ -38,4 +44,32 @@ class AssetsHelperTest < Test::Unit::TestCase generate_assets_menu end + should 'generate link only to non-disabled assets' do + env = mock + env.expects(:enabled?).with('disable_asset_articles').returns(false) + env.expects(:enabled?).with('disable_asset_enterprises').returns(true) + env.expects(:enabled?).with('disable_asset_people').returns(false) + env.expects(:enabled?).with('disable_asset_communities').returns(false) + env.expects(:enabled?).with('disable_asset_products').returns(true) + env.expects(:enabled?).with('disable_asset_events').returns(false) + stubs(:environment).returns(env) + + %w[ articles + people + communities + events + ].each do |asset| + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => [ 'my-category' ]}) + end + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => 'products', :category_path => [ 'my-category' ]}).never + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => 'enterprises', :category_path => [ 'my-category' ]}).never + + stubs(:_).returns('') + stubs(:content_tag).returns('') + @category = mock + @category.expects(:explode_path).returns(['my-category']).at_least_once + + generate_assets_menu + end + end -- libgit2 0.21.2