bans: fix exception when username is blank.

Fix exception when submitting the ban form and the username is blank.
This commit is contained in:
evazion
2021-03-07 21:19:32 -06:00
parent 5b37ac3adb
commit 28d101eaa7
2 changed files with 6 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ class Ban < ApplicationRecord
end
def validate_user_is_bannable
errors.add(:user, "is already banned") if user.is_banned?
errors.add(:user, "is already banned") if user&.is_banned?
end
def update_user_on_create

View File

@@ -100,6 +100,11 @@ class BansControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
end
should "not raise an exception on a blank username" do
post_auth bans_path, @mod, params: {}
assert_response :success
end
end
context "update action" do