1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
require File.expand_path('../../test_helper', __FILE__)
require 'search_controller'
# Re-raise errors caught by the controller.
class SearchController; def rescue_action(e) raise e end; end
class SearchControllerTest < ActionController::TestCase
fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
:issues, :trackers, :issue_statuses,
:custom_fields, :custom_values,
:repositories, :changesets
def setup
@controller = SearchController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
def test_search_for_projects
get :index
assert_response :success
assert_template 'index'
get :index, :q => "cook"
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Project.find(1))
end
def test_search_all_projects
get :index, :q => 'recipe subproject commit', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(2))
assert assigns(:results).include?(Issue.find(5))
assert assigns(:results).include?(Changeset.find(101))
assert_tag :dt, :attributes => { :class => /issue/ },
:child => { :tag => 'a', :content => /Add ingredients categories/ },
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
assert assigns(:results_by_type).is_a?(Hash)
assert_equal 5, assigns(:results_by_type)['changesets']
assert_tag :a, :content => 'Changesets (5)'
end
def test_search_issues
get :index, :q => 'issue', :issues => 1
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/ },
:child => { :tag => 'a', :content => /Closed/ }
end
def test_search_all_projects_with_scope_param
get :index, :q => 'issue', :scope => 'all'
assert_response :success
assert_template 'index'
assert assigns(:results).present?
end
def test_search_my_projects
@request.session[:user_id] = 2
get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
assert !assigns(:results).include?(Issue.find(5))
end
def test_search_my_projects_without_memberships
# anonymous user has no memberships
get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).empty?
end
def test_search_project_and_subprojects
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(1))
assert assigns(:results).include?(Issue.find(5))
end
def test_search_without_searchable_custom_fields
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
get :index, :id => 1
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
get :index, :id => 1, :q => "can"
assert_response :success
assert_template 'index'
end
def test_search_with_searchable_custom_fields
get :index, :id => 1, :q => "stringforcustomfield"
assert_response :success
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert results.include?(Issue.find(7))
end
def test_search_all_words
# 'all words' is on by default
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
assert results.include?(Issue.find(3))
end
def test_search_one_of_the_words
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
assert results.include?(Issue.find(3))
end
def test_search_titles_only_without_result
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'
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_offset
get :index, :q => 'coo', :offset => '20080806073000'
assert_response :success
results = assigns(:results)
assert results.any?
assert results.map(&:event_datetime).max < '20080806T073000'.to_time
end
def test_search_previous_with_offset
get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
assert_response :success
results = assigns(:results)
assert results.any?
assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
end
def test_search_with_invalid_project_id
get :index, :id => 195, :q => 'recipe'
assert_response 404
assert_nil assigns(:results)
end
def test_quick_jump_to_issue
# issue of a public project
get :index, :q => "3"
assert_redirected_to '/issues/3'
# issue of a private project
get :index, :q => "4"
assert_response :success
assert_template 'index'
end
def test_large_integer
get :index, :q => '4615713488'
assert_response :success
assert_template 'index'
end
def test_tokens_with_quotes
get :index, :id => 1, :q => '"good bye" hello "bye bye"'
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
end
end
|