Mercurial > hg > soundsoftware-site
comparison .svn/pristine/4c/4cf321de05d6993523d4f53f4c3078dcaf49b46c.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 | |
20 class SearchControllerTest < ActionController::TestCase | |
21 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles, | |
22 :issues, :trackers, :issue_statuses, :enumerations, | |
23 :custom_fields, :custom_values, | |
24 :repositories, :changesets | |
25 | |
26 def setup | |
27 User.current = nil | |
28 end | |
29 | |
30 def test_search_for_projects | |
31 get :index | |
32 assert_response :success | |
33 assert_template 'index' | |
34 | |
35 get :index, :q => "cook" | |
36 assert_response :success | |
37 assert_template 'index' | |
38 assert assigns(:results).include?(Project.find(1)) | |
39 end | |
40 | |
41 def test_search_all_projects | |
42 get :index, :q => 'recipe subproject commit', :all_words => '' | |
43 assert_response :success | |
44 assert_template 'index' | |
45 | |
46 assert assigns(:results).include?(Issue.find(2)) | |
47 assert assigns(:results).include?(Issue.find(5)) | |
48 assert assigns(:results).include?(Changeset.find(101)) | |
49 assert_tag :dt, :attributes => { :class => /issue/ }, | |
50 :child => { :tag => 'a', :content => /Add ingredients categories/ }, | |
51 :sibling => { :tag => 'dd', :content => /should be classified by categories/ } | |
52 | |
53 assert assigns(:results_by_type).is_a?(Hash) | |
54 assert_equal 5, assigns(:results_by_type)['changesets'] | |
55 assert_tag :a, :content => 'Changesets (5)' | |
56 end | |
57 | |
58 def test_search_issues | |
59 get :index, :q => 'issue', :issues => 1 | |
60 assert_response :success | |
61 assert_template 'index' | |
62 | |
63 assert_equal true, assigns(:all_words) | |
64 assert_equal false, assigns(:titles_only) | |
65 assert assigns(:results).include?(Issue.find(8)) | |
66 assert assigns(:results).include?(Issue.find(5)) | |
67 assert_tag :dt, :attributes => { :class => /issue closed/ }, | |
68 :child => { :tag => 'a', :content => /Closed/ } | |
69 end | |
70 | |
71 def test_search_issues_should_search_notes | |
72 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword') | |
73 | |
74 get :index, :q => 'searchkeyword', :issues => 1 | |
75 assert_response :success | |
76 assert_include Issue.find(2), assigns(:results) | |
77 end | |
78 | |
79 def test_search_issues_with_multiple_matches_in_journals_should_return_issue_once | |
80 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword') | |
81 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword') | |
82 | |
83 get :index, :q => 'searchkeyword', :issues => 1 | |
84 assert_response :success | |
85 assert_include Issue.find(2), assigns(:results) | |
86 assert_equal 1, assigns(:results).size | |
87 end | |
88 | |
89 def test_search_issues_should_search_private_notes_with_permission_only | |
90 Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true) | |
91 @request.session[:user_id] = 2 | |
92 | |
93 Role.find(1).add_permission! :view_private_notes | |
94 get :index, :q => 'searchkeyword', :issues => 1 | |
95 assert_response :success | |
96 assert_include Issue.find(2), assigns(:results) | |
97 | |
98 Role.find(1).remove_permission! :view_private_notes | |
99 get :index, :q => 'searchkeyword', :issues => 1 | |
100 assert_response :success | |
101 assert_not_include Issue.find(2), assigns(:results) | |
102 end | |
103 | |
104 def test_search_all_projects_with_scope_param | |
105 get :index, :q => 'issue', :scope => 'all' | |
106 assert_response :success | |
107 assert_template 'index' | |
108 assert assigns(:results).present? | |
109 end | |
110 | |
111 def test_search_my_projects | |
112 @request.session[:user_id] = 2 | |
113 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => '' | |
114 assert_response :success | |
115 assert_template 'index' | |
116 assert assigns(:results).include?(Issue.find(1)) | |
117 assert !assigns(:results).include?(Issue.find(5)) | |
118 end | |
119 | |
120 def test_search_my_projects_without_memberships | |
121 # anonymous user has no memberships | |
122 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => '' | |
123 assert_response :success | |
124 assert_template 'index' | |
125 assert assigns(:results).empty? | |
126 end | |
127 | |
128 def test_search_project_and_subprojects | |
129 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => '' | |
130 assert_response :success | |
131 assert_template 'index' | |
132 assert assigns(:results).include?(Issue.find(1)) | |
133 assert assigns(:results).include?(Issue.find(5)) | |
134 end | |
135 | |
136 def test_search_without_searchable_custom_fields | |
137 CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}" | |
138 | |
139 get :index, :id => 1 | |
140 assert_response :success | |
141 assert_template 'index' | |
142 assert_not_nil assigns(:project) | |
143 | |
144 get :index, :id => 1, :q => "can" | |
145 assert_response :success | |
146 assert_template 'index' | |
147 end | |
148 | |
149 def test_search_with_searchable_custom_fields | |
150 get :index, :id => 1, :q => "stringforcustomfield" | |
151 assert_response :success | |
152 results = assigns(:results) | |
153 assert_not_nil results | |
154 assert_equal 1, results.size | |
155 assert results.include?(Issue.find(7)) | |
156 end | |
157 | |
158 def test_search_all_words | |
159 # 'all words' is on by default | |
160 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1' | |
161 assert_equal true, assigns(:all_words) | |
162 results = assigns(:results) | |
163 assert_not_nil results | |
164 assert_equal 1, results.size | |
165 assert results.include?(Issue.find(3)) | |
166 end | |
167 | |
168 def test_search_one_of_the_words | |
169 get :index, :id => 1, :q => 'recipe updating saving', :all_words => '' | |
170 assert_equal false, assigns(:all_words) | |
171 results = assigns(:results) | |
172 assert_not_nil results | |
173 assert_equal 3, results.size | |
174 assert results.include?(Issue.find(3)) | |
175 end | |
176 | |
177 def test_search_titles_only_without_result | |
178 get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1' | |
179 results = assigns(:results) | |
180 assert_not_nil results | |
181 assert_equal 0, results.size | |
182 end | |
183 | |
184 def test_search_titles_only | |
185 get :index, :id => 1, :q => 'recipe', :titles_only => '1' | |
186 assert_equal true, assigns(:titles_only) | |
187 results = assigns(:results) | |
188 assert_not_nil results | |
189 assert_equal 2, results.size | |
190 end | |
191 | |
192 def test_search_content | |
193 Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1") | |
194 | |
195 get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => '' | |
196 assert_equal false, assigns(:titles_only) | |
197 results = assigns(:results) | |
198 assert_not_nil results | |
199 assert_equal 1, results.size | |
200 end | |
201 | |
202 def test_search_with_offset | |
203 get :index, :q => 'coo', :offset => '20080806073000' | |
204 assert_response :success | |
205 results = assigns(:results) | |
206 assert results.any? | |
207 assert results.map(&:event_datetime).max < '20080806T073000'.to_time | |
208 end | |
209 | |
210 def test_search_previous_with_offset | |
211 get :index, :q => 'coo', :offset => '20080806073000', :previous => '1' | |
212 assert_response :success | |
213 results = assigns(:results) | |
214 assert results.any? | |
215 assert results.map(&:event_datetime).min >= '20080806T073000'.to_time | |
216 end | |
217 | |
218 def test_search_with_invalid_project_id | |
219 get :index, :id => 195, :q => 'recipe' | |
220 assert_response 404 | |
221 assert_nil assigns(:results) | |
222 end | |
223 | |
224 def test_quick_jump_to_issue | |
225 # issue of a public project | |
226 get :index, :q => "3" | |
227 assert_redirected_to '/issues/3' | |
228 | |
229 # issue of a private project | |
230 get :index, :q => "4" | |
231 assert_response :success | |
232 assert_template 'index' | |
233 end | |
234 | |
235 def test_large_integer | |
236 get :index, :q => '4615713488' | |
237 assert_response :success | |
238 assert_template 'index' | |
239 end | |
240 | |
241 def test_tokens_with_quotes | |
242 get :index, :id => 1, :q => '"good bye" hello "bye bye"' | |
243 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens) | |
244 end | |
245 | |
246 def test_results_should_be_escaped_once | |
247 assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once') | |
248 get :index, :q => 'escaped_once' | |
249 assert_response :success | |
250 assert_select '#search-results' do | |
251 assert_select 'dt.issue a', :text => /<subject>/ | |
252 assert_select 'dd', :text => /<description>/ | |
253 end | |
254 end | |
255 | |
256 def test_keywords_should_be_highlighted | |
257 assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted') | |
258 get :index, :q => 'highlighted' | |
259 assert_response :success | |
260 assert_select '#search-results' do | |
261 assert_select 'dt.issue a span.highlight', :text => 'highlighted' | |
262 assert_select 'dd span.highlight', :text => 'highlighted' | |
263 end | |
264 end | |
265 end |