Skip to content

Commit f95bc96

Browse files
committed
Tests de contrôleurs à peu près completes, et propres
1 parent 88073de commit f95bc96

File tree

57 files changed

+460
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+460
-394
lines changed

test/controllers/admin/accounts_controller_test.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class Admin::AccountsControllerTest < ActionDispatch::IntegrationTest
1010
test 'should not list accounts' do
1111
sign_in accounts 'visitor_0'
1212
get admin_accounts_url
13+
1314
assert_redirected_to account_session_url
1415
end
1516

1617
test 'should list accounts' do
1718
get admin_accounts_url
19+
1820
assert_response :success
1921
end
2022

@@ -26,33 +28,41 @@ class Admin::AccountsControllerTest < ActionDispatch::IntegrationTest
2628
2729
inactive: '1'
2830
}
31+
2932
assert_response :success
3033
end
3134

3235
test 'should send password reset' do
3336
post password_admin_account_url(accounts(:anonymous))
37+
3438
assert_redirected_to admin_accounts_url
3539
end
3640

3741
test 'should give karma' do
3842
post karma_admin_account_url(accounts(:anonymous))
43+
3944
assert_redirected_to accounts(:anonymous).user
4045
end
4146

42-
test 'should activate/inactivate account' do
47+
test 'should activate account' do
4348
patch admin_account_url accounts(:anonymous)
49+
4450
assert_nil flash[:alert]
4551
assert_equal 'Compte réactivé', flash[:notice]
4652
assert_redirected_to admin_accounts_url
53+
end
54+
55+
test 'should inactivate account' do
56+
patch admin_account_url accounts('visitor_999')
4757

48-
patch admin_account_url accounts(:anonymous)
4958
assert_nil flash[:alert]
5059
assert_equal 'Compte désactivé', flash[:notice]
5160
assert_redirected_to admin_accounts_url
5261
end
5362

5463
test 'should destroy account' do
5564
delete admin_account_url(accounts(:anonymous))
65+
5666
assert_redirected_to admin_accounts_url
5767
end
5868
end

test/controllers/admin/admins_controller_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class Admin::AdminsControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should create admin' do
1111
post admin_account_admin_url(accounts('visitor_0'))
12+
1213
assert_nil flash[:alert]
1314
assert flash[:notice]
1415
assert_redirected_to accounts('visitor_0').user
1516
end
1617

1718
test 'should destroy admin' do
1819
delete admin_account_admin_url(accounts('admin_0'))
20+
1921
assert_nil flash[:alert]
2022
assert flash[:notice]
2123
assert_redirected_to accounts('admin_0').user

test/controllers/admin/applications_controller_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class Admin::ApplicationsControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should list applications' do
1111
get admin_applications_url
12+
1213
assert_response :success
1314
end
1415

1516
test 'should not update application' do
1617
patch admin_application_url(Doorkeeper::Application.first), params: {
1718
doorkeeper_application: { name: 'New name' }
1819
}
20+
1921
assert_response :success
2022
end
2123

@@ -27,6 +29,7 @@ class Admin::ApplicationsControllerTest < ActionDispatch::IntegrationTest
2729
patch admin_application_url(app), params: {
2830
doorkeeper_application: { name: 'New name' }
2931
}
32+
3033
assert_nil flash[:alert]
3134
assert flash[:notice]
3235
assert_redirected_to admin_applications_url

test/controllers/admin/banners_controller_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ class Admin::BannersControllerTest < ActionDispatch::IntegrationTest
77
sign_in accounts 'admin_0'
88
end
99

10+
teardown do
11+
# Reset
12+
$redis.del('banners')
13+
end
14+
1015
test 'should list banners' do
1116
get admin_banners_url
17+
1218
assert_response :success
1319
end
1420

1521
test 'should get new' do
1622
get new_admin_banner_url
23+
1724
assert_response :success
1825
end
1926

@@ -46,6 +53,7 @@ class Admin::BannersControllerTest < ActionDispatch::IntegrationTest
4653

4754
test 'should edit banner' do
4855
get edit_admin_banner_url(banners(:one))
56+
4957
assert_response :success
5058
end
5159

