diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 99006308e..9a39c0d47 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -46,6 +46,7 @@ module IconsHelper end def principal_icon(principal, **options) + return if principal.nil? raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal) principal_class = principal.class.name.downcase diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb index ab0b58db4..3917480e5 100644 --- a/test/helpers/icons_helper_test.rb +++ b/test/helpers/icons_helper_test.rb @@ -107,6 +107,10 @@ class IconsHelperTest < Redmine::HelperTest assert_nil principal_icon(Principal.find(1)) end + def test_principal_icon_should_not_raise_exception_for_nil + assert_nil principal_icon(nil) + end + def test_activity_event_type_icon_should_return_correct_icon_for_reply_events expected = %r{} assert_match expected, activity_event_type_icon('reply')