To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 3b / 3b0a04b81b3503971b4e570669380aa1831579cc.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (5.02 KB)
| 1 |
require File.expand_path('../../test_helper', __FILE__)
|
|---|---|
| 2 |
require 'search_controller' |
| 3 |
|
| 4 |
# Re-raise errors caught by the controller. |
| 5 |
class SearchController; def rescue_action(e) raise e end; end |
| 6 |
|
| 7 |
class SearchControllerTest < ActionController::TestCase |
| 8 |
fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles, |
| 9 |
:issues, :trackers, :issue_statuses, |
| 10 |
:custom_fields, :custom_values, |
| 11 |
:repositories, :changesets |
| 12 |
|
| 13 |
def setup |
| 14 |
@controller = SearchController.new |
| 15 |
@request = ActionController::TestRequest.new |
| 16 |
@response = ActionController::TestResponse.new |
| 17 |
User.current = nil |
| 18 |
end |
| 19 |
|
| 20 |
def test_search_for_projects |
| 21 |
get :index |
| 22 |
assert_response :success |
| 23 |
assert_template 'index' |
| 24 |
|
| 25 |
get :index, :q => "cook" |
| 26 |
assert_response :success |
| 27 |
assert_template 'index' |
| 28 |
assert assigns(:results).include?(Project.find(1)) |
| 29 |
end |
| 30 |
|
| 31 |
def test_search_all_projects |
| 32 |
get :index, :q => 'recipe subproject commit', :all_words => '' |
| 33 |
assert_response :success |
| 34 |
assert_template 'index' |
| 35 |
|
| 36 |
assert assigns(:results).include?(Issue.find(2)) |
| 37 |
assert assigns(:results).include?(Issue.find(5)) |
| 38 |
assert assigns(:results).include?(Changeset.find(101)) |
| 39 |
assert_tag :dt, :attributes => { :class => /issue/ },
|
| 40 |
:child => { :tag => 'a', :content => /Add ingredients categories/ },
|
| 41 |
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
|
| 42 |
|
| 43 |
assert assigns(:results_by_type).is_a?(Hash) |
| 44 |
assert_equal 5, assigns(:results_by_type)['changesets'] |
| 45 |
assert_tag :a, :content => 'Changesets (5)' |
| 46 |
end |
| 47 |
|
| 48 |
def test_search_issues |
| 49 |
get :index, :q => 'issue', :issues => 1 |
| 50 |
assert_response :success |
| 51 |
assert_template 'index' |
| 52 |
|
| 53 |
assert_equal true, assigns(:all_words) |
| 54 |
assert_equal false, assigns(:titles_only) |
| 55 |
assert assigns(:results).include?(Issue.find(8)) |
| 56 |
assert assigns(:results).include?(Issue.find(5)) |
| 57 |
assert_tag :dt, :attributes => { :class => /issue closed/ },
|
| 58 |
:child => { :tag => 'a', :content => /Closed/ }
|
| 59 |
end |
| 60 |
|
| 61 |
def test_search_project_and_subprojects |
| 62 |
get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => '' |
| 63 |
assert_response :success |
| 64 |
assert_template 'index' |
| 65 |
assert assigns(:results).include?(Issue.find(1)) |
| 66 |
assert assigns(:results).include?(Issue.find(5)) |
| 67 |
end |
| 68 |
|
| 69 |
def test_search_without_searchable_custom_fields |
| 70 |
CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
|
| 71 |
|
| 72 |
get :index, :id => 1 |
| 73 |
assert_response :success |
| 74 |
assert_template 'index' |
| 75 |
assert_not_nil assigns(:project) |
| 76 |
|
| 77 |
get :index, :id => 1, :q => "can" |
| 78 |
assert_response :success |
| 79 |
assert_template 'index' |
| 80 |
end |
| 81 |
|
| 82 |
def test_search_with_searchable_custom_fields |
| 83 |
get :index, :id => 1, :q => "stringforcustomfield" |
| 84 |
assert_response :success |
| 85 |
results = assigns(:results) |
| 86 |
assert_not_nil results |
| 87 |
assert_equal 1, results.size |
| 88 |
assert results.include?(Issue.find(7)) |
| 89 |
end |
| 90 |
|
| 91 |
def test_search_all_words |
| 92 |
# 'all words' is on by default |
| 93 |
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1' |
| 94 |
assert_equal true, assigns(:all_words) |
| 95 |
results = assigns(:results) |
| 96 |
assert_not_nil results |
| 97 |
assert_equal 1, results.size |
| 98 |
assert results.include?(Issue.find(3)) |
| 99 |
end |
| 100 |
|
| 101 |
def test_search_one_of_the_words |
| 102 |
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '' |
| 103 |
assert_equal false, assigns(:all_words) |
| 104 |
results = assigns(:results) |
| 105 |
assert_not_nil results |
| 106 |
assert_equal 3, results.size |
| 107 |
assert results.include?(Issue.find(3)) |
| 108 |
end |
| 109 |
|
| 110 |
def test_search_titles_only_without_result |
| 111 |
get :index, :id => 1, :q => 'recipe updating saving', :titles_only => '1' |
| 112 |
results = assigns(:results) |
| 113 |
assert_not_nil results |
| 114 |
assert_equal 0, results.size |
| 115 |
end |
| 116 |
|
| 117 |
def test_search_titles_only |
| 118 |
get :index, :id => 1, :q => 'recipe', :titles_only => '1' |
| 119 |
assert_equal true, assigns(:titles_only) |
| 120 |
results = assigns(:results) |
| 121 |
assert_not_nil results |
| 122 |
assert_equal 2, results.size |
| 123 |
end |
| 124 |
|
| 125 |
def test_search_content |
| 126 |
Issue.update_all("description = 'This is a searchkeywordinthecontent'", "id=1")
|
| 127 |
|
| 128 |
get :index, :id => 1, :q => 'searchkeywordinthecontent', :titles_only => '' |
| 129 |
assert_equal false, assigns(:titles_only) |
| 130 |
results = assigns(:results) |
| 131 |
assert_not_nil results |
| 132 |
assert_equal 1, results.size |
| 133 |
end |
| 134 |
|
| 135 |
def test_search_with_invalid_project_id |
| 136 |
get :index, :id => 195, :q => 'recipe' |
| 137 |
assert_response 404 |
| 138 |
assert_nil assigns(:results) |
| 139 |
end |
| 140 |
|
| 141 |
def test_quick_jump_to_issue |
| 142 |
# issue of a public project |
| 143 |
get :index, :q => "3" |
| 144 |
assert_redirected_to '/issues/3' |
| 145 |
|
| 146 |
# issue of a private project |
| 147 |
get :index, :q => "4" |
| 148 |
assert_response :success |
| 149 |
assert_template 'index' |
| 150 |
end |
| 151 |
|
| 152 |
def test_large_integer |
| 153 |
get :index, :q => '4615713488' |
| 154 |
assert_response :success |
| 155 |
assert_template 'index' |
| 156 |
end |
| 157 |
|
| 158 |
def test_tokens_with_quotes |
| 159 |
get :index, :id => 1, :q => '"good bye" hello "bye bye"' |
| 160 |
assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens) |
| 161 |
end |
| 162 |
end |