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