From b686936230494b52082dd7f304bedf80c5e4da73 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Mon, 10 Nov 2025 13:08:29 +0100 Subject: [PATCH] Fix: extract mentions when publishing cards This wasn't working when creation and publishing happened on separated instances of the same record, which is what happens when you edit a draft and then you publish it https://app.fizzy.do/5986089/cards/2835/edit --- app/models/card/mentions.rb | 4 ++++ app/models/concerns/mentions.rb | 6 +++++- test/models/concerns/mentions_test.rb | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/card/mentions.rb b/app/models/card/mentions.rb index cb3a34f17..3ce74726b 100644 --- a/app/models/card/mentions.rb +++ b/app/models/card/mentions.rb @@ -7,5 +7,9 @@ module Card::Mentions def mentionable? published? end + + def should_check_mentions? + saved_change_to_status? && published? + end end end diff --git a/app/models/concerns/mentions.rb b/app/models/concerns/mentions.rb index 055c114fc..a412fac69 100644 --- a/app/models/concerns/mentions.rb +++ b/app/models/concerns/mentions.rb @@ -49,7 +49,7 @@ module Mentions end def should_create_mentions? - mentionable? && mentionable_content_changed? + mentionable? && (mentionable_content_changed? || should_check_mentions?) end def mentionable_content_changed? @@ -64,4 +64,8 @@ module Mentions def mentionable? true end + + def should_check_mentions? + false + end end diff --git a/test/models/concerns/mentions_test.rb b/test/models/concerns/mentions_test.rb index d2edb073a..92cf95e1c 100644 --- a/test/models/concerns/mentions_test.rb +++ b/test/models/concerns/mentions_test.rb @@ -20,6 +20,8 @@ class MentionsTest < ActiveSupport::TestCase boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?" end + card = Card.find(card.id) + assert_difference -> { Mention.count }, +1 do card.published! end @@ -33,6 +35,8 @@ class MentionsTest < ActiveSupport::TestCase boards(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?" end + card = Card.find(card.id) + assert_difference -> { Mention.count }, +1 do card.published! end