Additional tests for SearchController and handle my_projects scope without memberships.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8266 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-17 18:23:53 +00:00
parent 199eaff14e
commit bb0cd34f4e
2 changed files with 45 additions and 0 deletions

View File

@ -58,6 +58,30 @@ class SearchControllerTest < ActionController::TestCase
: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
@ -132,6 +156,22 @@ class SearchControllerTest < ActionController::TestCase
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

View File

@ -62,6 +62,11 @@ module Redmine
# projects argument can be either nil (will search all projects), a project or an array of projects
# Returns the results and the results count
def search(tokens, projects=nil, options={})
if projects.is_a?(Array) && projects.empty?
# no results
return [[], 0]
end
# TODO: make user an argument
user = User.current
tokens = [] << tokens unless tokens.is_a?(Array)