To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / .svn / text-base / search_controller_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (4.53 KB)

1 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
2 0:513646585e45 Chris
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 441:cbce1fd3b1b7 Chris
13 0:513646585e45 Chris
  def setup
14
    @controller = SearchController.new
15
    @request    = ActionController::TestRequest.new
16
    @response   = ActionController::TestResponse.new
17
    User.current = nil
18
  end
19 441:cbce1fd3b1b7 Chris
20 0:513646585e45 Chris
  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 441:cbce1fd3b1b7 Chris
31 0:513646585e45 Chris
  def test_search_all_projects
32
    get :index, :q => 'recipe subproject commit', :submit => 'Search'
33
    assert_response :success
34
    assert_template 'index'
35 441:cbce1fd3b1b7 Chris
36 0:513646585e45 Chris
    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 441:cbce1fd3b1b7 Chris
43 0:513646585e45 Chris
    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 441:cbce1fd3b1b7 Chris
48 0:513646585e45 Chris
  def test_search_issues
49
    get :index, :q => 'issue', :issues => 1
50
    assert_response :success
51
    assert_template 'index'
52 441:cbce1fd3b1b7 Chris
53 0:513646585e45 Chris
    assert assigns(:results).include?(Issue.find(8))
54
    assert assigns(:results).include?(Issue.find(5))
55
    assert_tag :dt, :attributes => { :class => /issue closed/ },
56
                    :child => { :tag => 'a',  :content => /Closed/ }
57
  end
58 441:cbce1fd3b1b7 Chris
59 0:513646585e45 Chris
  def test_search_project_and_subprojects
60
    get :index, :id => 1, :q => 'recipe subproject', :scope => 'subprojects', :submit => 'Search'
61
    assert_response :success
62
    assert_template 'index'
63
    assert assigns(:results).include?(Issue.find(1))
64
    assert assigns(:results).include?(Issue.find(5))
65
  end
66
67
  def test_search_without_searchable_custom_fields
68
    CustomField.update_all "searchable = #{ActiveRecord::Base.connection.quoted_false}"
69 441:cbce1fd3b1b7 Chris
70 0:513646585e45 Chris
    get :index, :id => 1
71
    assert_response :success
72
    assert_template 'index'
73
    assert_not_nil assigns(:project)
74 441:cbce1fd3b1b7 Chris
75 0:513646585e45 Chris
    get :index, :id => 1, :q => "can"
76
    assert_response :success
77
    assert_template 'index'
78
  end
79 441:cbce1fd3b1b7 Chris
80 0:513646585e45 Chris
  def test_search_with_searchable_custom_fields
81
    get :index, :id => 1, :q => "stringforcustomfield"
82
    assert_response :success
83
    results = assigns(:results)
84
    assert_not_nil results
85
    assert_equal 1, results.size
86 119:8661b858af72 Chris
    assert results.include?(Issue.find(7))
87 0:513646585e45 Chris
  end
88 441:cbce1fd3b1b7 Chris
89 0:513646585e45 Chris
  def test_search_all_words
90
    # 'all words' is on by default
91
    get :index, :id => 1, :q => 'recipe updating saving'
92
    results = assigns(:results)
93
    assert_not_nil results
94
    assert_equal 1, results.size
95
    assert results.include?(Issue.find(3))
96
  end
97 441:cbce1fd3b1b7 Chris
98 0:513646585e45 Chris
  def test_search_one_of_the_words
99
    get :index, :id => 1, :q => 'recipe updating saving', :submit => 'Search'
100
    results = assigns(:results)
101
    assert_not_nil results
102
    assert_equal 3, results.size
103
    assert results.include?(Issue.find(3))
104
  end
105
106
  def test_search_titles_only_without_result
107
    get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1', :titles_only => '1', :submit => 'Search'
108
    results = assigns(:results)
109
    assert_not_nil results
110
    assert_equal 0, results.size
111
  end
112
113
  def test_search_titles_only
114
    get :index, :id => 1, :q => 'recipe', :titles_only => '1', :submit => 'Search'
115
    results = assigns(:results)
116
    assert_not_nil results
117
    assert_equal 2, results.size
118
  end
119 441:cbce1fd3b1b7 Chris
120 0:513646585e45 Chris
  def test_search_with_invalid_project_id
121
    get :index, :id => 195, :q => 'recipe'
122
    assert_response 404
123
    assert_nil assigns(:results)
124
  end
125
126
  def test_quick_jump_to_issue
127
    # issue of a public project
128
    get :index, :q => "3"
129 37:94944d00e43c chris
    assert_redirected_to '/issues/3'
130 441:cbce1fd3b1b7 Chris
131 0:513646585e45 Chris
    # issue of a private project
132
    get :index, :q => "4"
133
    assert_response :success
134
    assert_template 'index'
135
  end
136
137
  def test_large_integer
138
    get :index, :q => '4615713488'
139
    assert_response :success
140
    assert_template 'index'
141
  end
142 441:cbce1fd3b1b7 Chris
143 0:513646585e45 Chris
  def test_tokens_with_quotes
144
    get :index, :id => 1, :q => '"good bye" hello "bye bye"'
145
    assert_equal ["good bye", "hello", "bye bye"], assigns(:tokens)
146
  end
147
end