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