Skip to content

Commit 31c0767

Browse files
committed
Plus de tests, les contrôleurs sont testés à plus de 99%
Il manque les contrôleurs d'API dans cette couverture...
1 parent 2cebe59 commit 31c0767

20 files changed

+393
-15
lines changed

test/controllers/bookmarks_controller_test.rb

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ class BookmarksControllerTest < ActionDispatch::IntegrationTest
1515
assert_nil flash[:alert]
1616
end
1717

18+
test 'should not find bookmark' do
19+
get user_bookmark_url(users('visitor_1'), bookmarks(:one), format: :html)
20+
assert_redirected_to user_bookmark_url(users('visitor_0'), Bookmark.last)
21+
end
22+
1823
test 'should get new' do
19-
sign_in accounts 'maintainer_0'
24+
sign_in accounts 'visitor_0'
2025
get new_bookmark_url
2126
assert_response :success
2227
end
2328

2429
test 'should preview bookmark' do
25-
sign_in accounts 'maintainer_0'
30+
sign_in accounts 'visitor_0'
2631
assert_no_difference('Bookmark.count') do
2732
post bookmarks_url,
2833
params: {
@@ -38,7 +43,7 @@ class BookmarksControllerTest < ActionDispatch::IntegrationTest
3843
end
3944

4045
test 'should create bookmark' do
41-
sign_in accounts 'maintainer_0'
46+
sign_in accounts 'visitor_0'
4247
assert_difference('Bookmark.count') do
4348
post bookmarks_url,
4449
params: {
@@ -50,7 +55,7 @@ class BookmarksControllerTest < ActionDispatch::IntegrationTest
5055
tags: 'foo, bar'
5156
}
5257
end
53-
assert_redirected_to user_bookmark_url(users('maintainer_0'), Bookmark.last)
58+
assert_redirected_to user_bookmark_url(users('visitor_0'), Bookmark.last)
5459
end
5560

5661
test 'should get edit' do
@@ -59,6 +64,18 @@ class BookmarksControllerTest < ActionDispatch::IntegrationTest
5964
assert_response :success
6065
end
6166

67+
test 'should preview update' do
68+
sign_in accounts 'admin_0'
69+
patch user_bookmark_url(users('visitor_0'), bookmarks(:one)),
70+
params: {
71+
bookmark: {
72+
link: 'http://example.com'
73+
},
74+
commit: 'Prévisualiser'
75+
}
76+
assert_response :success
77+
end
78+
6279
test 'should update bookmark' do
6380
sign_in accounts 'admin_0'
6481
patch user_bookmark_url(users('visitor_0'), bookmarks(:one)),
@@ -70,6 +87,17 @@ class BookmarksControllerTest < ActionDispatch::IntegrationTest
7087
assert_redirected_to user_bookmark_url(users('visitor_0'), bookmarks(:one))
7188
end
7289

90+
test 'should not update bookmark' do
91+
sign_in accounts 'admin_0'
92+
patch user_bookmark_url(users('visitor_0'), bookmarks(:one)),
93+
params: {
94+
bookmark: {
95+
title: ''
96+
}
97+
}
98+
assert_response :success
99+
end
100+
73101
test 'should destroy bookmark' do
74102
sign_in accounts 'admin_0'
75103
delete user_bookmark_url(users('visitor_0'), bookmarks(:one))

test/controllers/home_controller_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class HomeControllerTest < ActionDispatch::IntegrationTest
99

1010
get root_url
1111
assert_response :success
12+
13+
assert_select 'title', 'Accueil - LinuxFr.org'
14+
15+
post destroy_account_session_url
1216
end
1317

1418
test 'should not login' do

test/controllers/moderation/news_controller_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ class Moderation::NewsControllerTest < ActionDispatch::IntegrationTest
5757
assert_redirected_to moderation_news_url news(:candidate)
5858
end
5959

60+
test 'should not accept empty news' do
61+
sign_in accounts 'admin_0'
62+
63+
news(:first_part_only).paragraphs << Paragraph.new(wiki_body: News::DEFAULT_PARAGRAPH)
64+
65+
assert_no_difference 'News.candidate.count' do
66+
post accept_moderation_news_url news(:first_part_only)
67+
assert flash[:alert]
68+
end
69+
assert_redirected_to moderation_news_url news(:first_part_only)
70+
end
71+
6072
test 'should accept news' do
6173
sign_in accounts 'admin_0'
74+
6275
assert_difference 'News.candidate.count', -1 do
6376
post accept_moderation_news_url news(:candidate)
6477
assert flash[:alert]
Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,74 @@
11
require 'test_helper'
22

33
class Moderation::PollControllerTest < ActionDispatch::IntegrationTest
4-
# Replace this with your real tests.
5-
test 'the truth' do
6-
assert true
4+
include Devise::Test::IntegrationHelpers
5+
6+
setup do
7+
sign_in accounts 'moderator_0'
8+
end
9+
10+
test 'should list polls' do
11+
get moderation_polls_url
12+
assert_response :success
13+
end
14+
15+
test 'should show poll' do
16+
comments(:poll_2).parent_id = comments(:poll).id
17+
comments(:poll_2).generate_materialized_path
18+
get moderation_poll_url(polls(:one))
19+
assert_response :success
20+
end
21+
22+
test 'should accept poll' do
23+
# For information, there can only be one published poll!
24+
assert_difference('Poll.draft.count', -1) do
25+
post accept_moderation_poll_url(polls(:draft))
26+
assert_nil flash[:alert]
27+
assert flash[:notice]
28+
end
29+
assert_redirected_to poll_url polls(:draft)
30+
end
31+
32+
test 'should refuse poll' do
33+
assert_difference('Poll.draft.count', -1) do
34+
post refuse_moderation_poll_url(polls(:draft))
35+
assert_nil flash[:alert]
36+
assert flash[:notice]
37+
end
38+
assert_redirected_to moderation_polls_url
39+
end
40+
41+
test 'should get edit' do
42+
get edit_moderation_poll_url(polls(:one))
43+
assert_response :success
44+
end
45+
46+
test 'should update poll' do
47+
patch moderation_poll_url(polls(:one)), params: {
48+
poll: {
49+
title: 'hello world my poll'
50+
}
51+
}
52+
assert_nil flash[:alert]
53+
assert flash[:notice]
54+
assert_redirected_to moderation_poll_url(polls(:one).reload)
55+
end
56+
57+
test 'should not update poll' do
58+
patch moderation_poll_url(polls(:one)), params: {
59+
poll: {
60+
title: ''
61+
}
62+
}
63+
assert flash[:alert]
64+
assert_nil flash[:notice]
65+
assert_response :success
66+
end
67+
68+
test 'should set poll on ppp' do
69+
post ppp_moderation_poll_url(polls(:one))
70+
assert_nil flash[:alert]
71+
assert flash[:notice]
72+
assert_redirected_to root_url
773
end
874
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'test_helper'
2+
3+
class Moderation::TagsControllerTest < ActionDispatch::IntegrationTest
4+
include Devise::Test::IntegrationHelpers
5+
6+
setup do
7+
sign_in accounts 'moderator_0'
8+
end
9+
10+
test 'should list tags' do
11+
get moderation_tags_url
12+
assert_response :success
13+
end
14+
end

test/controllers/posts_controller_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
1313
assert_response :success
1414
end
1515

16+
test 'should show post when logged in' do
17+
sign_in accounts 'visitor_0'
18+
get forum_post_url(forums(:one), posts(:one))
19+
assert_response :success
20+
end
21+
22+
test 'should show post from another forum' do
23+
get forum_post_url(forums(:two), posts(:one))
24+
assert_redirected_to forum_post_url forums(:one), posts(:one)
25+
end
26+
1627
test 'should get new page' do
1728
sign_in accounts 'maintainer_0'
1829
get new_post_url forums(:one)

test/controllers/redaction/links_controller_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,34 @@ def setup
3232
assert_response :success
3333
end
3434

35+
test 'should not create link' do
36+
assert_no_difference 'Link.count' do
37+
post redaction_links_url params: {
38+
link: {
39+
lang: 'fr',
40+
url: 'https://linuxfr.org'
41+
},
42+
news_id: news(:news).id
43+
}
44+
end
45+
assert_response :unprocessable_entity
46+
end
47+
3548
test 'should get edit' do
3649
get edit_redaction_link_url links(:one)
3750
assert_response :success
3851
end
3952

53+
test 'should not get edit' do
54+
get edit_redaction_link_url links(:one)
55+
56+
sign_in accounts 'moderator_0'
57+
get edit_redaction_link_url links(:one)
58+
assert_response :forbidden
59+
60+
post unlock_redaction_link_url links(:one)
61+
end
62+
4063
test 'should update link' do
4164
patch redaction_link_url links(:one), params: {
4265
link: {
@@ -48,6 +71,17 @@ def setup
4871
assert_response :success
4972
end
5073

74+
test 'should not update link' do
75+
patch redaction_link_url links(:one), params: {
76+
link: {
77+
lang: 'fr',
78+
title: '',
79+
url: 'https://linuxfr.org'
80+
}
81+
}
82+
assert_response :unprocessable_entity
83+
end
84+
5185
test 'should unlock link' do
5286
post unlock_redaction_link_url links(:one)
5387
assert_response :no_content

test/controllers/redaction/news_controller_test.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ class Redaction::NewsControllerTest < ActionDispatch::IntegrationTest
7070
end
7171

7272
test 'should get reorganize news page' do
73-
sign_in accounts 'admin_0'
7473
get reorganize_redaction_news_url news(:draft)
7574
assert_nil flash[:alert]
7675
assert_response :success
76+
77+
sign_in accounts 'visitor_1'
78+
get reorganize_redaction_news_url news(:draft)
79+
assert_response :forbidden
7780
end
7881

7982
test 'should reorganize news' do
@@ -83,7 +86,16 @@ class Redaction::NewsControllerTest < ActionDispatch::IntegrationTest
8386
}
8487
}
8588
assert_nil flash[:alert]
86-
assert_redirected_to redaction_news_url News.draft.last
89+
assert_redirected_to redaction_news_url news(:draft).reload
90+
end
91+
92+
test 'should not reorganize news' do
93+
put reorganized_redaction_news_url news(:draft), params: {
94+
news: {
95+
title: ''
96+
}
97+
}
98+
assert_response :success
8799
end
88100

89101
test 'should get revision' do
@@ -105,7 +117,7 @@ class Redaction::NewsControllerTest < ActionDispatch::IntegrationTest
105117
message: 'Hello world'
106118
}
107119
assert_nil flash[:alert]
108-
assert_redirected_to redaction_news_url News.draft.last
120+
assert_redirected_to redaction_news_url news(:draft).reload
109121
end
110122