@@ -71,6 +79,7 @@ class Admin::BannersControllerTest < ActionDispatch::IntegrationTest
7179
content: 'This is a banner'
7280
}
7381
}
82+
7483
assert_redirected_to admin_banners_url
7584
end
7685

test/controllers/admin/categories_controller_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class Admin::CategoriesControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should list categories' do
1111
get admin_categories_url
12+
1213
assert_response :success
1314
end
1415

1516
test 'should get new' do
1617
get new_admin_category_url
18+
1719
assert_response :success
1820
end
1921

@@ -22,6 +24,7 @@ class Admin::CategoriesControllerTest < ActionDispatch::IntegrationTest
2224
post admin_categories_url, params: {
2325
category: { title: '' }
2426
}
27+
2528
assert flash[:alert]
2629
end
2730
assert_response :success
@@ -32,20 +35,23 @@ class Admin::CategoriesControllerTest < ActionDispatch::IntegrationTest
3235
post admin_categories_url, params: {
3336
category: { title: 'Hello world' }
3437
}
38+
3539
assert_nil flash[:alert]
3640
end
3741
assert_redirected_to admin_categories_url
3842
end
3943

4044
test 'should get edit' do
4145
get edit_admin_category_url(categories(:one))
46+
4247
assert_response :success
4348
end
4449

4550
test 'should not update category' do
4651
patch admin_category_url(categories(:one)), params: {
4752
category: { title: '' }
4853
}
54+
4955
assert flash[:alert]
5056
assert_response :success
5157
end
@@ -54,13 +60,15 @@ class Admin::CategoriesControllerTest < ActionDispatch::IntegrationTest
5460
patch admin_category_url(categories(:one)), params: {
5561
category: { title: 'Hello world' }
5662
}
63+
5764
assert_nil flash[:alert]
5865
assert_redirected_to admin_categories_url
5966
end
6067

6168
test 'should destroy category' do
6269
assert_difference('Category.count', -1) do
6370
delete admin_category_url(categories(:two))
71+
6472
assert_nil flash[:alert]
6573
end
6674
assert_redirected_to admin_categories_url

test/controllers/admin/editors_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Admin::EditorsControllerTest < ActionDispatch::IntegrationTest
1010
test 'should authorize editor' do
1111
assert_difference 'Account.editor.count' do
1212
post admin_account_editor_url accounts('visitor_0')
13-
assert_nil flash[:alert]
13+
1414
assert flash[:notice]
1515
end
1616
assert_redirected_to accounts('visitor_0').user
@@ -19,7 +19,7 @@ class Admin::EditorsControllerTest < ActionDispatch::IntegrationTest
1919
test 'should destroy editor' do
2020
assert_difference 'Account.editor.count', -1 do
2121
delete admin_account_editor_url accounts('editor_0')
22-
assert_nil flash[:alert]
22+
2323
assert flash[:notice]
2424
end
2525
assert_redirected_to accounts('editor_0').user

test/controllers/admin/forums_controller_test.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class Admin::ForumsControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should list forums' do
1111
get admin_forums_url
12+
1213
assert_response :success
1314
end
1415

1516
test 'should get new' do
1617
get new_admin_forum_url
18+
1719
assert_response :success
1820
end
1921

@@ -34,45 +36,47 @@ class Admin::ForumsControllerTest < ActionDispatch::IntegrationTest
3436
cached_slug: 'hello-world'
3537
}
3638
}
37-
assert_nil flash[:alert]
39+
3840
assert flash[:notice]
3941
end
4042
assert_redirected_to admin_forums_url
4143
end
4244

4345
test 'should get edit' do
4446
get edit_admin_forum_url(forums(:one))
47+
4548
assert_response :success
4649
end
4750

4851
test 'should not update forum' do
4952
patch admin_forum_url(forums(:one)), params: {
5053
forum: { title: '' }
5154
}
55+
5256
assert_response :success
5357
end
5458

5559
test 'should update forum' do
5660
patch admin_forum_url(forums(:one)), params: {
5761
forum: { title: 'Hello world' }
5862
}
59-
assert_nil flash[:alert]
63+
6064
assert flash[:notice]
6165
assert_redirected_to admin_forums_url
6266
end
6367

