From 807a3009809fb22a6182f1f556afee127c1558b8 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 29 Apr 2008 02:42:51 +0000 Subject: [PATCH] ActionItem341: remembering search options from one search to another --- app/controllers/public/search_controller.rb | 6 +++++- app/views/search/_search_form.rhtml | 2 +- test/functional/search_controller_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) 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