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