@@ -5,12 +5,12 | |||
|
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. |
@@ -25,14 +25,14 class QueryTest < ActiveSupport::TestCase | |||
|
25 | 25 | assert query.available_filters.has_key?('cf_1') |
|
26 | 26 | assert !query.available_filters.has_key?('cf_3') |
|
27 | 27 | end |
|
28 | ||
|
28 | ||
|
29 | 29 | def test_system_shared_versions_should_be_available_in_global_queries |
|
30 | 30 | Version.find(2).update_attribute :sharing, 'system' |
|
31 | 31 | query = Query.new(:project => nil, :name => '_') |
|
32 | 32 | assert query.available_filters.has_key?('fixed_version_id') |
|
33 | 33 | assert query.available_filters['fixed_version_id'][:values].detect {|v| v.last == '2'} |
|
34 | 34 | end |
|
35 | ||
|
35 | ||
|
36 | 36 | def test_project_filter_in_global_queries |
|
37 | 37 | query = Query.new(:project => nil, :name => '_') |
|
38 | 38 | project_filter = query.available_filters["project_id"] |
@@ -41,10 +41,10 class QueryTest < ActiveSupport::TestCase | |||
|
41 | 41 | assert project_ids.include?("1") #public project |
|
42 | 42 | assert !project_ids.include?("2") #private project user cannot see |
|
43 | 43 | end |
|
44 | ||
|
44 | ||
|
45 | 45 | def find_issues_with_query(query) |
|
46 | 46 | Issue.find :all, |
|
47 |
:include => [ :assigned_to, :status, :tracker, :project, :priority ], |
|
|
47 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], | |
|
48 | 48 | :conditions => query.statement |
|
49 | 49 | end |
|
50 | 50 | |
@@ -65,7 +65,7 class QueryTest < ActiveSupport::TestCase | |||
|
65 | 65 | |
|
66 | 66 | assert query.statement.include?("#{Issue.table_name}.fixed_version_id IN ('4')") |
|
67 | 67 | end |
|
68 | ||
|
68 | ||
|
69 | 69 | def test_query_with_multiple_custom_fields |
|
70 | 70 | query = Query.find(1) |
|
71 | 71 | assert query.valid? |
@@ -74,7 +74,7 class QueryTest < ActiveSupport::TestCase | |||
|
74 | 74 | assert_equal 1, issues.length |
|
75 | 75 | assert_equal Issue.find(3), issues.first |
|
76 | 76 | end |
|
77 | ||
|
77 | ||
|
78 | 78 | def test_operator_none |
|
79 | 79 | query = Query.new(:project => Project.find(1), :name => '_') |
|
80 | 80 | query.add_filter('fixed_version_id', '!*', ['']) |
@@ -83,7 +83,7 class QueryTest < ActiveSupport::TestCase | |||
|
83 | 83 | assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''") |
|
84 | 84 | find_issues_with_query(query) |
|
85 | 85 | end |
|
86 | ||
|
86 | ||
|
87 | 87 | def test_operator_none_for_integer |
|
88 | 88 | query = Query.new(:project => Project.find(1), :name => '_') |
|
89 | 89 | query.add_filter('estimated_hours', '!*', ['']) |
@@ -100,39 +100,39 class QueryTest < ActiveSupport::TestCase | |||
|
100 | 100 | assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''") |
|
101 | 101 | find_issues_with_query(query) |
|
102 | 102 | end |
|
103 | ||
|
103 | ||
|
104 | 104 | def test_numeric_filter_should_not_accept_non_numeric_values |
|
105 | 105 | query = Query.new(:name => '_') |
|
106 | 106 | query.add_filter('estimated_hours', '=', ['a']) |
|
107 | ||
|
107 | ||
|
108 | 108 | assert query.has_filter?('estimated_hours') |
|
109 | 109 | assert !query.valid? |
|
110 | 110 | end |
|
111 | ||
|
111 | ||
|
112 | 112 | def test_operator_is_on_float |
|
113 | 113 | Issue.update_all("estimated_hours = 171.2", "id=2") |
|
114 | ||
|
114 | ||
|
115 | 115 | query = Query.new(:name => '_') |
|
116 | 116 | query.add_filter('estimated_hours', '=', ['171.20']) |
|
117 | 117 | issues = find_issues_with_query(query) |
|
118 | 118 | assert_equal 1, issues.size |
|
119 | 119 | assert_equal 2, issues.first.id |
|
120 | 120 | end |
|
121 | ||
|
121 | ||
|
122 | 122 | def test_operator_greater_than |
|
123 | 123 | query = Query.new(:project => Project.find(1), :name => '_') |
|
124 | 124 | query.add_filter('done_ratio', '>=', ['40']) |
|
125 | 125 | assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40.0") |
|
126 | 126 | find_issues_with_query(query) |
|
127 | 127 | end |
|
128 | ||
|
128 | ||
|
129 | 129 | def test_operator_greater_than_a_float |
|
130 | 130 | query = Query.new(:project => Project.find(1), :name => '_') |
|
131 | 131 | query.add_filter('estimated_hours', '>=', ['40.5']) |
|
132 | 132 | assert query.statement.include?("#{Issue.table_name}.estimated_hours >= 40.5") |
|
133 | 133 | find_issues_with_query(query) |
|
134 | 134 | end |
|
135 | ||
|
135 | ||
|
136 | 136 | def test_operator_greater_than_on_custom_field |
|
137 | 137 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true) |
|
138 | 138 | query = Query.new(:project => Project.find(1), :name => '_') |
@@ -140,14 +140,14 class QueryTest < ActiveSupport::TestCase | |||
|
140 | 140 | assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) >= 40.0") |
|
141 | 141 | find_issues_with_query(query) |
|
142 | 142 | end |
|
143 | ||
|
143 | ||
|
144 | 144 | def test_operator_lesser_than |
|
145 | 145 | query = Query.new(:project => Project.find(1), :name => '_') |
|
146 | 146 | query.add_filter('done_ratio', '<=', ['30']) |
|
147 | 147 | assert query.statement.include?("#{Issue.table_name}.done_ratio <= 30.0") |
|
148 | 148 | find_issues_with_query(query) |
|
149 | 149 | end |
|
150 | ||
|
150 | ||
|
151 | 151 | def test_operator_lesser_than_on_custom_field |
|
152 | 152 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true) |
|
153 | 153 | query = Query.new(:project => Project.find(1), :name => '_') |
@@ -155,14 +155,14 class QueryTest < ActiveSupport::TestCase | |||
|
155 | 155 | assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) <= 30.0") |
|
156 | 156 | find_issues_with_query(query) |
|
157 | 157 | end |
|
158 | ||
|
158 | ||
|
159 | 159 | def test_operator_between |
|
160 | 160 | query = Query.new(:project => Project.find(1), :name => '_') |
|
161 | 161 | query.add_filter('done_ratio', '><', ['30', '40']) |
|
162 | 162 | assert_include "#{Issue.table_name}.done_ratio BETWEEN 30.0 AND 40.0", query.statement |
|
163 | 163 | find_issues_with_query(query) |
|
164 | 164 | end |
|
165 | ||
|
165 | ||
|
166 | 166 | def test_operator_between_on_custom_field |
|
167 | 167 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true) |
|
168 | 168 | query = Query.new(:project => Project.find(1), :name => '_') |
@@ -170,27 +170,27 class QueryTest < ActiveSupport::TestCase | |||
|
170 | 170 | assert_include "CAST(custom_values.value AS decimal(60,3)) BETWEEN 30.0 AND 40.0", query.statement |
|
171 | 171 | find_issues_with_query(query) |
|
172 | 172 | end |
|
173 | ||
|
173 | ||
|
174 | 174 | def test_date_filter_should_not_accept_non_date_values |
|
175 | 175 | query = Query.new(:name => '_') |
|
176 | 176 | query.add_filter('created_on', '=', ['a']) |
|
177 | ||
|
177 | ||
|
178 | 178 | assert query.has_filter?('created_on') |
|
179 | 179 | assert !query.valid? |
|
180 | 180 | end |
|
181 | ||
|
181 | ||
|
182 | 182 | def test_date_filter_should_not_accept_invalid_date_values |
|
183 | 183 | query = Query.new(:name => '_') |
|
184 | 184 | query.add_filter('created_on', '=', ['2011-01-34']) |
|
185 | ||
|
185 | ||
|
186 | 186 | assert query.has_filter?('created_on') |
|
187 | 187 | assert !query.valid? |
|
188 | 188 | end |
|
189 | ||
|
189 | ||
|
190 | 190 | def test_relative_date_filter_should_not_accept_non_integer_values |
|
191 | 191 | query = Query.new(:name => '_') |
|
192 | 192 | query.add_filter('created_on', '>t-', ['a']) |
|
193 | ||
|
193 | ||
|
194 | 194 | assert query.has_filter?('created_on') |
|
195 | 195 | assert !query.valid? |
|
196 | 196 | end |
@@ -239,7 +239,7 class QueryTest < ActiveSupport::TestCase | |||
|
239 | 239 | assert !issues.empty? |
|
240 | 240 | issues.each {|issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15))} |
|
241 | 241 | end |
|
242 | ||
|
242 | ||
|
243 | 243 | def test_operator_less_than_ago |
|
244 | 244 | Issue.find(7).update_attribute(:due_date, (Date.today - 3)) |
|
245 | 245 | query = Query.new(:project => Project.find(1), :name => '_') |
@@ -248,7 +248,7 class QueryTest < ActiveSupport::TestCase | |||
|
248 | 248 | assert !issues.empty? |
|
249 | 249 | issues.each {|issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today)} |
|
250 | 250 | end |
|
251 | ||
|
251 | ||
|
252 | 252 | def test_operator_more_than_ago |
|
253 | 253 | Issue.find(7).update_attribute(:due_date, (Date.today - 10)) |
|
254 | 254 | query = Query.new(:project => Project.find(1), :name => '_') |
@@ -305,37 +305,37 class QueryTest < ActiveSupport::TestCase | |||
|
305 | 305 | assert result.empty? |
|
306 | 306 | result.each {|issue| assert issue.subject.downcase.include?('unable') } |
|
307 | 307 | end |
|
308 | ||
|
308 | ||
|
309 | 309 | def test_range_for_this_week_with_week_starting_on_monday |
|
310 | 310 | I18n.locale = :fr |
|
311 | 311 | assert_equal '1', I18n.t(:general_first_day_of_week) |
|
312 | ||
|
312 | ||
|
313 | 313 | Date.stubs(:today).returns(Date.parse('2011-04-29')) |
|
314 | ||
|
314 | ||
|
315 | 315 | query = Query.new(:project => Project.find(1), :name => '_') |
|
316 | 316 | query.add_filter('due_date', 'w', ['']) |
|
317 | 317 | assert query.statement.match(/issues\.due_date > '2011-04-24 23:59:59(\.9+)?' AND issues\.due_date <= '2011-05-01 23:59:59(\.9+)?/), "range not found in #{query.statement}" |
|
318 | 318 | I18n.locale = :en |
|
319 | 319 | end |
|
320 | ||
|
320 | ||
|
321 | 321 | def test_range_for_this_week_with_week_starting_on_sunday |
|
322 | 322 | I18n.locale = :en |
|
323 | 323 | assert_equal '7', I18n.t(:general_first_day_of_week) |
|
324 | ||
|
324 | ||
|
325 | 325 | Date.stubs(:today).returns(Date.parse('2011-04-29')) |
|
326 | ||
|
326 | ||
|
327 | 327 | query = Query.new(:project => Project.find(1), :name => '_') |
|
328 | 328 | query.add_filter('due_date', 'w', ['']) |
|
329 | 329 | assert query.statement.match(/issues\.due_date > '2011-04-23 23:59:59(\.9+)?' AND issues\.due_date <= '2011-04-30 23:59:59(\.9+)?/), "range not found in #{query.statement}" |
|
330 | 330 | end |
|
331 | ||
|
331 | ||
|
332 | 332 | def test_operator_does_not_contains |
|
333 | 333 | query = Query.new(:project => Project.find(1), :name => '_') |
|
334 | 334 | query.add_filter('subject', '!~', ['uNable']) |
|
335 | 335 | assert query.statement.include?("LOWER(#{Issue.table_name}.subject) NOT LIKE '%unable%'") |
|
336 | 336 | find_issues_with_query(query) |
|
337 | 337 | end |
|
338 | ||
|
338 | ||
|
339 | 339 | def test_filter_assigned_to_me |
|
340 | 340 | user = User.find(2) |
|
341 | 341 | group = Group.find(10) |
@@ -344,16 +344,16 class QueryTest < ActiveSupport::TestCase | |||
|
344 | 344 | i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group) |
|
345 | 345 | i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => Group.find(11)) |
|
346 | 346 | group.users << user |
|
347 | ||
|
347 | ||
|
348 | 348 | query = Query.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}}) |
|
349 | 349 | result = query.issues |
|
350 | 350 | assert_equal Issue.visible.all(:conditions => {:assigned_to_id => ([2] + user.reload.group_ids)}).sort_by(&:id), result.sort_by(&:id) |
|
351 | ||
|
351 | ||
|
352 | 352 | assert result.include?(i1) |
|
353 | 353 | assert result.include?(i2) |
|
354 | 354 | assert !result.include?(i3) |
|
355 | 355 | end |
|
356 | ||
|
356 | ||
|
357 | 357 | def test_filter_watched_issues |
|
358 | 358 | User.current = User.find(1) |
|
359 | 359 | query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}}) |
@@ -363,7 +363,7 class QueryTest < ActiveSupport::TestCase | |||
|
363 | 363 | assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id) |
|
364 | 364 | User.current = nil |
|
365 | 365 | end |
|
366 | ||
|
366 | ||
|
367 | 367 | def test_filter_unwatched_issues |
|
368 | 368 | User.current = User.find(1) |
|
369 | 369 | query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '!', :values => ['me']}}) |
@@ -373,20 +373,20 class QueryTest < ActiveSupport::TestCase | |||
|
373 | 373 | assert_equal((Issue.visible - Issue.watched_by(User.current)).sort_by(&:id).size, result.sort_by(&:id).size) |
|
374 | 374 | User.current = nil |
|
375 | 375 | end |
|
376 | ||
|
376 | ||
|
377 | 377 | def test_statement_should_be_nil_with_no_filters |
|
378 | 378 | q = Query.new(:name => '_') |
|
379 | 379 | q.filters = {} |
|
380 | ||
|
380 | ||
|
381 | 381 | assert q.valid? |
|
382 | 382 | assert_nil q.statement |
|
383 | 383 | end |
|
384 | ||
|
384 | ||
|
385 | 385 | def test_default_columns |
|
386 | 386 | q = Query.new |
|
387 |
assert !q.columns.empty? |
|
|
387 | assert !q.columns.empty? | |
|
388 | 388 | end |
|
389 | ||
|
389 | ||
|
390 | 390 | def test_set_column_names |
|
391 | 391 | q = Query.new |
|
392 | 392 | q.column_names = ['tracker', :subject, '', 'unknonw_column'] |
@@ -394,7 +394,7 class QueryTest < ActiveSupport::TestCase | |||
|
394 | 394 | c = q.columns.first |
|
395 | 395 | assert q.has_column?(c) |
|
396 | 396 | end |
|
397 | ||
|
397 | ||
|
398 | 398 | def test_groupable_columns_should_include_custom_fields |
|
399 | 399 | q = Query.new |
|
400 | 400 | assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn} |
@@ -408,31 +408,31 class QueryTest < ActiveSupport::TestCase | |||
|
408 | 408 | assert_not_nil q.group_by_statement |
|
409 | 409 | assert_equal 'status', q.group_by_statement |
|
410 | 410 | end |
|
411 | ||
|
411 | ||
|
412 | 412 | def test_grouped_with_invalid_column |
|
413 | 413 | q = Query.new(:group_by => 'foo') |
|
414 | 414 | assert !q.grouped? |
|
415 | 415 | assert_nil q.group_by_column |
|
416 | 416 | assert_nil q.group_by_statement |
|
417 | 417 | end |
|
418 | ||
|
418 | ||
|
419 | 419 | def test_default_sort |
|
420 | 420 | q = Query.new |
|
421 | 421 | assert_equal [], q.sort_criteria |
|
422 | 422 | end |
|
423 | ||
|
423 | ||
|
424 | 424 | def test_set_sort_criteria_with_hash |
|
425 | 425 | q = Query.new |
|
426 | 426 | q.sort_criteria = {'0' => ['priority', 'desc'], '2' => ['tracker']} |
|
427 | 427 | assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria |
|
428 | 428 | end |
|
429 | ||
|
429 | ||
|
430 | 430 | def test_set_sort_criteria_with_array |
|
431 | 431 | q = Query.new |
|
432 | 432 | q.sort_criteria = [['priority', 'desc'], 'tracker'] |
|
433 | 433 | assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria |
|
434 | 434 | end |
|
435 | ||
|
435 | ||
|
436 | 436 | def test_create_query_with_sort |
|
437 | 437 | q = Query.new(:name => 'Sorted') |
|
438 | 438 | q.sort_criteria = [['priority', 'desc'], 'tracker'] |
@@ -440,49 +440,49 class QueryTest < ActiveSupport::TestCase | |||
|
440 | 440 | q.reload |
|
441 | 441 | assert_equal [['priority', 'desc'], ['tracker', 'asc']], q.sort_criteria |
|
442 | 442 | end |
|
443 | ||
|
443 | ||
|
444 | 444 | def test_sort_by_string_custom_field_asc |
|
445 | 445 | q = Query.new |
|
446 | 446 | c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } |
|
447 | 447 | assert c |
|
448 | 448 | assert c.sortable |
|
449 | 449 | issues = Issue.find :all, |
|
450 |
:include => [ :assigned_to, :status, :tracker, :project, :priority ], |
|
|
450 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], | |
|
451 | 451 | :conditions => q.statement, |
|
452 | 452 | :order => "#{c.sortable} ASC" |
|
453 | 453 | values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s} |
|
454 | 454 | assert !values.empty? |
|
455 | 455 | assert_equal values.sort, values |
|
456 | 456 | end |
|
457 | ||
|
457 | ||
|
458 | 458 | def test_sort_by_string_custom_field_desc |
|
459 | 459 | q = Query.new |
|
460 | 460 | c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } |
|
461 | 461 | assert c |
|
462 | 462 | assert c.sortable |
|
463 | 463 | issues = Issue.find :all, |
|
464 |
:include => [ :assigned_to, :status, :tracker, :project, :priority ], |
|
|
464 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], | |
|
465 | 465 | :conditions => q.statement, |
|
466 | 466 | :order => "#{c.sortable} DESC" |
|
467 | 467 | values = issues.collect {|i| i.custom_value_for(c.custom_field).to_s} |
|
468 | 468 | assert !values.empty? |
|
469 | 469 | assert_equal values.sort.reverse, values |
|
470 | 470 | end |
|
471 | ||
|
471 | ||
|
472 | 472 | def test_sort_by_float_custom_field_asc |
|
473 | 473 | q = Query.new |
|
474 | 474 | c = q.available_columns.find {|col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' } |
|
475 | 475 | assert c |
|
476 | 476 | assert c.sortable |
|
477 | 477 | issues = Issue.find :all, |
|
478 |
:include => [ :assigned_to, :status, :tracker, :project, :priority ], |
|
|
478 | :include => [ :assigned_to, :status, :tracker, :project, :priority ], | |
|
479 | 479 | :conditions => q.statement, |
|
480 | 480 | :order => "#{c.sortable} ASC" |
|
481 | 481 | values = issues.collect {|i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end}.compact |
|
482 | 482 | assert !values.empty? |
|
483 | 483 | assert_equal values.sort, values |
|
484 | 484 | end |
|
485 | ||
|
485 | ||
|
486 | 486 | def test_invalid_query_should_raise_query_statement_invalid_error |
|
487 | 487 | q = Query.new |
|
488 | 488 | assert_raise Query::StatementInvalid do |
@@ -521,7 +521,7 class QueryTest < ActiveSupport::TestCase | |||
|
521 | 521 | assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq |
|
522 | 522 | assert count_by_group.has_key?('MySQL') |
|
523 | 523 | end |
|
524 | ||
|
524 | ||
|
525 | 525 | def test_issue_count_by_date_custom_field_group |
|
526 | 526 | q = Query.new(:name => '_', :group_by => 'cf_8') |
|
527 | 527 | count_by_group = q.issue_count_by_group |
@@ -529,17 +529,17 class QueryTest < ActiveSupport::TestCase | |||
|
529 | 529 | assert_equal %w(Date NilClass), count_by_group.keys.collect {|k| k.class.name}.uniq.sort |
|
530 | 530 | assert_equal %w(Fixnum), count_by_group.values.collect {|k| k.class.name}.uniq |
|
531 | 531 | end |
|
532 | ||
|
532 | ||
|
533 | 533 | def test_label_for |
|
534 | 534 | q = Query.new |
|
535 | 535 | assert_equal 'assigned_to', q.label_for('assigned_to_id') |
|
536 | 536 | end |
|
537 | ||
|
537 | ||
|
538 | 538 | def test_editable_by |
|
539 | 539 | admin = User.find(1) |
|
540 | 540 | manager = User.find(2) |
|
541 | 541 | developer = User.find(3) |
|
542 | ||
|
542 | ||
|
543 | 543 | # Public query on project 1 |
|
544 | 544 | q = Query.find(1) |
|
545 | 545 | assert q.editable_by?(admin) |
@@ -564,10 +564,10 class QueryTest < ActiveSupport::TestCase | |||
|
564 | 564 | assert !q.editable_by?(manager) |
|
565 | 565 | assert !q.editable_by?(developer) |
|
566 | 566 | end |
|
567 | ||
|
567 | ||
|
568 | 568 | def test_visible_scope |
|
569 | 569 | query_ids = Query.visible(User.anonymous).map(&:id) |
|
570 | ||
|
570 | ||
|
571 | 571 | assert query_ids.include?(1), 'public query on public project was not visible' |
|
572 | 572 | assert query_ids.include?(4), 'public query for all projects was not visible' |
|
573 | 573 | assert !query_ids.include?(2), 'private query on public project was visible' |
@@ -579,7 +579,7 class QueryTest < ActiveSupport::TestCase | |||
|
579 | 579 | setup do |
|
580 | 580 | @query = Query.new(:name => "_") |
|
581 | 581 | end |
|
582 | ||
|
582 | ||
|
583 | 583 | should "include users of visible projects in cross-project view" do |
|
584 | 584 | users = @query.available_filters["assigned_to_id"] |
|
585 | 585 | assert_not_nil users |
@@ -596,11 +596,11 class QueryTest < ActiveSupport::TestCase | |||
|
596 | 596 | should "be present" do |
|
597 | 597 | assert @query.available_filters.keys.include?("member_of_group") |
|
598 | 598 | end |
|
599 | ||
|
599 | ||
|
600 | 600 | should "be an optional list" do |
|
601 | 601 | assert_equal :list_optional, @query.available_filters["member_of_group"][:type] |
|
602 | 602 | end |
|
603 | ||
|
603 | ||
|
604 | 604 | should "have a list of the groups as values" do |
|
605 | 605 | Group.destroy_all # No fixtures |
|
606 | 606 | group1 = Group.generate!.reload |
@@ -619,11 +619,11 class QueryTest < ActiveSupport::TestCase | |||
|
619 | 619 | should "be present" do |
|
620 | 620 | assert @query.available_filters.keys.include?("assigned_to_role") |
|
621 | 621 | end |
|
622 | ||
|
622 | ||
|
623 | 623 | should "be an optional list" do |
|
624 | 624 | assert_equal :list_optional, @query.available_filters["assigned_to_role"][:type] |
|
625 | 625 | end |
|
626 | ||
|
626 | ||
|
627 | 627 | should "have a list of the Roles as values" do |
|
628 | 628 | assert @query.available_filters["assigned_to_role"][:values].include?(['Manager','1']) |
|
629 | 629 | assert @query.available_filters["assigned_to_role"][:values].include?(['Developer','2']) |
@@ -647,16 +647,16 class QueryTest < ActiveSupport::TestCase | |||
|
647 | 647 | @second_user_in_group = User.generate! |
|
648 | 648 | @user_in_group2 = User.generate! |
|
649 | 649 | @user_not_in_group = User.generate! |
|
650 | ||
|
650 | ||
|
651 | 651 | @group = Group.generate!.reload |
|
652 | 652 | @group.users << @user_in_group |
|
653 | 653 | @group.users << @second_user_in_group |
|
654 | ||
|
654 | ||
|
655 | 655 | @group2 = Group.generate!.reload |
|
656 | 656 | @group2.users << @user_in_group2 |
|
657 | ||
|
657 | ||
|
658 | 658 | end |
|
659 | ||
|
659 | ||
|
660 | 660 | should "search assigned to for users in the group" do |
|
661 | 661 | @query = Query.new(:name => '_') |
|
662 | 662 | @query.add_filter('member_of_group', '=', [@group.id.to_s]) |
@@ -682,20 +682,20 class QueryTest < ActiveSupport::TestCase | |||
|
682 | 682 | assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}')" |
|
683 | 683 | assert_find_issues_with_query_is_successful @query |
|
684 | 684 | end |
|
685 | ||
|
685 | ||
|
686 | 686 | should "return an empty set with = empty group" do |
|
687 | 687 | @empty_group = Group.generate! |
|
688 | 688 | @query = Query.new(:name => '_') |
|
689 | 689 | @query.add_filter('member_of_group', '=', [@empty_group.id.to_s]) |
|
690 | ||
|
690 | ||
|
691 | 691 | assert_equal [], find_issues_with_query(@query) |
|
692 | 692 | end |
|
693 | ||
|
693 | ||
|
694 | 694 | should "return issues with ! empty group" do |
|
695 | 695 | @empty_group = Group.generate! |
|
696 | 696 | @query = Query.new(:name => '_') |
|
697 | 697 | @query.add_filter('member_of_group', '!', [@empty_group.id.to_s]) |
|
698 | ||
|
698 | ||
|
699 | 699 | assert_find_issues_with_query_is_successful @query |
|
700 | 700 | end |
|
701 | 701 | end |
@@ -706,7 +706,7 class QueryTest < ActiveSupport::TestCase | |||
|
706 | 706 | MemberRole.delete_all |
|
707 | 707 | Member.delete_all |
|
708 | 708 | Role.delete_all |
|
709 | ||
|
709 | ||
|
710 | 710 | @manager_role = Role.generate!(:name => 'Manager') |
|
711 | 711 | @developer_role = Role.generate!(:name => 'Developer') |
|
712 | 712 | |
@@ -718,7 +718,7 class QueryTest < ActiveSupport::TestCase | |||
|
718 | 718 | User.add_to_project(@developer, @project, @developer_role) |
|
719 | 719 | User.add_to_project(@boss, @project, [@manager_role, @developer_role]) |
|
720 | 720 | end |
|
721 | ||
|
721 | ||
|
722 | 722 | should "search assigned to for users with the Role" do |
|
723 | 723 | @query = Query.new(:name => '_') |
|
724 | 724 | @query.add_filter('assigned_to_role', '=', [@manager_role.id.to_s]) |
@@ -742,23 +742,23 class QueryTest < ActiveSupport::TestCase | |||
|
742 | 742 | assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')" |
|
743 | 743 | assert_find_issues_with_query_is_successful @query |
|
744 | 744 | end |
|
745 | ||
|
745 | ||
|
746 | 746 | should "return an empty set with empty role" do |
|
747 | 747 | @empty_role = Role.generate! |
|
748 | 748 | @query = Query.new(:name => '_') |
|
749 | 749 | @query.add_filter('assigned_to_role', '=', [@empty_role.id.to_s]) |
|
750 | ||
|
750 | ||
|
751 | 751 | assert_equal [], find_issues_with_query(@query) |
|
752 | 752 | end |
|
753 | ||
|
753 | ||
|
754 | 754 | should "return issues with ! empty role" do |
|
755 | 755 | @empty_role = Role.generate! |
|
756 | 756 | @query = Query.new(:name => '_') |
|
757 | 757 | @query.add_filter('member_of_group', '!', [@empty_role.id.to_s]) |
|
758 | ||
|
758 | ||
|
759 | 759 | assert_find_issues_with_query_is_successful @query |
|
760 | 760 | end |
|
761 | 761 | end |
|
762 | 762 | end |
|
763 | ||
|
763 | ||
|
764 | 764 | end |
General Comments 0
You need to be logged in to leave comments.
Login now