2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2007-04-30 12:52:39 +04:00
|
|
|
require 'search_controller'
|
|
|
|
|
|
|
|
# Re-raise errors caught by the controller.
|
|
|
|
class SearchController; def rescue_action(e) raise e end; end
|
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class SearchControllerTest < ActionController::TestCase
|
2009-05-10 14:54:31 +04:00
|
|
|
fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
|
2008-05-18 20:15:22 +04:00
|
|
|
:issues, :trackers, :issue_statuses,
|
|
|
|
:custom_fields, :custom_values,
|
|
|
|
:repositories, :changesets
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-04-30 12:52:39 +04:00
|
|
|
def setup
|
|
|
|
@controller = SearchController.new
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
2007-08-29 20:52:35 +04:00
|
|
|
User.current = nil
|
2007-04-30 12:52:39 +04:00
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-04-30 12:52:39 +04: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-17 02:56:25 +04:00
|
|
|
|
2008-05-18 20:15:22 +04:00
|
|
|
def test_search_all_projects
|
2011-07-09 15:25:01 +04:00
|
|
|
get :index, :q => 'recipe subproject commit', :all_words => ''
|
2008-05-18 20:15:22 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2008-05-18 20:15:22 +04:00
|
|
|
assert assigns(:results).include?(Issue.find(2))
|
|
|
|
assert assigns(:results).include?(Issue.find(5))
|
|
|
|
assert assigns(:results).include?(Changeset.find(101))
|
2008-07-20 21:26:07 +04:00
|
|
|
assert_tag :dt, :attributes => { :class => /issue/ },
|
|
|
|
:child => { :tag => 'a', :content => /Add ingredients categories/ },
|
|
|
|
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2008-07-20 21:26:07 +04:00
|
|
|
assert assigns(:results_by_type).is_a?(Hash)
|
2009-08-17 20:32:24 +04:00
|
|
|
assert_equal 5, assigns(:results_by_type)['changesets']
|
|
|
|
assert_tag :a, :content => 'Changesets (5)'
|
2008-05-18 20:15:22 +04:00
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2009-01-11 14:01:35 +03:00
|
|
|
def test_search_issues
|
|
|
|
get :index, :q => 'issue', :issues => 1
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2011-07-09 15:25:01 +04:00
|
|
|
assert_equal true, assigns(:all_words)
|
|
|
|
assert_equal false, assigns(:titles_only)
|
2009-01-11 14:01:35 +03:00
|
|
|
assert assigns(:results).include?(Issue.find(8))
|
|
|
|
assert assigns(:results).include?(Issue.find(5))
|
|
|
|
assert_tag :dt, :attributes => { :class => /issue closed/ },
|
|
|
|
:child => { :tag => 'a', :content => /Closed/ }
|
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2011-12-17 22:23:53 +04: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-21 00:31:04 +04:00
|
|
|
def test_search_project_and_subprojects
|
2011-07-09 15:25:01 +04:00
|
|
|
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''
|
2008-05-21 00:31:04 +04: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 21:54:55 +03:00
|
|
|
def test_search_without_searchable_custom_fields
|
|
|
|
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-04-30 12:52:39 +04:00
|
|
|
get :index, :id => 1
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
assert_not_nil assigns(:project)
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-09-27 21:28:22 +04:00
|
|
|
get :index, :id => 1, :q => "can"
|
2007-04-30 12:52:39 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-12-14 21:54:55 +03: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 13:47:00 +03:00
|
|
|
assert results.include?(Issue.find(7))
|
2007-12-14 21:54:55 +03:00
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2008-01-21 21:52:45 +03:00
|
|
|
def test_search_all_words
|
|
|
|
# 'all words' is on by default
|
2011-07-09 15:25:01 +04:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
|
|
|
|
assert_equal true, assigns(:all_words)
|
2008-01-21 21:52:45 +03:00
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 1, results.size
|
|
|
|
assert results.include?(Issue.find(3))
|
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2008-01-21 21:52:45 +03:00
|
|
|
def test_search_one_of_the_words
|
2011-07-09 15:25:01 +04:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :all_words => ''
|
|
|
|
assert_equal false, assigns(:all_words)
|
2008-01-21 21:52:45 +03: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 15:25:01 +04:00
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1'
|
2008-01-21 21:52:45 +03:00
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 0, results.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_titles_only
|
2011-07-09 15:25:01 +04:00
|
|
|
get :index, :id => 1, :q => 'recipe', :titles_only => '1'
|
|
|
|
assert_equal true, assigns(:titles_only)
|
2008-01-21 21:52:45 +03:00
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 2, results.size
|
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2011-07-09 15:25:01 +04:00
|
|
|
def test_search_content
|
|
|
|
Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
|
2011-09-01 02:57:34 +04:00
|
|
|
|
2011-07-09 15:25:01 +04: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
|
|
|
|
|
2011-12-17 22:23:53 +04:00
|
|
|
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
|
|
|
|
|
2008-03-12 23:50:48 +03: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 12:52:39 +04:00
|
|
|
def test_quick_jump_to_issue
|
|
|
|
# issue of a public project
|
|
|
|
get :index, :q => "3"
|
2010-11-14 19:45:32 +03:00
|
|
|
assert_redirected_to '/issues/3'
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-04-30 12:52:39 +04:00
|
|
|
# issue of a private project
|
|
|
|
get :index, :q => "4"
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
end
|
2010-06-21 00:01:32 +04:00
|
|
|
|
|
|
|
def test_large_integer
|
|
|
|
get :index, :q => '4615713488'
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
end
|
2011-05-17 02:56:25 +04:00
|
|
|
|
2007-11-29 23:08:14 +03: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
|
2007-04-30 12:52:39 +04:00
|
|
|
end
|