forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budget_investments_spec.rb
1878 lines (1414 loc) · 69.8 KB
/
budget_investments_spec.rb
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
require "rails_helper"
describe "Admin budget investments" do
let(:budget) { create(:budget) }
let(:administrator) do
create(:administrator, user: create(:user, username: "Ana", email: "[email protected]"))
end
it_behaves_like "admin_milestoneable",
:budget_investment,
"admin_budget_budget_investment_path"
before do
@admin = create(:administrator)
login_as(@admin.user)
end
context "Feature flag" do
before do
Setting["process.budgets"] = nil
end
scenario "Disabled with a feature flag" do
expect { visit admin_budgets_path }.to raise_exception(FeatureFlags::FeatureDisabled)
end
end
context "Load" do
let!(:investment) { create(:budget_investment, budget: budget) }
before { budget.update(slug: "budget_slug") }
scenario "finds investments using budget slug" do
visit admin_budget_budget_investments_path("budget_slug")
expect(page).to have_link investment.title
end
scenario "raises an error if budget slug is not found" do
expect do
visit admin_budget_budget_investments_path("wrong_budget", investment)
end.to raise_error ActiveRecord::RecordNotFound
end
scenario "raises an error if budget id is not found" do
expect do
visit admin_budget_budget_investments_path(0, investment)
end.to raise_error ActiveRecord::RecordNotFound
end
end
context "Index" do
scenario "Displaying investments" do
budget_investment = create(:budget_investment, budget: budget, cached_votes_up: 77)
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_content(budget_investment.title)
expect(page).to have_content(budget_investment.heading.name)
expect(page).to have_content(budget_investment.id)
expect(page).to have_content(budget_investment.total_votes)
end
scenario "If budget is finished do not show 'Selected' button" do
finished_budget = create(:budget, :finished)
budget_investment = create(:budget_investment, budget: finished_budget, cached_votes_up: 77)
visit admin_budget_budget_investments_path(budget_id: finished_budget.id)
within("#budget_investment_#{budget_investment.id}") do
expect(page).to have_content(budget_investment.title)
expect(page).to have_content(budget_investment.heading.name)
expect(page).to have_content(budget_investment.id)
expect(page).to have_content(budget_investment.total_votes)
expect(page).not_to have_link("Selected")
end
end
scenario "Display admin and valuator assignments" do
budget_investment1 = create(:budget_investment, budget: budget)
budget_investment2 = create(:budget_investment, budget: budget)
budget_investment3 = create(:budget_investment, budget: budget)
olga = create(:user, username: "Olga")
miriam = create(:user, username: "Miriam")
valuator1 = create(:valuator, user: olga, description: "Valuator Olga")
valuator2 = create(:valuator, user: miriam, description: "Valuator Miriam")
valuator_group = create(:valuator_group, name: "Health")
admin = create(:administrator, user: create(:user, username: "Gema"))
budget_investment1.valuators << valuator1
budget_investment2.valuators << valuator1
budget_investment2.valuators << valuator2
budget_investment2.valuator_groups << valuator_group
visit admin_budget_budget_investments_path(budget_id: budget.id)
within("#budget_investment_#{budget_investment1.id}") do
expect(page).to have_content("No admin assigned")
expect(page).to have_content("Valuator Olga")
end
within("#budget_investment_#{budget_investment2.id}") do
expect(page).to have_content("No admin assigned")
expect(page).to have_content("Valuator Olga")
expect(page).to have_content("Valuator Miriam")
expect(page).to have_content("Health")
end
budget_investment3.update(administrator_id: admin.id)
visit admin_budget_budget_investments_path(budget_id: budget.id)
within("#budget_investment_#{budget_investment3.id}") do
expect(page).to have_content("Gema")
expect(page).to have_content("No valuators assigned")
end
end
scenario "Filtering by budget heading", :js do
group1 = create(:budget_group, name: "Streets", budget: budget)
group2 = create(:budget_group, name: "Parks", budget: budget)
group1_heading1 = create(:budget_heading, group: group1, name: "Main Avenue")
group1_heading2 = create(:budget_heading, group: group1, name: "Mercy Street")
group2_heading1 = create(:budget_heading, group: group2, name: "Central Park")
create(:budget_investment, title: "Realocate visitors", budget: budget, group: group1,
heading: group1_heading1)
create(:budget_investment, title: "Change name", budget: budget, group: group1,
heading: group1_heading2)
create(:budget_investment, title: "Plant trees", budget: budget, group: group2,
heading: group2_heading1)
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Change name")
expect(page).to have_link("Plant trees")
select "Central Park", from: "heading_id"
click_button "Filter"
expect(page).not_to have_link("Realocate visitors")
expect(page).not_to have_link("Change name")
expect(page).to have_link("Plant trees")
select "All headings", from: "heading_id"
click_button "Filter"
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Change name")
expect(page).to have_link("Plant trees")
select "Streets: Main Avenue", from: "heading_id"
click_button "Filter"
expect(page).to have_link("Realocate visitors")
expect(page).not_to have_link("Change name")
expect(page).not_to have_link("Plant trees")
select "Streets: Mercy Street", from: "heading_id"
click_button "Filter"
expect(page).not_to have_link("Realocate visitors")
expect(page).to have_link("Change name")
expect(page).not_to have_link("Plant trees")
end
scenario "Filtering by admin", :js do
user = create(:user, username: "Admin 1")
user2 = create(:user, username: "Admin 2")
administrator = create(:administrator, user: user)
create(:administrator, user: user2, description: "Alias")
create(:budget_investment, title: "Realocate visitors", budget: budget,
administrator: administrator)
create(:budget_investment, title: "Destroy the city", budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
select "Admin 1", from: "administrator_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "Alias", from: "administrator_id"
click_button "Filter"
expect(page).to have_content("There are no investment projects")
expect(page).not_to have_link("Destroy the city")
expect(page).not_to have_link("Realocate visitors")
select "All administrators", from: "administrator_id"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "Admin 1", from: "administrator_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
end
scenario "Filtering by valuator", :js do
user = create(:user)
valuator = create(:valuator, user: user, description: "Valuator 1")
budget_investment = create(:budget_investment, title: "Realocate visitors", budget: budget)
budget_investment.valuators << valuator
create(:budget_investment, title: "Destroy the city", budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
select "Valuator 1", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "All valuators", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
select "Valuator 1", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
end
scenario "Filtering by valuator group", :js do
health_group = create(:valuator_group, name: "Health")
culture_group = create(:valuator_group, name: "Culture")
budget_investment1 = create(:budget_investment, title: "Build a hospital", budget: budget)
budget_investment1.valuator_groups << health_group
budget_investment2 = create(:budget_investment, title: "Build a theatre", budget: budget)
budget_investment2.valuator_groups << culture_group
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Build a hospital")
expect(page).to have_link("Build a theatre")
select "Health", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Build a hospital")
expect(page).not_to have_link("Build a theatre")
select "All valuators", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Build a hospital")
expect(page).to have_link("Build a theatre")
select "Culture", from: "valuator_or_group_id"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Build a theatre")
expect(page).not_to have_link("Build a hospital")
end
scenario "Filtering by without assigned admin", :js do
create(:budget_investment,
title: "Investment without admin",
budget: budget)
create(:budget_investment,
:with_administrator,
title: "Investment with admin",
budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Investment without admin")
expect(page).to have_link("Investment with admin")
click_link "Advanced filters"
check("Without assigned admin")
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Investment without admin")
expect(page).not_to have_link("Investment with admin")
uncheck("Without assigned admin")
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Investment without admin")
expect(page).to have_link("Investment with admin")
end
scenario "Filtering by without assigned valuator", :js do
user = create(:user)
valuator = create(:valuator, user: user)
create(:budget_investment,
title: "Investment without valuator",
budget: budget)
create(:budget_investment,
title: "Investment with valuator",
budget: budget,
valuators: [valuator])
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Investment without valuator")
expect(page).to have_link("Investment with valuator")
click_link "Advanced filters"
check "Without assigned valuator"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Investment without valuator")
expect(page).not_to have_link("Investment with valuator")
uncheck "Without assigned valuator"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Investment without valuator")
expect(page).to have_link("Investment with valuator")
end
scenario "Filtering by under valuation", :js do
user = create(:user)
valuator = create(:valuator, user: user)
create(:budget_investment,
:with_administrator,
valuation_finished: false,
title: "Investment without valuation",
budget: budget,
valuators: [valuator])
create(:budget_investment,
:with_administrator,
title: "Investment with valuation",
budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Investment without valuation")
expect(page).to have_link("Investment with valuation")
click_link "Advanced filters"
check "Under valuation"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Investment without valuation")
expect(page).not_to have_link("Investment with valuation")
uncheck "Under valuation"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Investment without valuation")
expect(page).to have_link("Investment with valuation")
end
scenario "Filtering by valuation finished", :js do
create(:budget_investment,
title: "Investment valuation open",
budget: budget)
create(:budget_investment,
:finished,
title: "Investment valuation finished",
budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Investment valuation open")
expect(page).to have_link("Investment valuation finished")
click_link "Advanced filters"
check "Valuation finished"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).not_to have_link("Investment valuation open")
expect(page).to have_link("Investment valuation finished")
uncheck "Valuation finished"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Investment valuation open")
expect(page).to have_link("Investment valuation finished")
end
scenario "Filtering by winners", :js do
create(:budget_investment,
:winner,
valuation_finished: true,
title: "Investment winner",
budget: budget)
create(:budget_investment,
title: "Investment without winner",
budget: budget)
visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Investment winner")
expect(page).to have_link("Investment without winner")
click_link "Advanced filters"
check "Winners"
click_button "Filter"
expect(page).to have_content("There is 1 investment")
expect(page).to have_link("Investment winner")
expect(page).not_to have_link("Investment without winner")
uncheck "Winners"
click_button "Filter"
expect(page).to have_content("There are 2 investments")
expect(page).to have_link("Investment winner")
expect(page).to have_link("Investment without winner")
end
scenario "Current filter is properly highlighted" do
filters_links = { "all" => "All" }
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).not_to have_link(filters_links.values.first)
filters_links.keys.drop(1).each { |filter| expect(page).to have_link(filters_links[filter]) }
filters_links.each_pair do |current_filter, link|
visit admin_budget_budget_investments_path(budget_id: budget.id, filter: current_filter)
expect(page).not_to have_link(link)
(filters_links.keys - [current_filter]).each do |filter|
expect(page).to have_link(filters_links[filter])
end
end
end
scenario "Filtering by assignment status" do
create(:budget_investment, title: "Assigned idea", budget: budget,
administrator: create(:administrator))
create(:budget_investment, title: "Evaluating...", budget: budget,
valuators: [create(:valuator)])
create(:budget_investment, title: "With group", budget: budget,
valuator_groups: [create(:valuator_group)])
visit admin_budget_budget_investments_path(budget_id: budget.id, filter: "valuation_open")
expect(page).to have_content("Assigned idea")
expect(page).to have_content("Evaluating...")
expect(page).to have_content("With group")
visit admin_budget_budget_investments_path(budget_id: budget.id,
advanced_filters: ["without_admin"])
expect(page).to have_content("Evaluating...")
expect(page).to have_content("With group")
expect(page).not_to have_content("Assigned idea")
visit admin_budget_budget_investments_path(budget_id: budget.id,
advanced_filters: ["without_valuator"])
expect(page).to have_content("Assigned idea")
expect(page).not_to have_content("Evaluating...")
expect(page).not_to have_content("With group")
end
scenario "Filtering by valuation status" do
valuating = create(:budget_investment, budget: budget, title: "Ongoing valuation",
administrator: create(:administrator))
valuated = create(:budget_investment, budget: budget, title: "Old idea",
valuation_finished: true)
valuating.valuators.push(create(:valuator))
valuated.valuators.push(create(:valuator))
query_params = { budget_id: budget.id, advanced_filters: ["under_valuation"] }
visit admin_budget_budget_investments_path(query_params)
expect(page).to have_content("Ongoing valuation")
expect(page).not_to have_content("Old idea")
visit admin_budget_budget_investments_path(budget_id: budget.id,
advanced_filters: ["valuation_finished"])
expect(page).not_to have_content("Ongoing valuation")
expect(page).to have_content("Old idea")
visit admin_budget_budget_investments_path(budget_id: budget.id, advanced_filters: ["filter"])
expect(page).to have_content("Ongoing valuation")
expect(page).to have_content("Old idea")
end
scenario "Filtering by tag" do
create(:budget_investment, budget: budget, title: "Educate children", tag_list: "Education")
create(:budget_investment, budget: budget, title: "More schools", tag_list: "Education")
create(:budget_investment, budget: budget, title: "More hospitals", tag_list: "Health")
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_css(".budget_investment", count: 3)
expect(page).to have_content("Educate children")
expect(page).to have_content("More schools")
expect(page).to have_content("More hospitals")
visit admin_budget_budget_investments_path(budget_id: budget.id, tag_name: "Education")
expect(page).not_to have_content("More hospitals")
expect(page).to have_css(".budget_investment", count: 2)
expect(page).to have_content("Educate children")
expect(page).to have_content("More schools")
end
scenario "Filtering by tag, display only valuation tags" do
investment1 = create(:budget_investment, budget: budget, tag_list: "Education")
investment2 = create(:budget_investment, budget: budget, tag_list: "Health")
investment1.set_tag_list_on(:valuation, "Teachers")
investment2.set_tag_list_on(:valuation, "Hospitals")
investment1.save
investment2.save
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_select("tag_name", options: ["All tags", "Hospitals", "Teachers"])
end
scenario "Filtering by tag, display only valuation tags of the current budget" do
new_budget = create(:budget)
investment1 = create(:budget_investment, budget: budget, tag_list: "Roads")
investment2 = create(:budget_investment, budget: new_budget, tag_list: "Accessibility")
investment1.set_tag_list_on(:valuation, "Roads")
investment2.set_tag_list_on(:valuation, "Accessibility")
investment1.save
investment2.save
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_select("tag_name", options: ["All tags", "Roads"])
expect(page).not_to have_select("tag_name", options: ["All tags", "Accessibility"])
end
scenario "Disable 'Calculate winner' button if incorrect phase" do
budget.update(phase: "reviewing_ballots")
visit admin_budget_budget_investments_path(budget)
click_link "Advanced filters"
check "Winners"
click_button "Filter"
expect(page).to have_link "Calculate Winner Investments"
visit edit_admin_budget_path(budget)
expect(page).to have_link "Calculate Winner Investments"
budget.update(phase: "accepting")
visit admin_budget_budget_investments_path(budget)
check "Winners"
click_button "Filter"
expect(page).not_to have_link "Calculate Winner Investments"
expect(page).to have_content 'The budget has to stay on phase "Balloting projects", '\
'"Reviewing Ballots" or "Finished budget" in order '\
"to calculate winners projects"
visit edit_admin_budget_path(budget)
expect(page).not_to have_link "Calculate Winner Investments"
end
scenario "Filtering by minimum number of votes", :js do
group_1 = create(:budget_group, budget: budget)
group_2 = create(:budget_group, budget: budget)
parks = create(:budget_heading, group: group_1)
roads = create(:budget_heading, group: group_2)
streets = create(:budget_heading, group: group_2)
create(:budget_investment, heading: parks, cached_votes_up: 40, title: "Park 40 supports")
create(:budget_investment, heading: parks, cached_votes_up: 99, title: "Park 99 supports")
create(:budget_investment, heading: roads, cached_votes_up: 100, title: "Road 100 supports")
create(:budget_investment, heading: roads, cached_votes_up: 199, title: "Road 199 supports")
create(:budget_investment, heading: streets, cached_votes_up: 200, title: "St. 200 supports")
create(:budget_investment, heading: streets, cached_votes_up: 300, title: "St. 300 supports")
visit admin_budget_budget_investments_path(budget)
expect(page).to have_link("Park 40 supports")
expect(page).to have_link("Park 99 supports")
expect(page).to have_link("Road 100 supports")
expect(page).to have_link("Road 199 supports")
expect(page).to have_link("St. 200 supports")
expect(page).to have_link("St. 300 supports")
click_link "Advanced filters"
fill_in "min_total_supports", with: 180
click_button "Filter"
expect(page).to have_content("There are 3 investments")
expect(page).to have_link("Road 199 supports")
expect(page).to have_link("St. 200 supports")
expect(page).to have_link("St. 300 supports")
expect(page).not_to have_link("Park 40 supports")
expect(page).not_to have_link("Park 99 supports")
expect(page).not_to have_link("Road 100 supports")
end
scenario "Filtering by maximum number of votes", :js do
group_1 = create(:budget_group, budget: budget)
group_2 = create(:budget_group, budget: budget)
parks = create(:budget_heading, group: group_1)
roads = create(:budget_heading, group: group_2)
streets = create(:budget_heading, group: group_2)
create(:budget_investment, heading: parks, cached_votes_up: 40, title: "Park 40 supports")
create(:budget_investment, heading: parks, cached_votes_up: 99, title: "Park 99 supports")
create(:budget_investment, heading: roads, cached_votes_up: 100, title: "Road 100 supports")
create(:budget_investment, heading: roads, cached_votes_up: 199, title: "Road 199 supports")
create(:budget_investment, heading: streets, cached_votes_up: 200, title: "St. 200 supports")
create(:budget_investment, heading: streets, cached_votes_up: 300, title: "St. 300 supports")
visit admin_budget_budget_investments_path(budget)
expect(page).to have_link("Park 40 supports")
expect(page).to have_link("Park 99 supports")
expect(page).to have_link("Road 100 supports")
expect(page).to have_link("Road 199 supports")
expect(page).to have_link("St. 200 supports")
expect(page).to have_link("St. 300 supports")
click_link "Advanced filters"
fill_in "max_total_supports", with: 180
click_button "Filter"
expect(page).to have_content("There are 3 investments")
expect(page).not_to have_link("Road 199 supports")
expect(page).not_to have_link("St. 200 supports")
expect(page).not_to have_link("St. 300 supports")
expect(page).to have_link("Park 40 supports")
expect(page).to have_link("Park 99 supports")
expect(page).to have_link("Road 100 supports")
end
scenario "Combination of checkbox with text search", :js do
user = create(:user, username: "Admin 1")
administrator = create(:administrator, user: user)
create(:budget_investment, budget: budget, title: "Educate the children",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More schools",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More hospitals")
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_css(".budget_investment", count: 3)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).to have_content("More hospitals")
select "Admin 1", from: "administrator_id"
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 2)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).not_to have_content("More hospitals")
educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 1)
expect(page).to have_content("Educate the children")
expect(page).not_to have_content("More schools")
expect(page).not_to have_content("More hospitals")
expect(page).to have_content("Selected")
end
scenario "Combination of select with text search", :js do
create(:budget_investment, budget: budget, title: "Educate the children",
feasibility: "feasible", valuation_finished: true)
create(:budget_investment, budget: budget, title: "More schools",
feasibility: "feasible", valuation_finished: true)
create(:budget_investment, budget: budget, title: "More hospitals")
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_css(".budget_investment", count: 3)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).to have_content("More hospitals")
click_link "Advanced filters"
check("Feasible")
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 2)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).not_to have_content("More hospitals")
educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 1)
expect(page).to have_content("Educate the children")
expect(page).not_to have_content("More schools")
expect(page).not_to have_content("More hospitals")
expect(page).to have_content("Selected")
end
scenario "Combination of checkbox with text search and checkbox", :js do
user = create(:user, username: "Admin 1")
administrator = create(:administrator, user: user)
create(:budget_investment, budget: budget, title: "Educate the children",
feasibility: "feasible", valuation_finished: true,
administrator: administrator)
create(:budget_investment, budget: budget, title: "More schools",
feasibility: "feasible", valuation_finished: true,
administrator: administrator)
create(:budget_investment, budget: budget, title: "More hospitals",
administrator: administrator)
create(:budget_investment, budget: budget, title: "More hostals")
visit admin_budget_budget_investments_path(budget_id: budget.id)
expect(page).to have_css(".budget_investment", count: 4)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).to have_content("More hospitals")
expect(page).to have_content("More hostals")
select "Admin 1", from: "administrator_id"
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 3)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).to have_content("More hospitals")
expect(page).not_to have_content("More hostals")
click_link "Advanced filters"
within("#advanced_filters") { check("Feasible") }
click_button("Filter")
expect(page).to have_css(".budget_investment", count: 2)
expect(page).to have_content("Educate the children")
expect(page).to have_content("More schools")
expect(page).not_to have_content("More hospitals")
expect(page).not_to have_content("More hostals")
educate_children_investment = Budget::Investment.find_by(title: "Educate the children")
fill_in "title_or_id", with: educate_children_investment.id
click_button "Filter"
expect(page).to have_css(".budget_investment", count: 1)
expect(page).to have_content("Educate the children")
expect(page).not_to have_content("More schools")
expect(page).not_to have_content("More hospitals")
expect(page).not_to have_content("More hostals")
expect(page).to have_content("Selected")
end
scenario "See results button appears when budget status is finished" do
finished_budget = create(:budget, :finished)
create(:budget_investment, :winner, budget: finished_budget, title: "Winner project")
visit admin_budget_budget_investments_path(budget_id: finished_budget.id)
expect(page).to have_content "See results"
end
scenario "See results button does not appear for unfinished budgets" do
not_finished_budget = create(:budget, :valuating)
visit admin_budget_budget_investments_path(budget_id: not_finished_budget.id)
expect(page).not_to have_content "See results"
end
end
context "Search" do
let!(:first_investment) do
create(:budget_investment, title: "Some other investment", budget: budget)
end
before do
I18n.with_locale(:es) do
create(:budget_investment, title: "Proyecto de inversión", budget: budget)
end
end
scenario "Search investments by title" do
visit admin_budget_budget_investments_path(budget)
expect(page).to have_content("Proyecto de inversión")
expect(page).to have_content("Some other investment")
fill_in "title_or_id", with: "Proyecto de inversión"
click_button "Filter"
expect(page).to have_content("Proyecto de inversión")
expect(page).not_to have_content("Some other investment")
fill_in "title_or_id", with: "Some other investment"
click_button "Filter"
expect(page).not_to have_content("Proyecto de inversión")
expect(page).to have_content("Some other investment")
end
scenario "Search investments by ID" do
visit admin_budget_budget_investments_path(budget)
expect(page).to have_content("Proyecto de inversión")
expect(page).to have_content("Some other investment")
fill_in "title_or_id", with: first_investment.id
click_button "Filter"
expect(page).to have_content("Some other investment")
expect(page).not_to have_content("Proyecto de inversión")
end
end
context "Sorting" do
before do
create(:budget_investment, title: "B First Investment", budget: budget, cached_votes_up: 50)
create(:budget_investment, title: "A Second Investment", budget: budget, cached_votes_up: 25)
create(:budget_investment, title: "C Third Investment", budget: budget, cached_votes_up: 10)
end
scenario "Default" do
create(:budget_investment, title: "D Fourth Investment", cached_votes_up: 50, budget: budget)
visit admin_budget_budget_investments_path(budget)
expect("D Fourth Investment").to appear_before("B First Investment")
expect("B First Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("C Third Investment")
end
context "Ascending" do
scenario "Sort by ID" do
visit admin_budget_budget_investments_path(budget, sort_by: "id", direction: "asc")
expect("B First Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("C Third Investment")
within("th", text: "ID") do
expect(page).to have_css(".icon-sortable.desc")
end
end
scenario "Sort by title" do
visit admin_budget_budget_investments_path(budget, sort_by: "title", direction: "asc")
expect("A Second Investment").to appear_before("B First Investment")
expect("B First Investment").to appear_before("C Third Investment")
within("th", text: "Title") do
expect(page).to have_css(".icon-sortable.desc")
end
end
scenario "Sort by supports" do
visit admin_budget_budget_investments_path(budget, sort_by: "supports", direction: "asc")
expect("C Third Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("B First Investment")
within("th", text: "Supports") do
expect(page).to have_css(".icon-sortable.desc")
end
end
end
context "Descending" do
scenario "Sort by ID" do
visit admin_budget_budget_investments_path(budget, sort_by: "id", direction: "desc")
expect("C Third Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("B First Investment")
within("th", text: "ID") do
expect(page).to have_css(".icon-sortable.asc")
end
end
scenario "Sort by title" do
visit admin_budget_budget_investments_path(budget, sort_by: "title", direction: "desc")
expect("C Third Investment").to appear_before("B First Investment")
expect("B First Investment").to appear_before("A Second Investment")
within("th", text: "Title") do
expect(page).to have_css(".icon-sortable.asc")
end
end
scenario "Sort by supports" do
visit admin_budget_budget_investments_path(budget, sort_by: "supports", direction: "desc")
expect("B First Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("C Third Investment")
within("th", text: "Supports") do
expect(page).to have_css(".icon-sortable.asc")
end
end
end
context "With no direction provided sorts ascending" do
scenario "Sort by ID" do
visit admin_budget_budget_investments_path(budget, sort_by: "id")
expect("B First Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("C Third Investment")
within("th", text: "ID") do
expect(page).to have_css(".icon-sortable.desc")
end
end
scenario "Sort by title" do
visit admin_budget_budget_investments_path(budget, sort_by: "title")
expect("A Second Investment").to appear_before("B First Investment")
expect("B First Investment").to appear_before("C Third Investment")
within("th", text: "Title") do
expect(page).to have_css(".icon-sortable.desc")
end
end
scenario "Sort by supports" do
visit admin_budget_budget_investments_path(budget, sort_by: "supports")
expect("C Third Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("B First Investment")
within("th", text: "Supports") do
expect(page).to have_css(".icon-sortable.desc")
end
end
end
context "With incorrect direction provided sorts ascending" do
scenario "Sort by ID" do
visit admin_budget_budget_investments_path(budget, sort_by: "id", direction: "incorrect")
expect("B First Investment").to appear_before("A Second Investment")
expect("A Second Investment").to appear_before("C Third Investment")
within("th", text: "ID") do
expect(page).to have_css(".icon-sortable.desc")
end
end
end
end
context "Show" do
scenario "Show the investment details" do
user = create(:user, username: "Rachel", email: "[email protected]")
valuator = create(:valuator, user: user)
budget_investment = create(:budget_investment,
price: 1234,
price_first_year: 1000,
feasibility: "unfeasible",
unfeasibility_explanation: "It is impossible",
administrator: administrator)
budget_investment.valuators << valuator
visit admin_budget_budget_investments_path(budget_investment.budget)
click_link budget_investment.title