diff --git a/app/models/concerns/mentions.rb b/app/models/concerns/mentions.rb index a412fac69..df8563ba3 100644 --- a/app/models/concerns/mentions.rb +++ b/app/models/concerns/mentions.rb @@ -19,20 +19,6 @@ module Mentions private def scan_mentionees - mentionees_from_plain_text | mentionees_from_rich_text - end - - def mentionees_from_plain_text - scan_mentioned_handles.filter_map do |mention| - mentionable_users.find { |user| user.mentionable_handles.include?(mention) } - end - end - - def scan_mentioned_handles - mentionable_content.scan(/(? { Mention.count } do perform_enqueued_jobs only: Mention::CreateJob do - card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" - card.update description: "Any thoughts here @jz" + card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{mention_html_for(users(:david))}?" + card.update description: "Any thoughts here #{mention_html_for(users(:jz))}" end end end @@ -17,7 +17,7 @@ class MentionsTest < ActiveSupport::TestCase test "create mentions from plain text mentions when publishing cards" do perform_enqueued_jobs only: Mention::CreateJob do card = assert_no_difference -> { Mention.count } do - boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" + boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{mention_html_for(users(:david))}?" end card = Card.find(card.id) @@ -31,8 +31,7 @@ class MentionsTest < ActiveSupport::TestCase test "create mentions from rich text mentions when publishing cards" do perform_enqueued_jobs only: Mention::CreateJob do card = assert_no_difference -> { Mention.count } do - attachment = ActionText::Attachment.from_attachable(users(:david)) - boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?" + boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{mention_html_for(users(:david))}?" end card = Card.find(card.id) @@ -45,18 +44,18 @@ class MentionsTest < ActiveSupport::TestCase test "don't create repeated mentions when updating cards" do perform_enqueued_jobs only: Mention::CreateJob do - card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" + card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{mention_html_for(users(:david))}?" assert_difference -> { Mention.count }, +1 do card.published! end assert_no_difference -> { Mention.count } do - card.update description: "Any thoughts here @david" + card.update description: "Any thoughts here #{mention_html_for(users(:david))}" end assert_difference -> { Mention.count }, +1 do - card.update description: "Any thoughts here @jz" + card.update description: "Any thoughts here #{mention_html_for(users(:jz))}" end end end @@ -66,7 +65,7 @@ class MentionsTest < ActiveSupport::TestCase card = boards(:writebook).cards.create title: "Cleanup", description: "Some initial content", status: :published assert_difference -> { Mention.count }, +1 do - card.comments.create!(body: "Great work on this @david!") + card.comments.create!(body: "Great work on this #{mention_html_for(users(:david))}!") end end end @@ -76,7 +75,7 @@ class MentionsTest < ActiveSupport::TestCase card = boards(:writebook).cards.create title: "Cleanup", description: "Some initial content" assert_no_difference -> { Mention.count } do - card.comments.create!(body: "Great work on this @david!") + card.comments.create!(body: "Great work on this #{mention_html_for(users(:david))}!") end end end @@ -87,17 +86,21 @@ class MentionsTest < ActiveSupport::TestCase assert_no_difference -> { Mention.count }, +1 do perform_enqueued_jobs only: Mention::CreateJob do - attachment = ActionText::Attachment.from_attachable(users(:david)) - boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?" + boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{mention_html_for(users(:david))}?" end end end test "mentionees are added as watchers of the card" do perform_enqueued_jobs only: Mention::CreateJob do - card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup @kevin?" + card = boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup #{mention_html_for(users(:kevin))}?" card.published! assert card.watchers.include?(users(:kevin)) end end + + private + def mention_html_for(user) + ActionText::Attachment.from_attachable(user).to_html + end end