diff --git a/app/logical/concerns/mentionable.rb b/app/logical/concerns/mentionable.rb index fca768bec..71522378e 100644 --- a/app/logical/concerns/mentionable.rb +++ b/app/logical/concerns/mentionable.rb @@ -28,7 +28,7 @@ module Mentionable text_was = send(:attribute_before_last_save, message_field) names = DText.parse_mentions(text) - DText.parse_mentions(text_was) - users = names.map { |name| User.find_by_name(name) }.uniq + users = names.map { |name| User.find_by_name(name) }.compact.uniq users = users.without(CurrentUser.user) users.each do |user| diff --git a/test/unit/forum_post_test.rb b/test/unit/forum_post_test.rb index a6d6eb224..b9d0aec3e 100644 --- a/test/unit/forum_post_test.rb +++ b/test/unit/forum_post_test.rb @@ -66,6 +66,12 @@ class ForumPostTest < ActiveSupport::TestCase @forum_post = as(@user) { create(:forum_post, body: "hi from @#{@user.name}") } end end + + should "not fail when mentioning a nonexistent user" do + assert_no_difference("Dmail.count") do + @forum_post = as(@user) { create(:forum_post, body: "hi from @nonamethanks") } + end + end end context "that belongs to a topic with several pages of posts" do