Commit 3f8af20484a57772d7243c8998d7a9f2656ddd1c
1 parent
90f4f1c1
Exists in
staging
and in
4 other branches
Consider disabled assets at category search
Showing
2 changed files
with
23 additions
and
8 deletions
Show diff stats
app/controllers/public/search_controller.rb
| @@ -45,14 +45,15 @@ class SearchController < PublicController | @@ -45,14 +45,15 @@ class SearchController < PublicController | ||
| 45 | @order = [] | 45 | @order = [] |
| 46 | @names = {} | 46 | @names = {} |
| 47 | limit = MULTIPLE_SEARCH_LIMIT | 47 | limit = MULTIPLE_SEARCH_LIMIT |
| 48 | - [ | ||
| 49 | - [ :people, _('People'), :recent_people ], | ||
| 50 | - [ :enterprises, _('Enterprises'), :recent_enterprises ], | ||
| 51 | - [ :products, _('Products'), :recent_products ], | ||
| 52 | - [ :events, _('Upcoming events'), :upcoming_events ], | ||
| 53 | - [ :communities, _('Communities'), :recent_communities ], | ||
| 54 | - [ :articles, _('Contents'), :recent_articles ] | ||
| 55 | - ].each do |asset, name, filter| | 48 | + items = [] |
| 49 | + items << [ :people, _('People'), :recent_people ] if environment.disabled?('disable_asset_people') | ||
| 50 | + items << [ :enterprises, _('Enterprises'), :recent_enterprises ] if environment.disabled?('disable_asset_enterprises') | ||
| 51 | + items << [ :products, _('Products'), :recent_products ] if environment.disabled?('disable_asset_products') | ||
| 52 | + items << [ :events, _('Upcoming events'), :upcoming_events ] if environment.disabled?('disable_asset_events') | ||
| 53 | + items << [ :communities, _('Communities'), :recent_communities ] if environment.disabled?('disable_asset_communities') | ||
| 54 | + items << [ :articles, _('Contents'), :recent_articles ] if environment.disabled?('disable_asset_articles') | ||
| 55 | + | ||
| 56 | + items.each do |asset, name, filter| | ||
| 56 | @order << asset | 57 | @order << asset |
| 57 | @searches[asset]= {:results => @category.send(filter, limit)} | 58 | @searches[asset]= {:results => @category.send(filter, limit)} |
| 58 | raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries) | 59 | raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries) |
test/functional/search_controller_test.rb
| @@ -216,6 +216,20 @@ class SearchControllerTest < ActionController::TestCase | @@ -216,6 +216,20 @@ class SearchControllerTest < ActionController::TestCase | ||
| 216 | assert_equal @category, assigns(:category) | 216 | assert_equal @category, assigns(:category) |
| 217 | end | 217 | end |
| 218 | 218 | ||
| 219 | + should 'display results for enabled assets' do | ||
| 220 | + assets = ['people', 'enterprises', 'products', 'events', 'communities', 'articles'] | ||
| 221 | + get :category_index, :category_path => [ 'my-category' ] | ||
| 222 | + assets.each { |asset| assert_select "div.search-results-#{asset}" } | ||
| 223 | + end | ||
| 224 | + | ||
| 225 | + should 'not display results for disabled assets' do | ||
| 226 | + assets = ['people', 'enterprises', 'products', 'events', 'communities', 'articles'] | ||
| 227 | + environment = Environment.default | ||
| 228 | + assets.each { |asset| environment.enable("disable_asset_#{asset}") } | ||
| 229 | + get :category_index, :category_path => [ 'my-category' ] | ||
| 230 | + assets.each { |asset| assert_select "div.search-results-#{asset}", false } | ||
| 231 | + end | ||
| 232 | + | ||
| 219 | should 'not list "Search for ..." in category_index' do | 233 | should 'not list "Search for ..." in category_index' do |
| 220 | get :category_index, :category_path => [ 'my-category' ] | 234 | get :category_index, :category_path => [ 'my-category' ] |
| 221 | assert_no_tag :content => /Search for ".*" in the whole site/ | 235 | assert_no_tag :content => /Search for ".*" in the whole site/ |
-
mentioned in commit 17c21fbb5fe1641fbefc49990851c5392bed2d7e