comparison test/functional/search_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
4 # Re-raise errors caught by the controller. 4 # Re-raise errors caught by the controller.
5 class SearchController; def rescue_action(e) raise e end; end 5 class SearchController; def rescue_action(e) raise e end; end
6 6
7 class SearchControllerTest < ActionController::TestCase 7 class SearchControllerTest < ActionController::TestCase
8 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles, 8 fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
9 :issues, :trackers, :issue_statuses, 9 :issues, :trackers, :issue_statuses, :enumerations,
10 :custom_fields, :custom_values, 10 :custom_fields, :custom_values,
11 :repositories, :changesets 11 :repositories, :changesets
12 12
13 def setup 13 def setup
14 @controller = SearchController.new 14 @controller = SearchController.new
56 assert assigns(:results).include?(Issue.find(5)) 56 assert assigns(:results).include?(Issue.find(5))
57 assert_tag :dt, :attributes => { :class => /issue closed/ }, 57 assert_tag :dt, :attributes => { :class => /issue closed/ },
58 :child => { :tag => 'a', :content => /Closed/ } 58 :child => { :tag => 'a', :content => /Closed/ }
59 end 59 end
60 60
61 def test_search_issues_should_search_notes
62 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
63
64 get :index, :q => 'searchkeyword', :issues => 1
65 assert_response :success
66 assert_include Issue.find(2), assigns(:results)
67 end
68
69 def test_search_issues_with_multiple_matches_in_journals_should_return_issue_once
70 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
71 Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
72
73 get :index, :q => 'searchkeyword', :issues => 1
74 assert_response :success
75 assert_include Issue.find(2), assigns(:results)
76 assert_equal 1, assigns(:results).size
77 end
78
79 def test_search_issues_should_search_private_notes_with_permission_only
80 Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
81 @request.session[:user_id] = 2
82
83 Role.find(1).add_permission! :view_private_notes
84 get :index, :q => 'searchkeyword', :issues => 1
85 assert_response :success
86 assert_include Issue.find(2), assigns(:results)
87
88 Role.find(1).remove_permission! :view_private_notes
89 get :index, :q => 'searchkeyword', :issues => 1
90 assert_response :success
91 assert_not_include Issue.find(2), assigns(:results)
92 end
93
94 def test_search_all_projects_with_scope_param
95 get :index, :q => 'issue', :scope => 'all'
96 assert_response :success
97 assert_template 'index'
98 assert assigns(:results).present?
99 end
100
101 def test_search_my_projects
102 @request.session[:user_id] = 2
103 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
104 assert_response :success
105 assert_template 'index'
106 assert assigns(:results).include?(Issue.find(1))
107 assert !assigns(:results).include?(Issue.find(5))
108 end
109
110 def test_search_my_projects_without_memberships
111 # anonymous user has no memberships
112 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
113 assert_response :success
114 assert_template 'index'
115 assert assigns(:results).empty?
116 end
117
61 def test_search_project_and_subprojects 118 def test_search_project_and_subprojects
62 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => '' 119 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
63 assert_response :success 120 assert_response :success
64 assert_template 'index' 121 assert_template 'index'
65 assert assigns(:results).include?(Issue.find(1)) 122 assert assigns(:results).include?(Issue.find(1))
130 results = assigns(:results) 187 results = assigns(:results)
131 assert_not_nil results 188 assert_not_nil results
132 assert_equal 1, results.size 189 assert_equal 1, results.size
133 end 190 end
134 191
192 def test_search_with_offset
193 get :index, :q => 'coo', :offset => '20080806073000'
194 assert_response :success
195 results = assigns(:results)
196 assert results.any?
197 assert results.map(&:event_datetime).max < '20080806T073000'.to_time
198 end
199
200 def test_search_previous_with_offset
201 get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
202 assert_response :success
203 results = assigns(:results)
204 assert results.any?
205 assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
206 end
207
135 def test_search_with_invalid_project_id 208 def test_search_with_invalid_project_id
136 get :index, :id => 195, :q => 'recipe' 209 get :index, :id => 195, :q => 'recipe'
137 assert_response 404 210 assert_response 404
138 assert_nil assigns(:results) 211 assert_nil assigns(:results)
139 end 212 end
157 230
158 def test_tokens_with_quotes 231 def test_tokens_with_quotes
159 get :index, :id => 1, :q => '"good bye" hello "bye bye"' 232 get :index, :id => 1, :q => '"good bye" hello "bye bye"'
160 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens) 233 assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
161 end 234 end
235
236 def test_results_should_be_escaped_once
237 assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once')
238 get :index, :q => 'escaped_once'
239 assert_response :success
240 assert_select '#search-results' do
241 assert_select 'dt.issue a', :text => /&lt;subject&gt;/
242 assert_select 'dd', :text => /&lt;description&gt;/
243 end
244 end
245
246 def test_keywords_should_be_highlighted
247 assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted')
248 get :index, :q => 'highlighted'
249 assert_response :success
250 assert_select '#search-results' do
251 assert_select 'dt.issue a span.highlight', :text => 'highlighted'
252 assert_select 'dd span.highlight', :text => 'highlighted'
253 end
254 end
162 end 255 end