##// END OF EJS Templates
Additional tests for SearchController and handle my_projects scope without memberships....
Jean-Philippe Lang -
r8146:bb0cd34f4e2e
parent child
Show More
@@ -58,6 +58,30 class SearchControllerTest < ActionController::TestCase
58 58 :child => { :tag => 'a', :content => /Closed/ }
59 59 end
60 60
61 def test_search_all_projects_with_scope_param
62 get :index, :q => 'issue', :scope => 'all'
63 assert_response :success
64 assert_template 'index'
65 assert assigns(:results).present?
66 end
67
68 def test_search_my_projects
69 @request.session[:user_id] = 2
70 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
71 assert_response :success
72 assert_template 'index'
73 assert assigns(:results).include?(Issue.find(1))
74 assert !assigns(:results).include?(Issue.find(5))
75 end
76
77 def test_search_my_projects_without_memberships
78 # anonymous user has no memberships
79 get :index, :id => 1, :q => 'recipe subproject', :scope => 'my_projects', :all_words => ''
80 assert_response :success
81 assert_template 'index'
82 assert assigns(:results).empty?
83 end
84
61 85 def test_search_project_and_subprojects
62 86 get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
63 87 assert_response :success
@@ -132,6 +156,22 class SearchControllerTest < ActionController::TestCase
132 156 assert_equal 1, results.size
133 157 end
134 158
159 def test_search_with_offset
160 get :index, :q => 'coo', :offset => '20080806073000'
161 assert_response :success
162 results = assigns(:results)
163 assert results.any?
164 assert results.map(&:event_datetime).max < '20080806T073000'.to_time
165 end
166
167 def test_search_previous_with_offset
168 get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
169 assert_response :success
170 results = assigns(:results)
171 assert results.any?
172 assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
173 end
174
135 175 def test_search_with_invalid_project_id
136 176 get :index, :id => 195, :q => 'recipe'
137 177 assert_response 404
@@ -62,6 +62,11 module Redmine
62 62 # projects argument can be either nil (will search all projects), a project or an array of projects
63 63 # Returns the results and the results count
64 64 def search(tokens, projects=nil, options={})
65 if projects.is_a?(Array) && projects.empty?
66 # no results
67 return [[], 0]
68 end
69
65 70 # TODO: make user an argument
66 71 user = User.current
67 72 tokens = [] << tokens unless tokens.is_a?(Array)
General Comments 0
You need to be logged in to leave comments. Login now