diff --git a/lib/pretty_text/helpers.rb b/lib/pretty_text/helpers.rb index 09d7b1a31b9..54b33a27ea1 100644 --- a/lib/pretty_text/helpers.rb +++ b/lib/pretty_text/helpers.rb @@ -41,8 +41,8 @@ module PrettyText def mention_lookup(name) return false if name.blank? - return "group" if Group.exists?(name: name) return "user" if User.exists?(username_lower: name.downcase) + return "group" if Group.exists?(name: name) end def category_hashtag_lookup(category_slug) diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index dd68a554fca..adb4bec8fda 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -226,6 +226,14 @@ describe PrettyText do expect(PrettyText.cook("hi\n@sam.")).to eq("

hi
\n@sam.

") end + it "can handle group mention" do + group = Fabricate(:group) + + expect(PrettyText.cook("hi @#{group.name}! hi")).to match_html( + %Q{

hi @#{group.name}! hi

} + ) + end + it "can handle mentions inside a hyperlink" do expect(PrettyText.cook(" @inner ")).to match_html '

@inner

' end