forked from redmine/redmine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissues_controller_test.rb
More file actions
8607 lines (7848 loc) · 255 KB
/
issues_controller_test.rb
File metadata and controls
8607 lines (7848 loc) · 255 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2023 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative '../test_helper'
class IssuesControllerTest < Redmine::ControllerTest
fixtures :projects,
:users, :email_addresses, :user_preferences,
:roles,
:members,
:member_roles,
:issues,
:issue_statuses,
:issue_relations,
:versions,
:trackers,
:projects_trackers,
:issue_categories,
:enabled_modules,
:enumerations,
:attachments,
:workflows,
:custom_fields,
:custom_values,
:custom_fields_projects,
:custom_fields_trackers,
:time_entries,
:journals,
:journal_details,
:queries,
:repositories,
:changesets,
:watchers, :groups_users
include Redmine::I18n
def setup
User.current = nil
end
def test_index
with_settings :default_language => "en" do
get :index
assert_response :success
# links to visible issues
assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
# private projects hidden
assert_select 'a[href="/issues/6"]', 0
assert_select 'a[href="/issues/4"]', 0
# project column
assert_select 'th', :text => /Project/
end
end
def test_index_should_not_list_issues_when_module_disabled
EnabledModule.where("name = 'issue_tracking' AND project_id = 1").delete_all
get :index
assert_response :success
assert_select 'a[href="/issues/1"]', 0
assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
end
def test_index_should_list_visible_issues_only
get(:index, :params => {:per_page => 100})
assert_response :success
Issue.open.each do |issue|
assert_select "tr#issue-#{issue.id}", issue.visible? ? 1 : 0
end
end
def test_index_with_project
with_settings :display_subprojects_issues => '0' do
get(:index, :params => {:project_id => 1})
assert_response :success
# query form
assert_select 'form#query_form' do
assert_select 'div#query_form_with_buttons.hide-when-print' do
assert_select 'div#query_form_content' do
assert_select 'fieldset#filters.collapsible'
assert_select 'fieldset#options'
end
assert_select 'p.buttons'
end
end
assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
assert_select 'a[href="/issues/5"]', 0
end
end
def test_index_with_project_and_subprojects
with_settings :display_subprojects_issues => '1' do
get(:index, :params => {:project_id => 1})
assert_response :success
assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
assert_select 'a[href="/issues/6"]', 0
end
end
def test_index_should_list_issues_of_closed_subprojects
@request.session[:user_id] = 1
project = Project.find(1)
with_settings :display_subprojects_issues => '1' do
# One of subprojects is closed
Project.find_by(:identifier => 'subproject1').close
get(:index, :params => {:project_id => project.id})
assert_response :success
assert_equal 10, issues_in_list.count
# All subprojects are closed
project.descendants.each(&:close)
get(:index, :params => {:project_id => project.id})
assert_response :success
assert_equal 10, issues_in_list.count
end
end
def test_index_with_subproject_filter_should_not_exclude_closed_subprojects_issues
subproject1 = Project.find(3)
subproject2 = Project.find(4)
subproject1.close
with_settings :display_subprojects_issues => '1' do
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:f => ['subproject_id'],
:op => {'subproject_id' => '!'},
:v => {'subproject_id' => [subproject2.id.to_s]},
:c => ['project']
}
)
end
assert_response :success
column_values = columns_values_in_list('project')
assert_includes column_values, subproject1.name
assert_equal 9, column_values.size
end
def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
@request.session[:user_id] = 2
with_settings :display_subprojects_issues => '1' do
get(:index, :params => {:project_id => 1})
assert_response :success
assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
end
end
def test_index_with_project_and_default_filter
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1
}
)
assert_response :success
# default filter
assert_query_filters [['status_id', 'o', '']]
end
def test_index_with_project_and_filter
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:f => ['tracker_id'],
:op => {
'tracker_id' => '='
},
:v => {
'tracker_id' => ['1']
}
}
)
assert_response :success
assert_query_filters [['tracker_id', '=', '1']]
end
def test_index_with_short_filters
to_test = {
'status_id' => {
'o' => {:op => 'o', :values => ['']},
'c' => {:op => 'c', :values => ['']},
'7' => {:op => '=', :values => ['7']},
'7|3|4' => {:op => '=', :values => ['7', '3', '4']},
'=7' => {:op => '=', :values => ['7']},
'!3' => {:op => '!', :values => ['3']},
'!7|3|4' => {:op => '!', :values => ['7', '3', '4']}
},
'subject' => {
'This is a subject' => {:op => '=', :values => ['This is a subject']},
'o' => {:op => '=', :values => ['o']},
'~This is part of a subject' => {:op => '~', :values => ['This is part of a subject']},
'!~This is part of a subject' => {:op => '!~', :values => ['This is part of a subject']}
},
'tracker_id' => {
'3' => {:op => '=', :values => ['3']},
'=3' => {:op => '=', :values => ['3']}
},
'start_date' => {
'2011-10-12' => {:op => '=', :values => ['2011-10-12']},
'=2011-10-12' => {:op => '=', :values => ['2011-10-12']},
'>=2011-10-12' => {:op => '>=', :values => ['2011-10-12']},
'<=2011-10-12' => {:op => '<=', :values => ['2011-10-12']},
'><2011-10-01|2011-10-30' => {:op => '><', :values => ['2011-10-01', '2011-10-30']},
'<t+2' => {:op => '<t+', :values => ['2']},
'>t+2' => {:op => '>t+', :values => ['2']},
't+2' => {:op => 't+', :values => ['2']},
't' => {:op => 't', :values => ['']},
'w' => {:op => 'w', :values => ['']},
'>t-2' => {:op => '>t-', :values => ['2']},
'<t-2' => {:op => '<t-', :values => ['2']},
't-2' => {:op => 't-', :values => ['2']}
},
'created_on' => {
'>=2011-10-12' => {:op => '>=', :values => ['2011-10-12']},
'<t-2' => {:op => '<t-', :values => ['2']},
'>t-2' => {:op => '>t-', :values => ['2']},
't-2' => {:op => 't-', :values => ['2']}
},
'cf_1' => {
'c' => {:op => '=', :values => ['c']},
'!c' => {:op => '!', :values => ['c']},
'!*' => {:op => '!*', :values => ['']},
'*' => {:op => '*', :values => ['']}
},
'estimated_hours' => {
'=13.4' => {:op => '=', :values => ['13.4']},
'>=45' => {:op => '>=', :values => ['45']},
'<=125' => {:op => '<=', :values => ['125']},
'><10.5|20.5' => {:op => '><', :values => ['10.5', '20.5']},
'!*' => {:op => '!*', :values => ['']},
'*' => {:op => '*', :values => ['']}
}
}
default_filter = {'status_id' => {:operator => 'o', :values => ['']}}
to_test.each do |field, expression_and_expected|
expression_and_expected.each do |filter_expression, expected|
get(:index, :params => {:set_filter => 1, field => filter_expression})
assert_response :success
expected_with_default =
default_filter.
merge({field => {:operator => expected[:op], :values => expected[:values]}})
assert_query_filters(
expected_with_default.map {|f, v| [f, v[:operator], v[:values]]}
)
end
end
end
def test_index_with_project_and_empty_filters
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:fields => ['']
}
)
assert_response :success
# no filter
assert_query_filters []
end
def test_index_with_project_custom_field_filter
field =
ProjectCustomField.
create!(:name => 'Client', :is_filter => true, :field_format => 'string')
CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
filter_name = "project.cf_#{field.id}"
@request.session[:user_id] = 1
get(
:index,
:params => {
:set_filter => 1,
:f => [filter_name],
:op => {
filter_name => '='
},
:v => {
filter_name => ['Foo']
},
:c => ['project']
}
)
assert_response :success
assert_equal [3, 5], issues_in_list.map(&:project_id).uniq.sort
end
def test_index_with_project_status_filter
project = Project.find(2)
project.close
project.save
get(
:index,
:params => {
:set_filter => 1,
:f => ['project.status'],
:op => {'project.status' => '='},
:v => {'project.status' => ['1']}
}
)
assert_response :success
issues = issues_in_list.map(&:id).uniq.sort
assert_include 1, issues
assert_not_include 4, issues
end
def test_index_with_query
get(
:index,
:params => {
:project_id => 1,
:query_id => 5
}
)
assert_response :success
assert_select '#sidebar .queries' do
# assert only query is selected in sidebar
assert_select 'a.query.selected', 1
# assert link properties
assert_select(
'a.query.selected[href=?]',
'/projects/ecookbook/issues?query_id=5',
:text => "Open issues by priority and tracker"
)
# assert only one clear link exists
assert_select 'a.icon-clear-query', 1
# assert clear link properties
assert_select(
'a.icon-clear-query[title=?][href=?]',
'Clear',
'/projects/ecookbook/issues?set_filter=1&sort=',
1
)
end
end
def test_index_with_query_grouped_by_tracker
get(
:index,
:params => {
:project_id => 1,
:query_id => 6
}
)
assert_response :success
assert_select 'tr.group span.count'
end
def test_index_with_query_grouped_and_sorted_by_category
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "category",
:sort => "category"
}
)
assert_response :success
assert_select 'tr.group span.count'
end
def test_index_with_query_grouped_and_sorted_by_fixed_version
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "fixed_version",
:sort => "fixed_version"
}
)
assert_response :success
assert_select 'tr.group span.count'
end
def test_index_with_query_grouped_and_sorted_by_fixed_version_in_reverse_order
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "fixed_version",
:sort => "fixed_version:desc"
}
)
assert_response :success
assert_select 'tr.group span.count'
end
def test_index_grouped_by_due_date
set_tmp_attachments_directory
Issue.destroy_all
Issue.generate!(:due_date => '2018-08-10')
Issue.generate!(:due_date => '2018-08-10')
Issue.generate!
get(
:index,
:params => {
:set_filter => 1,
:group_by => "due_date"
}
)
assert_response :success
assert_select 'tr.group span.name', :value => '2018-08-10' do
assert_select '~ span.count', :value => '2'
end
assert_select 'tr.group span.name', :value => '(blank)' do
assert_select '~ span.count', :value => '1'
end
end
def test_index_grouped_by_created_on_if_time_zone_is_utc
# TODO: test fails with mysql
skip if mysql?
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
@request.session[:user_id] = 2
User.find(2).pref.update(time_zone: 'UTC')
get(
:index,
:params => {
:set_filter => 1,
:group_by => 'created_on'
}
)
assert_response :success
assert_select 'tr.group span.name', :text => '07/19/2006' do
assert_select '+ span.count', :text => '2'
end
end
def test_index_grouped_by_created_on_if_time_zone_is_nil
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
current_user = User.find(2)
@request.session[:user_id] = current_user.id
current_user.pref.update(time_zone: nil)
get(
:index,
:params => {
:set_filter => 1,
:group_by => 'created_on'
}
)
assert_response :success
# group_name depends on localtime
group_name = format_date(Issue.second.created_on.localtime)
assert_select 'tr.group span.name', :text => group_name do
assert_select '+ span.count', :text => '2'
end
end
def test_index_grouped_by_created_on_as_pdf
skip unless IssueQuery.new.groupable_columns.detect {|c| c.name == :created_on}
get(
:index,
:params => {
:set_filter => 1,
:group_by => 'created_on',
:format => 'pdf'
}
)
assert_response :success
assert_equal 'application/pdf', response.media_type
end
def test_index_with_query_grouped_by_list_custom_field
get(
:index,
:params => {
:project_id => 1,
:query_id => 9
}
)
assert_response :success
assert_select 'tr.group span.count'
end
def test_index_with_query_grouped_by_key_value_custom_field
cf = IssueCustomField.
create!(
:name => 'Key',
:is_for_all => true,
:tracker_ids => [1, 2, 3],
:field_format => 'enumeration'
)
cf.enumerations << valueb = CustomFieldEnumeration.new(:name => 'Value B', :position => 1)
cf.enumerations << valuea = CustomFieldEnumeration.new(:name => 'Value A', :position => 2)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => valueb.id)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => valueb.id)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => valuea.id)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "cf_#{cf.id}"
}
)
assert_response :success
assert_select 'tr.group', 3
assert_select 'tr.group' do
assert_select 'span.name', :text => 'Value B'
assert_select 'span.count', :text => '2'
end
assert_select 'tr.group' do
assert_select 'span.name', :text => 'Value A'
assert_select 'span.count', :text => '1'
end
end
def test_index_with_query_grouped_by_user_custom_field
cf = IssueCustomField.
create!(
:name => 'User',
:is_for_all => true,
:tracker_ids => [1, 2, 3],
:field_format => 'user'
)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "cf_#{cf.id}"
}
)
assert_response :success
assert_select 'tr.group', 3
assert_select 'tr.group' do
assert_select 'a', :text => 'John Smith'
assert_select 'span.count', :text => '1'
end
assert_select 'tr.group' do
assert_select 'a', :text => 'Dave Lopper'
assert_select 'span.count', :text => '2'
end
end
def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
cf = IssueCustomField.
create!(
:name => 'Bool',
:is_for_all => true,
:tracker_ids => [1, 2, 3],
:field_format => 'bool'
)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')
with_settings :default_language => 'en' do
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1,
:group_by => "cf_#{cf.id}"
}
)
assert_response :success
end
assert_select 'tr.group', 3
assert_select 'tr.group', :text => /Yes/
assert_select 'tr.group', :text => /No/
assert_select 'tr.group', :text => /blank/
end
def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
cf = IssueCustomField.
create!(
:name => 'Bool',
:is_for_all => true,
:tracker_ids => [1, 2, 3],
:field_format => 'bool',
:is_filter => true
)
CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
with_settings :default_language => 'en' do
get(
:index,
:params => {
:project_id => 1,
:set_filter => 1, "cf_#{cf.id}" => "*",
:group_by => "cf_#{cf.id}"
}
)
assert_response :success
end
assert_equal [1, 2], issues_in_list.map(&:id).sort
assert_select 'tr.group', 1
assert_select 'tr.group', :text => /No/
end
def test_index_with_query_grouped_by_tracker_in_normal_order
3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
get(
:index,
:params => {
:set_filter => 1,
:group_by => 'tracker',
:sort => 'id:desc'
}
)
assert_response :success
assert_equal ["Bug", "Feature request", "Support request"],
css_select("tr.issue td.tracker").map(&:text).uniq
end
def test_index_with_query_grouped_by_tracker_in_reverse_order
3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
get(
:index,
:params => {
:set_filter => 1,
:group_by => 'tracker',
:c => ['tracker', 'subject'],
:sort => 'id:desc,tracker:desc'
}
)
assert_response :success
assert_equal ["Bug", "Feature request", "Support request"].reverse,
css_select("tr.issue td.tracker").map(&:text).uniq
end
def test_index_with_query_id_and_project_id_should_set_session_query
get(
:index,
:params => {
:project_id => 1,
:query_id => 4
}
)
assert_response :success
assert_kind_of Hash, session[:issue_query]
assert_equal 4, session[:issue_query][:id]
assert_equal 1, session[:issue_query][:project_id]
end
def test_index_with_invalid_query_id_should_respond_404
get(
:index,
:params => {
:project_id => 1,
:query_id => 999
}
)
assert_response 404
end
def test_index_with_cross_project_query_in_session_should_show_project_issues
q = IssueQuery.
create!(
:name => "cross_project_query", :user_id => 2,
:project => nil, :column_names => ['project']
)
@request.session[:issue_query] = {:id => q.id, :project_id => 1}
with_settings :display_subprojects_issues => '0' do
get(:index, :params => {:project_id => 1})
end
assert_response :success
assert_select 'h2', :text => q.name
assert_equal ["eCookbook"], css_select("tr.issue td.project").map(&:text).uniq
end
def test_private_query_should_not_be_available_to_other_users
q = IssueQuery.
create!(
:name => "private", :user => User.find(2),
:visibility => IssueQuery::VISIBILITY_PRIVATE,
:project => nil
)
@request.session[:user_id] = 3
get(:index, :params => {:query_id => q.id})
assert_response 403
end
def test_private_query_should_be_available_to_its_user
q = IssueQuery.
create!(
:name => "private", :user => User.find(2),
:visibility => IssueQuery::VISIBILITY_PRIVATE,
:project => nil
)
@request.session[:user_id] = 2
get(:index, :params => {:query_id => q.id})
assert_response :success
end
def test_public_query_should_be_available_to_other_users
q = IssueQuery.
create!(
:name => "public", :user => User.find(2),
:visibility => IssueQuery::VISIBILITY_PUBLIC,
:project => nil
)
@request.session[:user_id] = 3
get(:index, :params => {:query_id => q.id})
assert_response :success
end
def test_index_should_omit_page_param_in_export_links
get(:index, :params => {:page => 2})
assert_response :success
assert_select 'a.atom[href="/issues.atom"]'
assert_select 'a.csv[href="/issues.csv"]'
assert_select 'a.pdf[href="/issues.pdf"]'
assert_select 'form#csv-export-form[action="/issues.csv"]'
end
def test_index_should_not_warn_when_not_exceeding_export_limit
with_settings :issues_export_limit => 200 do
get :index
assert_select '#csv-export-options p.icon-warning', 0
end
end
def test_index_should_warn_when_exceeding_export_limit
with_settings :issues_export_limit => 2 do
get :index
assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
end
end
def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
get(
:index,
:params => {
:project_id => 1,
:set_filter => "1",
:tracker_id => "2",
:sort => 'status',
:c => ["status", "priority"]
}
)
assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
assert_select '#csv-export-form[method=?]', 'get'
assert_select '#csv-export-form' do
assert_select 'input[name=?][value=?]', 'set_filter', '1'
assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'
assert_select 'input[name=?][value=?]', 'c[]', 'status'
assert_select 'input[name=?][value=?]', 'c[]', 'priority'
assert_select 'input[name=?][value=?]', 'sort', 'status'
end
get(
:index,
:params => {
:project_id => 1,
:set_filter => "1",
:f => ['']
}
)
assert_select '#csv-export-form input[name=?][value=?]', 'f[]', ''
end
def test_index_should_show_block_columns_in_csv_export_form
field = IssueCustomField.
create!(
:name => 'Long text', :field_format => 'text',
:full_width_layout => '1',
:tracker_ids => [1], :is_for_all => true
)
get :index
assert_response :success
assert_select '#csv-export-form' do
assert_select 'input[value=?]', 'description'
assert_select 'input[value=?]', 'last_notes'
assert_select 'input[value=?]', "cf_#{field.id}"
end
end
def test_index_csv
get(:index, :params => {:format => 'csv'})
assert_response :success
assert_equal 'text/csv; header=present', @response.media_type
assert response.body.starts_with?("#,")
lines = response.body.chomp.split("\n")
# default columns + id and project
assert_equal Setting.issue_list_default_columns.size + 2, lines[0].split(',').size
end
def test_index_csv_filename_without_query_name_param
get :index, :params => {:format => 'csv'}
assert_response :success
assert_match /issues.csv/, @response.headers['Content-Disposition']
end
def test_index_csv_filename_with_query_name_param
get :index, :params => {:query_name => 'My Query Name', :format => 'csv'}
assert_response :success
assert_match /my_query_name\.csv/, @response.headers['Content-Disposition']
end
def test_index_csv_with_project
get(
:index,
:params => {
:project_id => 1,
:format => 'csv'
}
)
assert_response :success
assert_equal 'text/csv; header=present', @response.media_type
end
def test_index_csv_without_any_filters
@request.session[:user_id] = 1
Issue.
create!(
:project_id => 1, :tracker_id => 1,
:status_id => 5, :subject => 'Closed issue', :author_id => 1
)
get(
:index,
:params => {
:set_filter => 1,
:f => [''],
:format => 'csv'
}
)
assert_response :success
# -1 for headers
assert_equal Issue.count, response.body.chomp.split("\n").size - 1
end
def test_index_csv_with_description
Issue.generate!(:description => 'test_index_csv_with_description')
with_settings :default_language => 'en' do
get(
:index,
:params => {
:format => 'csv',
:c => [:tracker, :description]
}
)
assert_response :success
end
assert_equal 'text/csv; header=present', response.media_type
headers = response.body.chomp.split("\n").first.split(',')
assert_include 'Description', headers
assert_include 'test_index_csv_with_description', response.body
end
def test_index_csv_with_spent_time_column
issue = Issue.
create!(
:project_id => 1, :tracker_id => 1,
:subject => 'test_index_csv_with_spent_time_column',
:author_id => 2
)
TimeEntry.
create!(
:project => issue.project, :issue => issue,
:hours => 7.33, :user => User.find(2),
:spent_on => Date.today
)
get(
:index,
:params => {
:format => 'csv',
:set_filter => '1',
:c => %w(subject spent_hours)
}
)
assert_response :success
assert_equal 'text/csv; header=present', @response.media_type
lines = @response.body.chomp.split("\n")
assert_include "#{issue.id},#{issue.subject},7.33", lines
end
def test_index_csv_with_all_columns
get(
:index,
:params => {
:format => 'csv',
:c => ['all_inline']
}
)
assert_response :success
assert_equal 'text/csv; header=present', @response.media_type
assert_match /\A#,/, response.body
lines = response.body.chomp.split("\n")
assert_equal IssueQuery.new.available_inline_columns.size, lines[0].split(',').size
end
def test_index_csv_with_multi_column_field
CustomField.find(1).update_attribute :multiple, true
issue = Issue.find(1)
issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
issue.save!
get(
:index,
:params => {
:format => 'csv',
:c => ['tracker', "cf_1"]
}
)
assert_response :success
lines = @response.body.chomp.split("\n")
assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
end
def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
field =
IssueCustomField.
create!(
:name => 'Float',
:is_for_all => true,
:tracker_ids => [1],
:field_format => 'float'
)
issue =
Issue.
generate!(
:project_id => 1, :tracker_id => 1,
:custom_field_values => {field.id => '185.6'}
)
with_settings :default_language => 'fr' do
get(
:index,
:params => {
:format => 'csv',
:c => ['id', 'tracker', "cf_#{field.id}"]
}
)
assert_response :success
issue_line =
response.body.chomp.split("\n").