diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index d45c5c2..e2fb414 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -13,6 +13,10 @@ class SearchController < ApplicationController def load_search_assets @search_in = SEARCH_IN + @searching = {} + @search_in.each do |key, name| + @searching[key] = params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s) + end end def prepare_filter @@ -54,7 +58,7 @@ class SearchController < ApplicationController @results = {} @names = {} SEARCH_IN.each do |key, description| - @results[key] = @finder.send(key, @filtered_query) if params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s) + @results[key] = @finder.send(key, @filtered_query) if @searching[key] @names[key] = gettext(description) end end diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index edc4c7e..24fea42 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -26,7 +26,7 @@ <% @search_in.map { |t,n| [t,gettext(n)] } . sort_by(&:last).each do |thing, name| %>
  • - <%= labelled_check_box name, 'find_in[]', thing.to_s, true %> + <%= labelled_check_box name, 'find_in[]', thing.to_s, @searching[thing.to_sym] %>
  • <% end %> diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 6565e0f..9c7535a 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -550,5 +550,13 @@ class SearchControllerTest < Test::Unit::TestCase assert_includes assigns(:results)[:people], p end + + should 'keep asset selection for new searches' do + get :index, :query => 'a sample query', :find_in => [ 'people', 'communities' ] + assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'people', :checked => 'checked' } + assert_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'communities', :checked => 'checked' } + assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'enterprises', :checked => 'checked' } + assert_no_tag :tag => 'input', :attributes => { :name => 'find_in[]', :value => 'products', :checked => 'checked' } + end end -- libgit2 0.21.2