summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/functional/search_controller_test.rb40
-rw-r--r--vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb5
2 files changed, 45 insertions, 0 deletions
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 9e48e7f2e..fc40ce2f0 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -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
diff --git a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
index ea29d3a1b..ed19dc736 100644
--- a/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
+++ b/vendor/plugins/acts_as_searchable/lib/acts_as_searchable.rb
@@ -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)