2012-12-03 22:23:23 +00:00
|
|
|
# Redmine - project management software
|
2014-01-29 22:45:39 +00:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2012-12-03 22:23:23 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-04-30 08:52:39 +00:00
|
|
|
|
2012-12-03 22:23:23 +00:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2007-04-30 08:52:39 +00:00
|
|
|
|
2009-09-13 17:14:35 +00:00
|
|
|
class SearchControllerTest < ActionController::TestCase
|
2014-12-13 17:42:18 +00:00
|
|
|
fixtures :projects, :projects_trackers,
|
|
|
|
|
:enabled_modules, :roles, :users, :members, :member_roles,
|
2012-11-01 22:47:44 +00:00
|
|
|
:issues, :trackers, :issue_statuses, :enumerations,
|
2008-05-18 16:15:22 +00:00
|
|
|
:custom_fields, :custom_values,
|
2014-07-13 02:44:12 +00:00
|
|
|
:custom_fields_projects, :custom_fields_trackers,
|
2008-05-18 16:15:22 +00:00
|
|
|
:repositories, :changesets
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-04-30 08:52:39 +00:00
|
|
|
def setup
|
2007-08-29 16:52:35 +00:00
|
|
|
User.current = nil
|
2007-04-30 08:52:39 +00:00
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-04-30 08:52:39 +00:00
|
|
|
def test_search_for_projects
|
|
|
|
|
get :index
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
|
|
|
|
|
get :index, :q => "cook"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
assert assigns(:results).include?(Project.find(1))
|
|
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2014-12-05 08:48:29 +00:00
|
|
|
def test_search_on_archived_project_should_return_404
|
|
|
|
|
Project.find(3).archive
|
|
|
|
|
get :index, :id => 3
|
|
|
|
|
assert_response 404
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_on_invisible_project_by_user_should_be_denied
|
|
|
|
|
@request.session[:user_id] = 7
|
|
|
|
|
get :index, :id => 2
|
|
|
|
|
assert_response 403
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_on_invisible_project_by_anonymous_user_should_redirect
|
|
|
|
|
get :index, :id => 2
|
|
|
|
|
assert_response 302
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_on_private_project_by_member_should_succeed
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
get :index, :id => 2
|
|
|
|
|
assert_response :success
|
|
|
|
|
end
|
|
|
|
|
|
2008-05-18 16:15:22 +00:00
|
|
|
def test_search_all_projects
|
2014-10-22 17:37:16 +00:00
|
|
|
with_settings :default_language => 'en' do
|
|
|
|
|
get :index, :q => 'recipe subproject commit', :all_words => ''
|
|
|
|
|
end
|
2008-05-18 16:15:22 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2008-05-18 16:15:22 +00:00
|
|
|
assert assigns(:results).include?(Issue.find(2))
|
|
|
|
|
assert assigns(:results).include?(Issue.find(5))
|
|
|
|
|
assert assigns(:results).include?(Changeset.find(101))
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'dt.issue a', :text => /Add ingredients categories/
|
|
|
|
|
assert_select 'dd', :text => /should be classified by categories/
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2014-12-12 20:49:31 +00:00
|
|
|
assert assigns(:result_count_by_type).is_a?(Hash)
|
|
|
|
|
assert_equal 5, assigns(:result_count_by_type)['changesets']
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'a', :text => 'Changesets (5)'
|
2008-05-18 16:15:22 +00:00
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2009-01-11 11:01:35 +00:00
|
|
|
def test_search_issues
|
|
|
|
|
get :index, :q => 'issue', :issues => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2011-07-09 11:25:01 +00:00
|
|
|
assert_equal true, assigns(:all_words)
|
|
|
|
|
assert_equal false, assigns(:titles_only)
|
2009-01-11 11:01:35 +00:00
|
|
|
assert assigns(:results).include?(Issue.find(8))
|
|
|
|
|
assert assigns(:results).include?(Issue.find(5))
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'dt.issue.closed a', :text => /Closed/
|
2009-01-11 11:01:35 +00:00
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2012-10-03 21:36:19 +00:00
|
|
|
def test_search_issues_should_search_notes
|
|
|
|
|
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
|
|
|
|
|
|
|
|
|
|
get :index, :q => 'searchkeyword', :issues => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_include Issue.find(2), assigns(:results)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_issues_with_multiple_matches_in_journals_should_return_issue_once
|
|
|
|
|
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
|
|
|
|
|
Journal.create!(:journalized => Issue.find(2), :notes => 'Issue notes with searchkeyword')
|
|
|
|
|
|
|
|
|
|
get :index, :q => 'searchkeyword', :issues => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_include Issue.find(2), assigns(:results)
|
|
|
|
|
assert_equal 1, assigns(:results).size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_issues_should_search_private_notes_with_permission_only
|
|
|
|
|
Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
|
|
|
|
Role.find(1).add_permission! :view_private_notes
|
|
|
|
|
get :index, :q => 'searchkeyword', :issues => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_include Issue.find(2), assigns(:results)
|
|
|
|
|
|
|
|
|
|
Role.find(1).remove_permission! :view_private_notes
|
|
|
|
|
get :index, :q => 'searchkeyword', :issues => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_not_include Issue.find(2), assigns(:results)
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 18:23:53 +00:00
|
|
|
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
|
|
|
|
|
|
2008-05-20 20:31:04 +00:00
|
|
|
def test_search_project_and_subprojects
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
|
2008-05-20 20:31:04 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
assert assigns(:results).include?(Issue.find(1))
|
|
|
|
|
assert assigns(:results).include?(Issue.find(5))
|
|
|
|
|
end
|
|
|
|
|
|
2007-12-14 18:54:55 +00:00
|
|
|
def test_search_without_searchable_custom_fields
|
|
|
|
|
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-04-30 08:52:39 +00:00
|
|
|
get :index, :id => 1
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
assert_not_nil assigns(:project)
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-09-27 17:28:22 +00:00
|
|
|
get :index, :id => 1, :q => "can"
|
2007-04-30 08:52:39 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-12-14 18:54:55 +00:00
|
|
|
def test_search_with_searchable_custom_fields
|
|
|
|
|
get :index, :id => 1, :q => "stringforcustomfield"
|
|
|
|
|
assert_response :success
|
|
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 1, results.size
|
2010-12-11 10:47:00 +00:00
|
|
|
assert results.include?(Issue.find(7))
|
2007-12-14 18:54:55 +00:00
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2008-01-21 18:52:45 +00:00
|
|
|
def test_search_all_words
|
|
|
|
|
# 'all words' is on by default
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
|
|
|
|
|
assert_equal true, assigns(:all_words)
|
2008-01-21 18:52:45 +00:00
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 1, results.size
|
|
|
|
|
assert results.include?(Issue.find(3))
|
|
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2008-01-21 18:52:45 +00:00
|
|
|
def test_search_one_of_the_words
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
|
|
|
|
|
assert_equal false, assigns(:all_words)
|
2008-01-21 18:52:45 +00:00
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 3, results.size
|
|
|
|
|
assert results.include?(Issue.find(3))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_titles_only_without_result
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
|
2008-01-21 18:52:45 +00:00
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 0, results.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_search_titles_only
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'recipe', :titles_only => '1'
|
|
|
|
|
assert_equal true, assigns(:titles_only)
|
2008-01-21 18:52:45 +00:00
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 2, results.size
|
|
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2011-07-09 11:25:01 +00:00
|
|
|
def test_search_content
|
2014-01-11 09:25:12 +00:00
|
|
|
Issue.where(:id => 1).update_all("description = 'This is a searchkeywordinthecontent'")
|
2011-07-09 11:25:01 +00:00
|
|
|
get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => ''
|
|
|
|
|
assert_equal false, assigns(:titles_only)
|
|
|
|
|
results = assigns(:results)
|
|
|
|
|
assert_not_nil results
|
|
|
|
|
assert_equal 1, results.size
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-12 20:49:31 +00:00
|
|
|
def test_search_with_pagination
|
|
|
|
|
issue = (0..24).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse
|
|
|
|
|
|
|
|
|
|
get :index, :q => 'search_with_limited_results'
|
2011-12-17 18:23:53 +00:00
|
|
|
assert_response :success
|
2014-12-12 20:49:31 +00:00
|
|
|
assert_equal issue[0..9], assigns(:results)
|
2011-12-17 18:23:53 +00:00
|
|
|
|
2014-12-12 20:49:31 +00:00
|
|
|
get :index, :q => 'search_with_limited_results', :page => 2
|
2011-12-17 18:23:53 +00:00
|
|
|
assert_response :success
|
2014-12-12 20:49:31 +00:00
|
|
|
assert_equal issue[10..19], assigns(:results)
|
|
|
|
|
|
|
|
|
|
get :index, :q => 'search_with_limited_results', :page => 3
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_equal issue[20..24], assigns(:results)
|
|
|
|
|
|
|
|
|
|
get :index, :q => 'search_with_limited_results', :page => 4
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_equal [], assigns(:results)
|
2011-12-17 18:23:53 +00:00
|
|
|
end
|
|
|
|
|
|
2008-03-12 20:50:48 +00:00
|
|
|
def test_search_with_invalid_project_id
|
|
|
|
|
get :index, :id => 195, :q => 'recipe'
|
|
|
|
|
assert_response 404
|
|
|
|
|
assert_nil assigns(:results)
|
|
|
|
|
end
|
|
|
|
|
|
2007-04-30 08:52:39 +00:00
|
|
|
def test_quick_jump_to_issue
|
|
|
|
|
# issue of a public project
|
|
|
|
|
get :index, :q => "3"
|
2010-11-14 16:45:32 +00:00
|
|
|
assert_redirected_to '/issues/3'
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-04-30 08:52:39 +00:00
|
|
|
# issue of a private project
|
|
|
|
|
get :index, :q => "4"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
end
|
2010-06-20 20:01:32 +00:00
|
|
|
|
|
|
|
|
def test_large_integer
|
|
|
|
|
get :index, :q => '4615713488'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template 'index'
|
|
|
|
|
end
|
2011-05-16 22:56:25 +00:00
|
|
|
|
2007-11-29 20:08:14 +00:00
|
|
|
def test_tokens_with_quotes
|
|
|
|
|
get :index, :id => 1, :q => '"good bye" hello "bye bye"'
|
|
|
|
|
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
|
|
|
|
|
end
|
2012-08-10 16:22:26 +00:00
|
|
|
|
|
|
|
|
def test_results_should_be_escaped_once
|
|
|
|
|
assert Issue.find(1).update_attributes(:subject => '<subject> escaped_once', :description => '<description> escaped_once')
|
|
|
|
|
get :index, :q => 'escaped_once'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select '#search-results' do
|
|
|
|
|
assert_select 'dt.issue a', :text => /<subject>/
|
|
|
|
|
assert_select 'dd', :text => /<description>/
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_keywords_should_be_highlighted
|
|
|
|
|
assert Issue.find(1).update_attributes(:subject => 'subject highlighted', :description => 'description highlighted')
|
|
|
|
|
get :index, :q => 'highlighted'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select '#search-results' do
|
|
|
|
|
assert_select 'dt.issue a span.highlight', :text => 'highlighted'
|
|
|
|
|
assert_select 'dd span.highlight', :text => 'highlighted'
|
|
|
|
|
end
|
|
|
|
|
end
|
2007-04-30 08:52:39 +00:00
|
|
|
end
|