111123
test 'should submit news' do
@@ -123,6 +135,15 @@ class Redaction::NewsControllerTest < ActionDispatch::IntegrationTest
123135
assert_redirected_to redaction_url
124136
end
125137

138+
test 'should not submit news' do
139+
# To lock the news
140+
get reorganize_redaction_news_url news(:draft)
141+
142+
post submit_redaction_news_url news(:draft).id
143+
assert flash[:alert]
144+
assert_redirected_to redaction_news_url news(:draft)
145+
end
146+
126147
test 'should erase news' do
127148
sign_in accounts 'admin_0'
128149
assert_difference('News.draft.count', -1) do

test/controllers/redaction/paragraphs_controller_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Moderation::ParagraphsControllerTest < ActionDispatch::IntegrationTest
2525
end
2626

2727
assert_response :created
28+
29+
assert_difference 'Paragraph.count' do
30+
post redaction_news_paragraphs_url news(:first_part_only)
31+
assert_nil flash[:alert]
32+
assert_equal 1, news(:first_part_only).paragraphs.in_first_part.count
33+
assert_equal 0, news(:first_part_only).paragraphs.in_second_part.count
34+
end
35+
36+
assert_response :created
2837
end
2938

3039
test 'should show paragraph' do
@@ -35,6 +44,10 @@ class Moderation::ParagraphsControllerTest < ActionDispatch::IntegrationTest
3544
test 'should edit paragraph' do
3645
get edit_redaction_paragraph_url paragraphs(:one)
3746
assert_response :success
47+
48+
sign_in accounts 'moderator_1'
49+
get edit_redaction_paragraph_url paragraphs(:one)
50+
assert_response :forbidden
3851
end
3952

4053
test 'should update paragraph' do

test/controllers/static_controller_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ class StaticControllerTest < ActionDispatch::IntegrationTest
66
assert_response :success
77
end
88

9+
test 'should get equipe page' do
10+
pages(:equipe).body = File.read('db/pages/equipe.html')
11+
pages(:equipe).save!
12+
13+
get static_url pages(:equipe)
14+
assert_response :success
15+
end
16+
17+
test 'should get sites amis' do
18+
pages(:amis).body = File.read('db/pages/sites-amis.html')
19+
pages(:amis).save!
20+
21+
get static_url pages(:amis)
22+
assert_response :success
23+
end
24+
25+
test 'should get règles de modération' do
26+
pages(:moderation).body = File.read('db/pages/regles_de_moderation.html')
27+
pages(:moderation).save!
28+
29+
get static_url pages(:moderation)
30+
assert_response :success
31+
end
32+
933
test 'get changelog' do
1034
get changelog_url pages(:one)
1135
assert_response :success

0 commit comments

Comments
 (0)