6468
test 'should archive forum' do
6569
assert_difference 'Forum.active.count', -1 do
6670
post archive_admin_forum_url(forums(:one))
67-
assert_nil flash[:alert]
71+
6872
assert flash[:notice]
6973
end
7074
assert_redirected_to admin_forums_url
7175
end
7276

7377
test 'should reopen forum' do
7478
post reopen_admin_forum_url(forums(:one))
75-
assert_nil flash[:alert]
79+
7680
assert flash[:notice]
7781

7882
assert_redirected_to admin_forums_url
@@ -81,7 +85,7 @@ class Admin::ForumsControllerTest < ActionDispatch::IntegrationTest
8185
test 'should destroy forum' do
8286
assert_difference 'Forum.count', -1 do
8387
delete admin_forum_url(forums(:two))
84-
assert_nil flash[:alert]
88+
8589
assert flash[:notice]
8690
end
8791
assert_redirected_to admin_forums_url

test/controllers/admin/friend_sites_controller_test.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ class FriendSitesControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should list friend sites' do
1111
get admin_friend_sites_url
12+
1213
assert_response :success
1314
end
1415

1516
test 'should get new' do
1617
get new_admin_friend_site_url
18+
1719
assert_response :success
1820
end
1921

@@ -25,7 +27,7 @@ class FriendSitesControllerTest < ActionDispatch::IntegrationTest
2527
url: 'http://example.com'
2628
}
2729
}
28-
assert_nil flash[:alert]
30+
2931
assert flash[:notice]
3032
end
3133
assert_response :redirect
@@ -38,14 +40,15 @@ class FriendSitesControllerTest < ActionDispatch::IntegrationTest
3840
url: 'http://example.com'
3941
}
4042
}
43+
4144
assert flash[:alert]
42-
assert_nil flash[:notice]
4345
end
4446
assert_response :success
4547
end
4648

4749
test 'should get edit' do
4850
get edit_admin_friend_site_url(friend_sites(:one))
51+
4952
assert_response :success
5053
end
5154

@@ -56,7 +59,7 @@ class FriendSitesControllerTest < ActionDispatch::IntegrationTest
5659
url: 'http://example.com'
5760
}
5861
}
59-
assert_nil flash[:alert]
62+
6063
assert flash[:notice]
6164
assert_response :redirect
6265
end
@@ -67,35 +70,35 @@ class FriendSitesControllerTest < ActionDispatch::IntegrationTest
6770
title: ''
6871
}
6972
}
73+
7074
assert flash[:alert]
71-
assert_nil flash[:notice]
7275
assert_response :success
7376
end
7477

7578
test 'should destroy friend site' do
7679
assert_difference('FriendSite.count', -1) do
7780
delete admin_friend_site_url(friend_sites(:one))
81+
82+
assert flash[:notice]
7883
end
79-
assert_nil flash[:alert]
80-
assert flash[:notice]
8184
assert_response :redirect
8285
end
8386

8487
test 'should lower friend site' do
8588
assert_difference('friend_sites(:one).reload.position') do
8689
post lower_admin_friend_site_url(friend_sites(:one))
90+
91+
assert_nil flash[:alert]
8792
end
88-
assert_nil flash[:alert]
89-
assert_nil flash[:notice]
9093
assert_response :redirect
9194
end
9295

9396
test 'should higher friend site' do
9497
assert_no_difference('friend_sites(:one).position') do
9598
post higher_admin_friend_site_url(friend_sites(:one))
99+
100+
assert_nil flash[:alert]
96101
end
97-
assert_nil flash[:alert]
98-
assert_nil flash[:notice]
99102
assert_response :redirect
100103
end
101104
end

test/controllers/admin/logos_controller_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ class Admin::LogosControllerTest < ActionDispatch::IntegrationTest
99

1010
test 'should show logo' do
1111
get admin_logo_url
12+
1213
assert_response :success
1314
end
1415

1516
test 'should create logo' do
1617
post admin_logo_url, params: {
1718
logo: fixture_file_upload('Logo.png', 'image/png')
1819
}
20+
1921
assert flash[:notice]
2022
assert_redirected_to admin_logo_url
2123
end

0 commit comments

Comments
 (0)