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:
parent
199eaff14e
commit
bb0cd34f4e
@ -58,6 +58,30 @@ class SearchControllerTest < ActionController::TestCase
|
|||||||
:child => { :tag => 'a', :content => /Closed/ }
|
:child => { :tag => 'a', :content => /Closed/ }
|
||||||
end
|
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
|
def test_search_project_and_subprojects
|
||||||
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
|
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@ -132,6 +156,22 @@ class SearchControllerTest < ActionController::TestCase
|
|||||||
assert_equal 1, results.size
|
assert_equal 1, results.size
|
||||||
end
|
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
|
def test_search_with_invalid_project_id
|
||||||
get :index, :id => 195, :q => 'recipe'
|
get :index, :id => 195, :q => 'recipe'
|
||||||
assert_response 404
|
assert_response 404
|
||||||
|
@ -62,6 +62,11 @@ module Redmine
|
|||||||
# projects argument can be either nil (will search all projects), a project or an array of projects
|
# projects argument can be either nil (will search all projects), a project or an array of projects
|
||||||
# Returns the results and the results count
|
# Returns the results and the results count
|
||||||
def search(tokens, projects=nil, options={})
|
def search(tokens, projects=nil, options={})
|
||||||
|
if projects.is_a?(Array) && projects.empty?
|
||||||
|
# no results
|
||||||
|
return [[], 0]
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: make user an argument
|
# TODO: make user an argument
|
||||||
user = User.current
|
user = User.current
|
||||||
tokens = [] << tokens unless tokens.is_a?(Array)
|
tokens = [] << tokens unless tokens.is_a?(Array)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user