bans: don't allow users to be double banned.
This commit is contained in:
@@ -4,10 +4,7 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
context "A bans controller" do
|
||||
setup do
|
||||
@mod = create(:moderator_user)
|
||||
@user = create(:user)
|
||||
as(@mod) do
|
||||
@ban = create(:ban, user: @user)
|
||||
end
|
||||
@ban = create(:ban)
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
@@ -40,7 +37,7 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "search action" do
|
||||
should "render" do
|
||||
get_auth bans_path(search: {user_name: @user.name}), @mod
|
||||
get_auth bans_path(search: { user_name: @ban.user.name }), @mod
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
@@ -48,6 +45,7 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "allow mods to ban members" do
|
||||
assert_difference("Ban.count", 1) do
|
||||
@user = create(:user)
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @user.id }}
|
||||
|
||||
assert_redirected_to bans_path
|
||||
@@ -77,12 +75,20 @@ class BansControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "not allow regular users to ban anyone" do
|
||||
assert_difference("Ban.count", 0) do
|
||||
@user = create(:user)
|
||||
post_auth bans_path, @user, params: { ban: { duration: 60, reason: "xxx", user_id: @mod.id }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal(false, @mod.reload.is_banned?)
|
||||
end
|
||||
end
|
||||
|
||||
should "not allow users to be double banned" do
|
||||
assert_difference("Ban.count", 0) do
|
||||
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @ban.user.id }}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
|
||||
Reference in New Issue
Block a user