##// END OF EJS Templates
Merged r6201 from trunk....
Jean-Philippe Lang -
r6082:2a799e83675a
parent child
Show More
@@ -1,5 +1,5
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
@@ -24,8 +24,8 class SearchController < ApplicationController
24 24 def index
25 25 @question = params[:q] || ""
26 26 @question.strip!
27 @all_words = params[:all_words] || (params[:submit] ? false : true)
28 @titles_only = !params[:titles_only].nil?
27 @all_words = params[:all_words] ? params[:all_words].present? : true
28 @titles_only = params[:titles_only] ? params[:titles_only].present? : false
29 29
30 30 projects_to_search =
31 31 case params[:scope]
@@ -1,5 +1,5
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
@@ -57,7 +57,7 module SearchHelper
57 57 c = results_by_type[t]
58 58 next if c == 0
59 59 text = "#{type_label(t)} (#{c})"
60 links << link_to(text, :q => params[:q], :titles_only => params[:title_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
60 links << link_to(text, :q => params[:q], :titles_only => params[:titles_only], :all_words => params[:all_words], :scope => params[:scope], t => 1)
61 61 end
62 62 ('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty?
63 63 end
@@ -5,7 +5,9
5 5 <p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input' %>
6 6 <%= javascript_tag "Field.focus('search-input')" %>
7 7 <%= project_select_tag %>
8 <%= hidden_field_tag 'all_words', '', :id => nil %>
8 9 <label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
10 <%= hidden_field_tag 'titles_only', '', :id => nil %>
9 11 <label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label>
10 12 </p>
11 13 <p>
@@ -29,7 +29,7 class SearchControllerTest < ActionController::TestCase
29 29 end
30 30
31 31 def test_search_all_projects
32 get :index, :q => 'recipe subproject commit', :submit => 'Search'
32 get :index, :q => 'recipe subproject commit', :all_words => ''
33 33 assert_response :success
34 34 assert_template 'index'
35 35
@@ -50,6 +50,8 class SearchControllerTest < ActionController::TestCase
50 50 assert_response :success
51 51 assert_template 'index'
52 52
53 assert_equal true, assigns(:all_words)
54 assert_equal false, assigns(:titles_only)
53 55 assert assigns(:results).include?(Issue.find(8))
54 56 assert assigns(:results).include?(Issue.find(5))
55 57 assert_tag :dt, :attributes => { :class => /issue closed/ },
@@ -57,7 +59,7 class SearchControllerTest < ActionController::TestCase
57 59 end
58 60
59 61 def test_search_project_and_subprojects
60 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
62 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
61 63 assert_response :success
62 64 assert_template 'index'
63 65 assert assigns(:results).include?(Issue.find(1))
@@ -88,7 +90,8 class SearchControllerTest < ActionController::TestCase
88 90
89 91 def test_search_all_words
90 92 # 'all words' is on by default
91 get :index, :id => 1, :q => 'recipe updating saving'
93 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
94 assert_equal true, assigns(:all_words)
92 95 results = assigns(:results)
93 96 assert_not_nil results
94 97 assert_equal 1, results.size
@@ -96,7 +99,8 class SearchControllerTest < ActionController::TestCase
96 99 end
97 100
98 101 def test_search_one_of_the_words
99 get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
102 get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
103 assert_equal false, assigns(:all_words)
100 104 results = assigns(:results)
101 105 assert_not_nil results
102 106 assert_equal 3, results.size
@@ -104,19 +108,30 class SearchControllerTest < ActionController::TestCase
104 108 end
105 109
106 110 def test_search_titles_only_without_result
107 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
111 get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
108 112 results = assigns(:results)
109 113 assert_not_nil results
110 114 assert_equal 0, results.size
111 115 end
112 116
113 117 def test_search_titles_only
114 get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
118 get :index, :id => 1, :q => 'recipe', :titles_only => '1'
119 assert_equal true, assigns(:titles_only)
115 120 results = assigns(:results)
116 121 assert_not_nil results
117 122 assert_equal 2, results.size
118 123 end
119 124
125 def test_search_content
126 Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
127
128 get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
129 assert_equal false, assigns(:titles_only)
130 results = assigns(:results)
131 assert_not_nil results
132 assert_equal 1, results.size
133 end
134
120 135 def test_search_with_invalid_project_id
121 136 get :index, :id => 195, :q => 'recipe'
122 137 assert_response 404
General Comments 0
You need to be logged in to leave comments. Login now