From 28d101eaa766907f800327fdb3af18e58188f7c1 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 7 Mar 2021 21:19:32 -0600 Subject: [PATCH] bans: fix exception when username is blank. Fix exception when submitting the ban form and the username is blank. --- app/models/ban.rb | 2 +- test/functional/bans_controller_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/ban.rb b/app/models/ban.rb index c641b4d5a..b1a23bf68 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -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 diff --git a/test/functional/bans_controller_test.rb b/test/functional/bans_controller_test.rb index f2168b420..26ef20f40 100644 --- a/test/functional/bans_controller_test.rb +++ b/test/functional/bans_controller_test.rb @@ -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