@@ -1,52 +1,52 | |||
|
1 | 1 | <%= error_messages_for 'query' %> |
|
2 | 2 | |
|
3 | 3 | <div class="box"> |
|
4 | 4 | <div class="tabular"> |
|
5 | 5 | <p><label for="query_name"><%=l(:field_name)%></label> |
|
6 | 6 | <%= text_field 'query', 'name', :size => 80 %></p> |
|
7 | 7 | |
|
8 | 8 | <% if User.current.admin? || User.current.allowed_to?(:manage_public_queries, @project) %> |
|
9 | 9 | <p><label for="query_is_public"><%=l(:field_is_public)%></label> |
|
10 | 10 | <%= check_box 'query', 'is_public', |
|
11 | 11 | :onchange => (User.current.admin? ? nil : 'if (this.checked) {$("query_is_for_all").checked = false; $("query_is_for_all").disabled = true;} else {$("query_is_for_all").disabled = false;}') %></p> |
|
12 | 12 | <% end %> |
|
13 | 13 | |
|
14 | 14 | <p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label> |
|
15 | 15 | <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, |
|
16 | 16 | :disabled => (!@query.new_record? && (@query.project.nil? || (@query.is_public? && !User.current.admin?))) %></p> |
|
17 | 17 | |
|
18 | 18 | <p><label for="query_default_columns"><%=l(:label_default_columns)%></label> |
|
19 | 19 | <%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns', |
|
20 | 20 | :onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p> |
|
21 | 21 | |
|
22 | 22 | <p><label for="query_group_by"><%= l(:field_group_by) %></label> |
|
23 | 23 | <%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p> |
|
24 | 24 | </div> |
|
25 | 25 | |
|
26 | 26 | <fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
27 | 27 | <%= render :partial => 'queries/filters', :locals => {:query => query}%> |
|
28 | 28 | </fieldset> |
|
29 | 29 | |
|
30 | 30 | <fieldset><legend><%= l(:label_sort) %></legend> |
|
31 | 31 | <% 3.times do |i| %> |
|
32 | 32 | <%= i+1 %>: |
|
33 | 33 | <%= label_tag "query_sort_criteria_attribute_" + i.to_s, |
|
34 | 34 | l(:description_query_sort_criteria_attribute), :class => "hidden-for-sighted" %> |
|
35 | 35 | <%= select_tag("query[sort_criteria][#{i}][]", |
|
36 | 36 | options_for_select([[]] + query.available_columns.select(&:sortable?).collect {|column| [column.caption, column.name.to_s]}, @query.sort_criteria_key(i)), |
|
37 | 37 | :id => "query_sort_criteria_attribute_" + i.to_s)%> |
|
38 | 38 | <%= label_tag "query_sort_criteria_direction_" + i.to_s, |
|
39 | 39 | l(:description_query_sort_criteria_direction), :class => "hidden-for-sighted" %> |
|
40 | 40 | <%= select_tag("query[sort_criteria][#{i}][]", |
|
41 | 41 | options_for_select([[], [l(:label_ascending), 'asc'], [l(:label_descending), 'desc']], @query.sort_criteria_order(i)), |
|
42 | 42 | :id => "query_sort_criteria_direction_" + i.to_s) %> |
|
43 | 43 | <br /> |
|
44 | 44 | <% end %> |
|
45 | 45 | </fieldset> |
|
46 | 46 | |
|
47 | <% content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> | |
|
47 | <%= content_tag 'fieldset', :id => 'columns', :style => (query.has_default_columns? ? 'display:none;' : nil) do %> | |
|
48 | 48 | <legend><%= l(:field_column_names) %></legend> |
|
49 | 49 | <%= render :partial => 'queries/columns', :locals => {:query => query}%> |
|
50 | 50 | <% end %> |
|
51 | 51 | |
|
52 | 52 | </div> |
@@ -1,271 +1,275 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 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 | |
|
20 | 20 | class QueriesControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_new_project_query |
|
28 | 28 | @request.session[:user_id] = 2 |
|
29 | 29 | get :new, :project_id => 1 |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_template 'new' |
|
32 | 32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
33 | 33 | :name => 'query[is_public]', |
|
34 | 34 | :checked => nil } |
|
35 | 35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
36 | 36 | :name => 'query_is_for_all', |
|
37 | 37 | :checked => nil, |
|
38 | 38 | :disabled => nil } |
|
39 | assert_select 'select[name=?]', 'c[]' do | |
|
40 | assert_select 'option[value=tracker]' | |
|
41 | assert_select 'option[value=subject]' | |
|
42 | end | |
|
39 | 43 | end |
|
40 | 44 | |
|
41 | 45 | def test_new_global_query |
|
42 | 46 | @request.session[:user_id] = 2 |
|
43 | 47 | get :new |
|
44 | 48 | assert_response :success |
|
45 | 49 | assert_template 'new' |
|
46 | 50 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
47 | 51 | :name => 'query[is_public]' } |
|
48 | 52 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
49 | 53 | :name => 'query_is_for_all', |
|
50 | 54 | :checked => 'checked', |
|
51 | 55 | :disabled => nil } |
|
52 | 56 | end |
|
53 | 57 | |
|
54 | 58 | def test_new_on_invalid_project |
|
55 | 59 | @request.session[:user_id] = 2 |
|
56 | 60 | get :new, :project_id => 'invalid' |
|
57 | 61 | assert_response 404 |
|
58 | 62 | end |
|
59 | 63 | |
|
60 | 64 | def test_create_project_public_query |
|
61 | 65 | @request.session[:user_id] = 2 |
|
62 | 66 | post :create, |
|
63 | 67 | :project_id => 'ecookbook', |
|
64 | 68 | :default_columns => '1', |
|
65 | 69 | :f => ["status_id", "assigned_to_id"], |
|
66 | 70 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
67 | 71 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
68 | 72 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
69 | 73 | |
|
70 | 74 | q = Query.find_by_name('test_new_project_public_query') |
|
71 | 75 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
72 | 76 | assert q.is_public? |
|
73 | 77 | assert q.has_default_columns? |
|
74 | 78 | assert q.valid? |
|
75 | 79 | end |
|
76 | 80 | |
|
77 | 81 | def test_create_project_private_query |
|
78 | 82 | @request.session[:user_id] = 3 |
|
79 | 83 | post :create, |
|
80 | 84 | :project_id => 'ecookbook', |
|
81 | 85 | :default_columns => '1', |
|
82 | 86 | :fields => ["status_id", "assigned_to_id"], |
|
83 | 87 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
84 | 88 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
85 | 89 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
86 | 90 | |
|
87 | 91 | q = Query.find_by_name('test_new_project_private_query') |
|
88 | 92 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
89 | 93 | assert !q.is_public? |
|
90 | 94 | assert q.has_default_columns? |
|
91 | 95 | assert q.valid? |
|
92 | 96 | end |
|
93 | 97 | |
|
94 | 98 | def test_create_global_private_query_with_custom_columns |
|
95 | 99 | @request.session[:user_id] = 3 |
|
96 | 100 | post :create, |
|
97 | 101 | :fields => ["status_id", "assigned_to_id"], |
|
98 | 102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
99 | 103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
100 | 104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
|
101 | 105 | :c => ["", "tracker", "subject", "priority", "category"] |
|
102 | 106 | |
|
103 | 107 | q = Query.find_by_name('test_new_global_private_query') |
|
104 | 108 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
105 | 109 | assert !q.is_public? |
|
106 | 110 | assert !q.has_default_columns? |
|
107 | 111 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
108 | 112 | assert q.valid? |
|
109 | 113 | end |
|
110 | 114 | |
|
111 | 115 | def test_create_global_query_with_custom_filters |
|
112 | 116 | @request.session[:user_id] = 3 |
|
113 | 117 | post :create, |
|
114 | 118 | :fields => ["assigned_to_id"], |
|
115 | 119 | :operators => {"assigned_to_id" => "="}, |
|
116 | 120 | :values => { "assigned_to_id" => ["me"]}, |
|
117 | 121 | :query => {"name" => "test_new_global_query"} |
|
118 | 122 | |
|
119 | 123 | q = Query.find_by_name('test_new_global_query') |
|
120 | 124 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
121 | 125 | assert !q.has_filter?(:status_id) |
|
122 | 126 | assert_equal ['assigned_to_id'], q.filters.keys |
|
123 | 127 | assert q.valid? |
|
124 | 128 | end |
|
125 | 129 | |
|
126 | 130 | def test_create_with_sort |
|
127 | 131 | @request.session[:user_id] = 1 |
|
128 | 132 | post :create, |
|
129 | 133 | :default_columns => '1', |
|
130 | 134 | :operators => {"status_id" => "o"}, |
|
131 | 135 | :values => {"status_id" => ["1"]}, |
|
132 | 136 | :query => {:name => "test_new_with_sort", |
|
133 | 137 | :is_public => "1", |
|
134 | 138 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
135 | 139 | |
|
136 | 140 | query = Query.find_by_name("test_new_with_sort") |
|
137 | 141 | assert_not_nil query |
|
138 | 142 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
139 | 143 | end |
|
140 | 144 | |
|
141 | 145 | def test_create_with_failure |
|
142 | 146 | @request.session[:user_id] = 2 |
|
143 | 147 | assert_no_difference '::Query.count' do |
|
144 | 148 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
145 | 149 | end |
|
146 | 150 | assert_response :success |
|
147 | 151 | assert_template 'new' |
|
148 | 152 | end |
|
149 | 153 | |
|
150 | 154 | def test_edit_global_public_query |
|
151 | 155 | @request.session[:user_id] = 1 |
|
152 | 156 | get :edit, :id => 4 |
|
153 | 157 | assert_response :success |
|
154 | 158 | assert_template 'edit' |
|
155 | 159 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
156 | 160 | :name => 'query[is_public]', |
|
157 | 161 | :checked => 'checked' } |
|
158 | 162 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
159 | 163 | :name => 'query_is_for_all', |
|
160 | 164 | :checked => 'checked', |
|
161 | 165 | :disabled => 'disabled' } |
|
162 | 166 | end |
|
163 | 167 | |
|
164 | 168 | def test_edit_global_private_query |
|
165 | 169 | @request.session[:user_id] = 3 |
|
166 | 170 | get :edit, :id => 3 |
|
167 | 171 | assert_response :success |
|
168 | 172 | assert_template 'edit' |
|
169 | 173 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
170 | 174 | :name => 'query[is_public]' } |
|
171 | 175 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
172 | 176 | :name => 'query_is_for_all', |
|
173 | 177 | :checked => 'checked', |
|
174 | 178 | :disabled => 'disabled' } |
|
175 | 179 | end |
|
176 | 180 | |
|
177 | 181 | def test_edit_project_private_query |
|
178 | 182 | @request.session[:user_id] = 3 |
|
179 | 183 | get :edit, :id => 2 |
|
180 | 184 | assert_response :success |
|
181 | 185 | assert_template 'edit' |
|
182 | 186 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
183 | 187 | :name => 'query[is_public]' } |
|
184 | 188 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
185 | 189 | :name => 'query_is_for_all', |
|
186 | 190 | :checked => nil, |
|
187 | 191 | :disabled => nil } |
|
188 | 192 | end |
|
189 | 193 | |
|
190 | 194 | def test_edit_project_public_query |
|
191 | 195 | @request.session[:user_id] = 2 |
|
192 | 196 | get :edit, :id => 1 |
|
193 | 197 | assert_response :success |
|
194 | 198 | assert_template 'edit' |
|
195 | 199 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
196 | 200 | :name => 'query[is_public]', |
|
197 | 201 | :checked => 'checked' |
|
198 | 202 | } |
|
199 | 203 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
200 | 204 | :name => 'query_is_for_all', |
|
201 | 205 | :checked => nil, |
|
202 | 206 | :disabled => 'disabled' } |
|
203 | 207 | end |
|
204 | 208 | |
|
205 | 209 | def test_edit_sort_criteria |
|
206 | 210 | @request.session[:user_id] = 1 |
|
207 | 211 | get :edit, :id => 5 |
|
208 | 212 | assert_response :success |
|
209 | 213 | assert_template 'edit' |
|
210 | 214 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
211 | 215 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
|
212 | 216 | :selected => 'selected' } } |
|
213 | 217 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
214 | 218 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
|
215 | 219 | :selected => 'selected' } } |
|
216 | 220 | end |
|
217 | 221 | |
|
218 | 222 | def test_edit_invalid_query |
|
219 | 223 | @request.session[:user_id] = 2 |
|
220 | 224 | get :edit, :id => 99 |
|
221 | 225 | assert_response 404 |
|
222 | 226 | end |
|
223 | 227 | |
|
224 | 228 | def test_udpate_global_private_query |
|
225 | 229 | @request.session[:user_id] = 3 |
|
226 | 230 | put :update, |
|
227 | 231 | :id => 3, |
|
228 | 232 | :default_columns => '1', |
|
229 | 233 | :fields => ["status_id", "assigned_to_id"], |
|
230 | 234 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
231 | 235 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
232 | 236 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
233 | 237 | |
|
234 | 238 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
235 | 239 | q = Query.find_by_name('test_edit_global_private_query') |
|
236 | 240 | assert !q.is_public? |
|
237 | 241 | assert q.has_default_columns? |
|
238 | 242 | assert q.valid? |
|
239 | 243 | end |
|
240 | 244 | |
|
241 | 245 | def test_update_global_public_query |
|
242 | 246 | @request.session[:user_id] = 1 |
|
243 | 247 | put :update, |
|
244 | 248 | :id => 4, |
|
245 | 249 | :default_columns => '1', |
|
246 | 250 | :fields => ["status_id", "assigned_to_id"], |
|
247 | 251 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
248 | 252 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
249 | 253 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
250 | 254 | |
|
251 | 255 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
252 | 256 | q = Query.find_by_name('test_edit_global_public_query') |
|
253 | 257 | assert q.is_public? |
|
254 | 258 | assert q.has_default_columns? |
|
255 | 259 | assert q.valid? |
|
256 | 260 | end |
|
257 | 261 | |
|
258 | 262 | def test_update_with_failure |
|
259 | 263 | @request.session[:user_id] = 1 |
|
260 | 264 | put :update, :id => 4, :query => {:name => ''} |
|
261 | 265 | assert_response :success |
|
262 | 266 | assert_template 'edit' |
|
263 | 267 | end |
|
264 | 268 | |
|
265 | 269 | def test_destroy |
|
266 | 270 | @request.session[:user_id] = 2 |
|
267 | 271 | delete :destroy, :id => 1 |
|
268 | 272 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
269 | 273 | assert_nil Query.find_by_id(1) |
|
270 | 274 | end |
|
271 | 275 | end |
General Comments 0
You need to be logged in to leave comments.
Login now