@@ -1,241 +1,241 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 |
# |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 |
# |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'queries_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class QueriesController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class QueriesControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = QueriesController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_get_new_project_query |
|
35 | 35 | @request.session[:user_id] = 2 |
|
36 | 36 | get :new, :project_id => 1 |
|
37 | 37 | assert_response :success |
|
38 | 38 | assert_template 'new' |
|
39 | 39 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
40 | 40 | :name => 'query[is_public]', |
|
41 | 41 |
:checked => nil } |
|
42 | 42 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
43 | 43 | :name => 'query_is_for_all', |
|
44 | 44 | :checked => nil, |
|
45 | 45 | :disabled => nil } |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_get_new_global_query |
|
49 | 49 | @request.session[:user_id] = 2 |
|
50 | 50 | get :new |
|
51 | 51 | assert_response :success |
|
52 | 52 | assert_template 'new' |
|
53 | 53 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
54 | 54 |
:name => 'query[is_public]' } |
|
55 | 55 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
56 | 56 | :name => 'query_is_for_all', |
|
57 | 57 | :checked => 'checked', |
|
58 | 58 | :disabled => nil } |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_new_project_public_query |
|
62 | 62 | @request.session[:user_id] = 2 |
|
63 | 63 | post :new, |
|
64 | 64 |
:project_id => 'ecookbook', |
|
65 | 65 | :confirm => '1', |
|
66 | 66 | :default_columns => '1', |
|
67 | 67 | :f => ["status_id", "assigned_to_id"], |
|
68 | 68 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
69 | 69 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
70 | 70 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
71 | 71 | |
|
72 | 72 | q = Query.find_by_name('test_new_project_public_query') |
|
73 | 73 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
74 | 74 | assert q.is_public? |
|
75 | 75 | assert q.has_default_columns? |
|
76 | 76 | assert q.valid? |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def test_new_project_private_query |
|
80 | 80 | @request.session[:user_id] = 3 |
|
81 | 81 | post :new, |
|
82 | 82 |
:project_id => 'ecookbook', |
|
83 | 83 | :confirm => '1', |
|
84 | 84 | :default_columns => '1', |
|
85 | 85 | :fields => ["status_id", "assigned_to_id"], |
|
86 | 86 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
87 | 87 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
88 | 88 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
89 | 89 | |
|
90 | 90 | q = Query.find_by_name('test_new_project_private_query') |
|
91 | 91 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
92 | 92 | assert !q.is_public? |
|
93 | 93 | assert q.has_default_columns? |
|
94 | 94 | assert q.valid? |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def test_new_global_private_query_with_custom_columns |
|
98 | 98 | @request.session[:user_id] = 3 |
|
99 | 99 | post :new, |
|
100 | 100 | :confirm => '1', |
|
101 | 101 | :fields => ["status_id", "assigned_to_id"], |
|
102 | 102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
103 | 103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
104 | 104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
|
105 | 105 | :c => ["", "tracker", "subject", "priority", "category"] |
|
106 | 106 | |
|
107 | 107 | q = Query.find_by_name('test_new_global_private_query') |
|
108 | 108 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
109 | 109 | assert !q.is_public? |
|
110 | 110 | assert !q.has_default_columns? |
|
111 | 111 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
112 | 112 | assert q.valid? |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def test_new_with_sort |
|
116 | 116 | @request.session[:user_id] = 1 |
|
117 | 117 | post :new, |
|
118 | 118 | :confirm => '1', |
|
119 | 119 | :default_columns => '1', |
|
120 | 120 | :operators => {"status_id" => "o"}, |
|
121 | 121 | :values => {"status_id" => ["1"]}, |
|
122 | 122 | :query => {:name => "test_new_with_sort", |
|
123 | 123 |
:is_public => "1", |
|
124 | 124 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
125 | 125 | |
|
126 | 126 | query = Query.find_by_name("test_new_with_sort") |
|
127 | 127 | assert_not_nil query |
|
128 | 128 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | def test_get_edit_global_public_query |
|
132 | 132 | @request.session[:user_id] = 1 |
|
133 | 133 | get :edit, :id => 4 |
|
134 | 134 | assert_response :success |
|
135 | 135 | assert_template 'edit' |
|
136 | 136 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
137 | 137 | :name => 'query[is_public]', |
|
138 | 138 |
:checked => 'checked' } |
|
139 | 139 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
140 | 140 | :name => 'query_is_for_all', |
|
141 | 141 | :checked => 'checked', |
|
142 | 142 | :disabled => 'disabled' } |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | def test_edit_global_public_query |
|
146 | 146 | @request.session[:user_id] = 1 |
|
147 | 147 | post :edit, |
|
148 | 148 |
:id => 4, |
|
149 | 149 | :confirm => '1', |
|
150 | 150 | :default_columns => '1', |
|
151 | 151 | :fields => ["status_id", "assigned_to_id"], |
|
152 | 152 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
153 | 153 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
154 | 154 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
155 | 155 | |
|
156 | 156 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
157 | 157 | q = Query.find_by_name('test_edit_global_public_query') |
|
158 | 158 | assert q.is_public? |
|
159 | 159 | assert q.has_default_columns? |
|
160 | 160 | assert q.valid? |
|
161 | 161 | end |
|
162 | 162 | |
|
163 | 163 | def test_get_edit_global_private_query |
|
164 | 164 | @request.session[:user_id] = 3 |
|
165 | 165 | get :edit, :id => 3 |
|
166 | 166 | assert_response :success |
|
167 | 167 | assert_template 'edit' |
|
168 | 168 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
169 | 169 |
:name => 'query[is_public]' } |
|
170 | 170 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
171 | 171 | :name => 'query_is_for_all', |
|
172 | 172 | :checked => 'checked', |
|
173 | 173 | :disabled => 'disabled' } |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def test_edit_global_private_query |
|
177 | 177 | @request.session[:user_id] = 3 |
|
178 | 178 | post :edit, |
|
179 | 179 |
:id => 3, |
|
180 | 180 | :confirm => '1', |
|
181 | 181 | :default_columns => '1', |
|
182 | 182 | :fields => ["status_id", "assigned_to_id"], |
|
183 | 183 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
184 | 184 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
185 | 185 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
186 | 186 | |
|
187 | 187 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
188 | 188 | q = Query.find_by_name('test_edit_global_private_query') |
|
189 | 189 | assert !q.is_public? |
|
190 | 190 | assert q.has_default_columns? |
|
191 | 191 | assert q.valid? |
|
192 | 192 | end |
|
193 | 193 | |
|
194 | 194 | def test_get_edit_project_private_query |
|
195 | 195 | @request.session[:user_id] = 3 |
|
196 | 196 | get :edit, :id => 2 |
|
197 | 197 | assert_response :success |
|
198 | 198 | assert_template 'edit' |
|
199 | 199 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
200 | 200 |
:name => 'query[is_public]' } |
|
201 | 201 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
202 | 202 | :name => 'query_is_for_all', |
|
203 | 203 | :checked => nil, |
|
204 | 204 | :disabled => nil } |
|
205 | 205 | end |
|
206 | 206 | |
|
207 | 207 | def test_get_edit_project_public_query |
|
208 | 208 | @request.session[:user_id] = 2 |
|
209 | 209 | get :edit, :id => 1 |
|
210 | 210 | assert_response :success |
|
211 | 211 | assert_template 'edit' |
|
212 | 212 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
213 | 213 | :name => 'query[is_public]', |
|
214 | 214 | :checked => 'checked' |
|
215 | 215 |
} |
|
216 | 216 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
217 | 217 | :name => 'query_is_for_all', |
|
218 | 218 | :checked => nil, |
|
219 | 219 | :disabled => 'disabled' } |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def test_get_edit_sort_criteria |
|
223 | 223 | @request.session[:user_id] = 1 |
|
224 | 224 | get :edit, :id => 5 |
|
225 | 225 | assert_response :success |
|
226 | 226 | assert_template 'edit' |
|
227 | 227 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
228 | 228 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
|
229 | 229 | :selected => 'selected' } } |
|
230 | 230 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
231 | 231 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
|
232 | 232 | :selected => 'selected' } } |
|
233 | 233 | end |
|
234 | 234 | |
|
235 | 235 | def test_destroy |
|
236 | 236 | @request.session[:user_id] = 2 |
|
237 | 237 | post :destroy, :id => 1 |
|
238 | 238 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
239 | 239 | assert_nil Query.find_by_id(1) |
|
240 | 240 | end |
|
241 | 241 | end |
General Comments 0
You need to be logged in to leave comments.
Login now