2007-04-30 12:52:39 +04:00
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
require 'search_controller'
|
|
|
|
|
|
|
|
# Re-raise errors caught by the controller.
|
|
|
|
class SearchController; def rescue_action(e) raise e end; end
|
|
|
|
|
|
|
|
class SearchControllerTest < Test::Unit::TestCase
|
2008-01-21 21:52:45 +03:00
|
|
|
fixtures :projects, :enabled_modules, :issues, :custom_fields, :custom_values
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-12-14 21:54:55 +03:00
|
|
|
def test_search_without_searchable_custom_fields
|
|
|
|
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
|
|
|
|
2007-04-30 12:52:39 +04:00
|
|
|
get :index, :id => 1
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
assert_not_nil assigns(:project)
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
assert results.include?(Issue.find(3))
|
|
|
|
end
|
|
|
|
|
2008-01-21 21:52:45 +03:00
|
|
|
def test_search_all_words
|
|
|
|
# 'all words' is on by default
|
|
|
|
get :index, :id => 1, :q => 'recipe updating saving'
|
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 1, results.size
|
|
|
|
assert results.include?(Issue.find(3))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_one_of_the_words
|
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
|
|
|
|
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
|
|
|
|
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
|
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 0, results.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_titles_only
|
|
|
|
get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
|
|
|
|
results = assigns(:results)
|
|
|
|
assert_not_nil results
|
|
|
|
assert_equal 2, results.size
|
|
|
|
end
|
|
|
|
|
2007-04-30 12:52:39 +04:00
|
|
|
def test_quick_jump_to_issue
|
|
|
|
# issue of a public project
|
|
|
|
get :index, :q => "3"
|
|
|
|
assert_redirected_to 'issues/show/3'
|
|
|
|
|
|
|
|
# issue of a private project
|
|
|
|
get :index, :q => "4"
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
end
|
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
|