-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
debates_spec.rb
859 lines (658 loc) · 27.4 KB
/
debates_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
require "rails_helper"
describe "Debates" do
context "Concerns" do
it_behaves_like "notifiable in-app", :debate
it_behaves_like "relationable", Debate
it_behaves_like "remotely_translatable",
:debate,
"debates_path",
{}
it_behaves_like "remotely_translatable",
:debate,
"debate_path",
{ "id": "id" }
it_behaves_like "flaggable", :debate
end
scenario "Index" do
debates = [create(:debate), create(:debate), create(:debate)]
visit debates_path
expect(page).to have_selector("#debates .debate", count: 3)
debates.each do |debate|
within("#debates") do
expect(page).to have_content debate.title
expect(page).to have_content debate.description
expect(page).to have_css("a[href='#{debate_path(debate)}']", text: debate.title)
end
end
end
scenario "Paginated Index" do
per_page = 3
allow(Debate).to receive(:default_per_page).and_return(per_page)
(per_page + 2).times { create(:debate) }
visit debates_path
expect(page).to have_selector("#debates .debate", count: per_page)
within("ul.pagination") do
expect(page).to have_content("1")
expect(page).to have_content("2")
expect(page).not_to have_content("3")
click_link "Next", exact: false
end
expect(page).to have_selector("#debates .debate", count: 2)
end
scenario "Index view mode" do
debates = [create(:debate), create(:debate), create(:debate)]
visit debates_path
click_button "View mode"
click_link "List"
debates.each do |debate|
within("#debates") do
expect(page).to have_link debate.title
expect(page).not_to have_content debate.description
end
end
click_button "View mode"
click_link "Cards"
debates.each do |debate|
within("#debates") do
expect(page).to have_link debate.title
expect(page).to have_content debate.description
end
end
end
scenario "Show" do
debate = create(:debate)
visit debate_path(debate)
expect(page).to have_content debate.title
expect(page).to have_content "Debate description"
expect(page).to have_content debate.author.name
expect(page).to have_content I18n.l(debate.created_at.to_date)
expect(page).to have_selector(avatar(debate.author.name))
expect(page.html).to include "<title>#{debate.title}</title>"
end
describe "Social share buttons", :js do
context "On desktop browsers" do
scenario "Shows links to share on facebook and twitter" do
visit debate_path(create(:debate))
within(".social-share-button") do
expect(page.all("a").count).to be(2)
expect(page).to have_link "Share to Facebook"
expect(page).to have_link "Share to Twitter"
end
end
end
context "On small devices" do
let!(:window_size) { Capybara.current_window.size }
before do
Capybara.current_window.resize_to(639, 479)
end
after do
Capybara.current_window.resize_to(*window_size)
end
scenario "Shows links to share on telegram and whatsapp too" do
visit debate_path(create(:debate))
within(".social-share-button") do
expect(page.all("a").count).to be(4)
expect(page).to have_link "Share to Facebook"
expect(page).to have_link "Share to Twitter"
expect(page).to have_link "Share to Telegram"
expect(page).to have_link "Share to WhatsApp"
end
end
end
end
scenario "Show: 'Back' link directs to previous page" do
debate = create(:debate, title: "Test Debate 1")
visit debates_path(order: :hot_score, page: 1)
within("#debate_#{debate.id}") do
click_link debate.title
end
link_text = find_link("Go back")[:href]
expect(link_text).to include(debates_path(order: :hot_score, page: 1))
end
context "Show" do
scenario "When path matches the friendly url" do
debate = create(:debate)
right_path = debate_path(debate)
visit right_path
expect(page).to have_current_path(right_path)
end
scenario "When path does not match the friendly url" do
debate = create(:debate)
right_path = debate_path(debate)
old_path = "#{debates_path}/#{debate.id}-something-else"
visit old_path
expect(page).not_to have_current_path(old_path)
expect(page).to have_current_path(right_path)
end
end
scenario "Show votes score on index and show" do
debate_positive = create(:debate, title: "Debate positive")
debate_zero = create(:debate, title: "Debate zero")
debate_negative = create(:debate, title: "Debate negative")
10.times { create(:vote, votable: debate_positive, vote_flag: true) }
3.times { create(:vote, votable: debate_positive, vote_flag: false) }
5.times { create(:vote, votable: debate_zero, vote_flag: true) }
5.times { create(:vote, votable: debate_zero, vote_flag: false) }
6.times { create(:vote, votable: debate_negative, vote_flag: false) }
visit debates_path
within "#debate_#{debate_positive.id}" do
expect(page).to have_content("7 votes")
end
within "#debate_#{debate_zero.id}" do
expect(page).to have_content("No votes")
end
within "#debate_#{debate_negative.id}" do
expect(page).to have_content("-6 votes")
end
visit debate_path(debate_positive)
expect(page).to have_content("7 votes")
visit debate_path(debate_zero)
expect(page).to have_content("No votes")
visit debate_path(debate_negative)
expect(page).to have_content("-6 votes")
end
scenario "Create", :js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "A title for a debate"
fill_in_ckeditor "Initial debate text", with: "This is very important because..."
check "debate_terms_of_service"
click_button "Start a debate"
expect(page).to have_content "A title for a debate"
expect(page).to have_content "Debate created successfully."
expect(page).to have_content "This is very important because..."
expect(page).to have_content author.name
expect(page).to have_content I18n.l(Debate.last.created_at.to_date)
end
scenario "Create with invisible_captcha honeypot field", :no_js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "I am a bot"
fill_in "debate_subtitle", with: "This is a honeypot field"
fill_in "Initial debate text", with: "This is the description"
check "debate_terms_of_service"
click_button "Start a debate"
expect(page.status_code).to eq(200)
expect(page.html).to be_empty
expect(page).to have_current_path(debates_path)
end
scenario "Create debate too fast", :js do
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "I am a bot"
fill_in_ckeditor "Initial debate text", with: "This is the description"
check "debate_terms_of_service"
click_button "Start a debate"
expect(page).to have_content "Sorry, that was too quick! Please resubmit"
expect(page).to have_current_path(new_debate_path)
end
scenario "Errors on create" do
author = create(:user)
login_as(author)
visit new_debate_path
click_button "Start a debate"
expect(page).to have_content error_message
end
scenario "JS injection is prevented but safe html is respected", :no_js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "Testing an attack"
fill_in "Initial debate text", with: "<p>This is <script>alert('an attack');</script></p>"
check "debate_terms_of_service"
click_button "Start a debate"
expect(page).to have_content "Debate created successfully."
expect(page).to have_content "Testing an attack"
expect(page.html).to include "<p>This is alert('an attack');</p>"
expect(page.html).not_to include "<script>alert('an attack');</script>"
expect(page.html).not_to include "<p>This is"
end
scenario "Autolinking is applied to description", :js do
author = create(:user)
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "Testing auto link"
fill_in_ckeditor "Initial debate text", with: "This is a link www.example.org"
check "debate_terms_of_service"
click_button "Start a debate"
expect(page).to have_content "Debate created successfully."
expect(page).to have_content "Testing auto link"
expect(page).to have_link("www.example.org", href: "http:https://www.example.org")
end
scenario "JS injection is prevented but autolinking is respected", :no_js do
author = create(:user)
js_injection_string = "<script>alert('hey')</script> <a href=\"javascript:alert('surprise!')\">click me<a/> http:https://example.org"
login_as(author)
visit new_debate_path
fill_in "Debate title", with: "Testing auto link"
fill_in "Initial debate text", with: js_injection_string
check "debate_terms_of_service"
click_button "Start a debate"
expect(page).to have_content "Debate created successfully."
expect(page).to have_content "Testing auto link"
expect(page).to have_link("http:https://example.org", href: "http:https://example.org")
expect(page).not_to have_link("click me")
expect(page.html).not_to include "<script>alert('hey')</script>"
click_link "Edit"
expect(page).to have_current_path(edit_debate_path(Debate.last))
expect(page).not_to have_link("click me")
expect(page.html).not_to include "<script>alert('hey')</script>"
end
scenario "Update should not be posible if logged user is not the author" do
debate = create(:debate)
expect(debate).to be_editable
login_as(create(:user))
visit edit_debate_path(debate)
expect(page).not_to have_current_path(edit_debate_path(debate))
expect(page).to have_current_path(root_path)
expect(page).to have_content "You do not have permission to carry out the action 'edit' on debate."
end
scenario "Update should not be posible if debate is not editable" do
Setting["max_votes_for_debate_edit"] = 2
debate = create(:debate, voters: Array.new(3) { create(:user) })
expect(debate).not_to be_editable
login_as(debate.author)
visit edit_debate_path(debate)
expect(page).not_to have_current_path(edit_debate_path(debate))
expect(page).to have_current_path(root_path)
expect(page).to have_content "You do not have permission to"
end
scenario "Update should be posible for the author of an editable debate", :js do
debate = create(:debate)
login_as(debate.author)
visit edit_debate_path(debate)
expect(page).to have_current_path(edit_debate_path(debate))
fill_in "Debate title", with: "End child poverty"
fill_in_ckeditor "Initial debate text", with: "Let's do something to end child poverty"
click_button "Save changes"
expect(page).to have_content "Debate updated successfully."
expect(page).to have_content "End child poverty"
expect(page).to have_content "Let's do something to end child poverty"
end
scenario "Errors on update" do
debate = create(:debate)
login_as(debate.author)
visit edit_debate_path(debate)
fill_in "Debate title", with: ""
click_button "Save changes"
expect(page).to have_content error_message
end
describe "Debate index order filters" do
scenario "Default order is hot_score", :js do
best_debate = create(:debate, title: "Best")
best_debate.update_column(:hot_score, 10)
worst_debate = create(:debate, title: "Worst")
worst_debate.update_column(:hot_score, 2)
medium_debate = create(:debate, title: "Medium")
medium_debate.update_column(:hot_score, 5)
visit debates_path
expect(best_debate.title).to appear_before(medium_debate.title)
expect(medium_debate.title).to appear_before(worst_debate.title)
end
scenario "Debates are ordered by confidence_score", :js do
best_debate = create(:debate, title: "Best")
best_debate.update_column(:confidence_score, 10)
worst_debate = create(:debate, title: "Worst")
worst_debate.update_column(:confidence_score, 2)
medium_debate = create(:debate, title: "Medium")
medium_debate.update_column(:confidence_score, 5)
visit debates_path
click_link "highest rated"
expect(page).to have_selector("a.is-active", text: "highest rated")
within "#debates" do
expect(best_debate.title).to appear_before(medium_debate.title)
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(page).to have_current_path(/order=confidence_score/)
expect(page).to have_current_path(/page=1/)
end
scenario "Debates are ordered by newest", :js do
best_debate = create(:debate, title: "Best", created_at: Time.current)
medium_debate = create(:debate, title: "Medium", created_at: Time.current - 1.hour)
worst_debate = create(:debate, title: "Worst", created_at: Time.current - 1.day)
visit debates_path
click_link "newest"
expect(page).to have_selector("a.is-active", text: "newest")
within "#debates" do
expect(best_debate.title).to appear_before(medium_debate.title)
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(page).to have_current_path(/order=created_at/)
expect(page).to have_current_path(/page=1/)
end
context "Recommendations" do
let!(:best_debate) { create(:debate, title: "Best", cached_votes_total: 10, tag_list: "Sport") }
let!(:medium_debate) { create(:debate, title: "Medium", cached_votes_total: 5, tag_list: "Sport") }
let!(:worst_debate) { create(:debate, title: "Worst", cached_votes_total: 1, tag_list: "Sport") }
scenario "can't be sorted if there's no logged user" do
visit debates_path
expect(page).not_to have_selector("a", text: "recommendations")
end
scenario "are shown on index header when account setting is enabled" do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user, followables: [proposal])
login_as(user)
visit debates_path
expect(page).to have_css(".recommendation", count: 3)
expect(page).to have_link "Best"
expect(page).to have_link "Medium"
expect(page).to have_link "Worst"
expect(page).to have_link "See more recommendations"
end
scenario "should display text when there are no results" do
proposal = create(:proposal, tag_list: "Distinct_to_sport")
user = create(:user, followables: [proposal])
login_as(user)
visit debates_path
click_link "recommendations"
expect(page).to have_content "There are no debates related to your interests"
end
scenario "should display text when user has no related interests" do
user = create(:user)
login_as(user)
visit debates_path
click_link "recommendations"
expect(page).to have_content "Follow proposals so we can give you recommendations"
end
scenario "can be sorted when there's a logged user" do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user, followables: [proposal])
login_as(user)
visit debates_path
click_link "recommendations"
expect(page).to have_selector("a.is-active", text: "recommendations")
within "#debates" do
expect(best_debate.title).to appear_before(medium_debate.title)
expect(medium_debate.title).to appear_before(worst_debate.title)
end
expect(page).to have_current_path(/order=recommendations/)
expect(page).to have_current_path(/page=1/)
end
scenario "are not shown if account setting is disabled" do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user, recommended_debates: false, followables: [proposal])
login_as(user)
visit debates_path
expect(page).not_to have_css(".recommendation", count: 3)
expect(page).not_to have_link("recommendations")
end
scenario "are automatically disabled when dismissed from index", :js do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user, followables: [proposal])
login_as(user)
visit debates_path
within("#recommendations") do
expect(page).to have_content("Best")
expect(page).to have_content("Worst")
expect(page).to have_content("Medium")
expect(page).to have_css(".recommendation", count: 3)
accept_confirm { click_link "Hide recommendations" }
end
expect(page).not_to have_link("recommendations")
expect(page).not_to have_css(".recommendation", count: 3)
expect(page).to have_content("Recommendations for debates are now disabled for this account")
user.reload
visit account_path
expect(find("#account_recommended_debates")).not_to be_checked
expect(user.recommended_debates).to be(false)
end
end
end
context "Search" do
context "Basic search" do
scenario "Search by text" do
debate1 = create(:debate, title: "Get Schwifty")
debate2 = create(:debate, title: "Schwifty Hello")
debate3 = create(:debate, title: "Do not show me")
visit debates_path
within(".expanded #search_form") do
fill_in "search", with: "Schwifty"
click_button "Search"
end
within("#debates") do
expect(page).to have_css(".debate", count: 2)
expect(page).to have_content(debate1.title)
expect(page).to have_content(debate2.title)
expect(page).not_to have_content(debate3.title)
end
end
scenario "Maintain search criteria" do
visit debates_path
within(".expanded #search_form") do
fill_in "search", with: "Schwifty"
click_button "Search"
end
expect(page).to have_selector("input[name='search'][value='Schwifty']")
end
end
scenario "Order by relevance by default", :js do
create(:debate, title: "Show you got", cached_votes_up: 10)
create(:debate, title: "Show what you got", cached_votes_up: 1)
create(:debate, title: "Show you got", cached_votes_up: 100)
visit debates_path
fill_in "search", with: "Show you got"
click_button "Search"
expect(page).to have_selector("a.is-active", text: "relevance")
within("#debates") do
expect(all(".debate")[0].text).to match "Show you got"
expect(all(".debate")[1].text).to match "Show you got"
expect(all(".debate")[2].text).to match "Show what you got"
end
end
scenario "Reorder results maintaing search", :js do
create(:debate, title: "Show you got", cached_votes_up: 10, created_at: 1.week.ago)
create(:debate, title: "Show what you got", cached_votes_up: 1, created_at: 1.month.ago)
create(:debate, title: "Show you got", cached_votes_up: 100, created_at: Time.current)
create(:debate, title: "Do not display", cached_votes_up: 1, created_at: 1.week.ago)
visit debates_path
fill_in "search", with: "Show you got"
click_button "Search"
click_link "newest"
expect(page).to have_selector("a.is-active", text: "newest")
within("#debates") do
expect(all(".debate")[0].text).to match "Show you got"
expect(all(".debate")[1].text).to match "Show you got"
expect(all(".debate")[2].text).to match "Show what you got"
expect(page).not_to have_content "Do not display"
end
end
scenario "Reorder by recommendations results maintaing search" do
proposal = create(:proposal, tag_list: "Sport")
user = create(:user, recommended_debates: true, followables: [proposal])
create(:debate, title: "Show you got", cached_votes_total: 10, tag_list: "Sport")
create(:debate, title: "Show what you got", cached_votes_total: 1, tag_list: "Sport")
create(:debate, title: "Do not display with same tag", cached_votes_total: 100, tag_list: "Sport")
create(:debate, title: "Do not display", cached_votes_total: 1)
login_as(user)
visit debates_path
fill_in "search", with: "Show you got"
click_button "Search"
click_link "recommendations"
expect(page).to have_selector("a.is-active", text: "recommendations")
within("#debates") do
expect(all(".debate")[0].text).to match "Show you got"
expect(all(".debate")[1].text).to match "Show what you got"
expect(page).not_to have_content "Do not display with same tag"
expect(page).not_to have_content "Do not display"
end
end
scenario "After a search do not show featured debates" do
create_featured_debates
create(:debate, title: "Abcdefghi")
visit debates_path
within(".expanded #search_form") do
fill_in "search", with: "Abcdefghi"
click_button "Search"
end
expect(page).not_to have_selector("#debates .debate-featured")
expect(page).not_to have_selector("#featured-debates")
end
end
scenario "Conflictive" do
good_debate = create(:debate)
conflictive_debate = create(:debate, :conflictive)
visit debate_path(conflictive_debate)
expect(page).to have_content "This debate has been flagged as inappropriate by several users."
visit debate_path(good_debate)
expect(page).not_to have_content "This debate has been flagged as inappropriate by several users."
end
scenario "Erased author" do
user = create(:user)
debate = create(:debate, author: user)
user.erase
visit debates_path
expect(page).to have_content("User deleted")
visit debate_path(debate)
expect(page).to have_content("User deleted")
end
context "Filter" do
context "By geozone" do
let(:california) { Geozone.create(name: "California") }
let(:new_york) { Geozone.create(name: "New York") }
before do
create(:debate, geozone: california, title: "Bigger sequoias")
create(:debate, geozone: california, title: "Green beach")
create(:debate, geozone: new_york, title: "Sully monument")
end
pending "From map" do
visit debates_path
click_link "map"
within("#html_map") do
url = find("area[title='California']")[:href]
visit url
end
within("#debates") do
expect(page).to have_css(".debate", count: 2)
expect(page).to have_content("Bigger sequoias")
expect(page).to have_content("Green beach")
expect(page).not_to have_content("Sully monument")
end
end
pending "From geozone list" do
visit debates_path
click_link "map"
within("#geozones") do
click_link "California"
end
within("#debates") do
expect(page).to have_css(".debate", count: 2)
expect(page).to have_content("Bigger sequoias")
expect(page).to have_content("Green beach")
expect(page).not_to have_content("Sully monument")
end
end
pending "From debate" do
debate = create(:debate, geozone: california, title: "Surf college")
visit debate_path(debate)
within("#geozone") do
click_link "California"
end
within("#debates") do
expect(page).to have_css(".debate", count: 3)
expect(page).to have_content("Surf college")
expect(page).to have_content("Bigger sequoias")
expect(page).to have_content("Green beach")
expect(page).not_to have_content("Sully monument")
end
end
end
end
context "Suggesting debates" do
scenario "Shows up to 5 suggestions", :js do
create(:debate, title: "First debate has 1 vote", cached_votes_up: 1)
create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
create(:debate, title: "Third debate has 3 votes", cached_votes_up: 3)
create(:debate, title: "This one has 4 votes", description: "This is the fourth debate", cached_votes_up: 4)
create(:debate, title: "Fifth debate has 5 votes", cached_votes_up: 5)
create(:debate, title: "Sixth debate has 6 votes", description: "This is the sixth debate", cached_votes_up: 6)
create(:debate, title: "This has seven votes, and is not suggest", description: "This is the seven", cached_votes_up: 7)
login_as(create(:user))
visit new_debate_path
fill_in "Debate title", with: "debate"
check "debate_terms_of_service"
within("div.js-suggest") do
expect(page).to have_content "You are seeing 5 of 6 debates containing the term 'debate'"
end
end
scenario "No found suggestions", :js do
create(:debate, title: "First debate has 10 vote", cached_votes_up: 10)
create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
login_as(create(:user))
visit new_debate_path
fill_in "Debate title", with: "proposal"
check "debate_terms_of_service"
within("div.js-suggest") do
expect(page).not_to have_content "You are seeing"
end
end
end
scenario "Mark/Unmark a debate as featured", :admin, :js do
debate = create(:debate)
visit debates_path
within("#debates") do
expect(page).not_to have_content "FEATURED"
end
click_link debate.title
accept_confirm { click_link "Featured" }
within("#debates") do
expect(page).to have_content "FEATURED"
end
within("#featured-debates") do
expect(page).to have_content debate.title
click_link debate.title
end
accept_confirm { click_link "Unmark featured" }
within("#debates") do
expect(page).not_to have_content "FEATURED"
end
end
scenario "Index include featured debates", :admin do
create(:debate, featured_at: Time.current)
create(:debate)
visit debates_path
within("#debates") do
expect(page).to have_content("Featured")
end
end
scenario "Index do not show featured debates if none is marked as featured", :admin do
create(:debate)
create(:debate)
visit debates_path
within("#debates") do
expect(page).not_to have_content("Featured")
end
end
describe "SDG related list" do
let(:user) { create(:user) }
before do
Setting["feature.sdg"] = true
Setting["sdg.process.debates"] = true
end
scenario "create debate with sdg related list", :js do
login_as(user)
visit new_debate_path
fill_in "Debate title", with: "A title for a debate related with SDG related content"
fill_in_ckeditor "Initial debate text", with: "This is very important because..."
click_sdg_goal(1)
check "debate_terms_of_service"
click_button "Start a debate"
within(".sdg-goal-tag-list") { expect(page).to have_link "1. No Poverty" }
end
scenario "edit debate with sdg related list", :js do
debate = create(:debate, author: user)
debate.sdg_goals = [SDG::Goal[1], SDG::Goal[2]]
login_as(user)
visit edit_debate_path(debate)
remove_sdg_goal_or_target_tag(1)
click_button "Save changes"
within(".sdg-goal-tag-list") do
expect(page).not_to have_link "1. No Poverty"
expect(page).to have_link "2. Zero Hunger"
end
end
end
end