Fixed: search options get lost after clicking on a specific result type (#7501).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6201 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-07-09 11:25:01 +00:00
parent 2072669769
commit 389c7779e6
4 changed files with 30 additions and 13 deletions

View File

@ -1,5 +1,5 @@
# redMine - project management software
# Copyright (C) 2006 Jean-Philippe Lang
# Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -24,8 +24,8 @@ class SearchController < ApplicationController
def index
@question = params[:q] || ""
@question.strip!
@all_words = params[:all_words] || (params[:submit] ? false : true)
@titles_only = !params[:titles_only].nil?
@all_words = params[:all_words] ? params[:all_words].present? : true
@titles_only = params[:titles_only] ? params[:titles_only].present? : false
projects_to_search =
case params[:scope]

View File

@ -1,5 +1,5 @@
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
# Redmine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -57,7 +57,7 @@ module SearchHelper
c = results_by_type[t]
next if c == 0
text = "#{type_label(t)} (#{c})"
links << link_to(text, :q => params[:q], :titles_only => params[:title_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
links << link_to(text, :q => params[:q], :titles_only => params[:titles_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
end
('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty?
end

View File

@ -5,7 +5,9 @@
<p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input' %>
<%= javascript_tag "Field.focus('search-input')" %>
<%= project_select_tag %>
<%= hidden_field_tag 'all_words', '', :id => nil %>
<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
<%= hidden_field_tag 'titles_only', '', :id => nil %>
<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label>
</p>
<p>

View File

@ -29,7 +29,7 @@ class SearchControllerTest < ActionController::TestCase
end
def test_search_all_projects
get :index, :q => 'recipe subproject commit', :submit => 'Search'
get :index, :q => 'recipe subproject commit', :all_words => ''
assert_response :success
assert_template 'index'
@ -50,6 +50,8 @@ class SearchControllerTest < ActionController::TestCase
assert_response :success
assert_template 'index'
assert_equal true, assigns(:all_words)
assert_equal false, assigns(:titles_only)
assert assigns(:results).include?(Issue.find(8))
assert assigns(:results).include?(Issue.find(5))
assert_tag :dt, :attributes => { :class => /issue closed/ },
@ -57,7 +59,7 @@ class SearchControllerTest < ActionController::TestCase
end
def test_search_project_and_subprojects
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
@ -88,7 +90,8 @@ class SearchControllerTest < ActionController::TestCase
def test_search_all_words
# 'all words' is on by default
get :index, :id => 1, :q => 'recipe updating saving'
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
assert_equal true, assigns(:all_words)
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
@ -96,7 +99,8 @@ class SearchControllerTest < ActionController::TestCase
end
def test_search_one_of_the_words
get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
assert_equal false, assigns(:all_words)
results = assigns(:results)
assert_not_nil results
assert_equal 3, results.size
@ -104,19 +108,30 @@ class SearchControllerTest < ActionController::TestCase
end
def test_search_titles_only_without_result
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
results = assigns(:results)
assert_not_nil results
assert_equal 0, results.size
end
def test_search_titles_only
get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
get :index, :id => 1, :q => 'recipe', :titles_only => '1'
assert_equal true, assigns(:titles_only)
results = assigns(:results)
assert_not_nil results
assert_equal 2, results.size
end
def test_search_content
Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
assert_equal false, assigns(:titles_only)
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
end
def test_search_with_invalid_project_id
get :index, :id => 195, :q => 'recipe'
assert_response 404