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
This commit is contained in:
Jorge Manrubia
2025-11-10 13:08:29 +01:00
parent 63291ca0a2
commit b686936230
3 changed files with 13 additions and 1 deletions
+4
View File
@@ -7,5 +7,9 @@ module Card::Mentions
def mentionable?
published?
end
def should_check_mentions?
saved_change_to_status? && published?
end
end
end
+5 -1
View File
@@ -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
+4
View File
@@ -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