Move comment events when card moves to a new board (#2486)

When a card moves between boards, comment events were staying on the
old board. Now they move with the card.
This commit is contained in:
Mike Dalessio
2026-02-04 15:04:28 -05:00
committed by GitHub
parent d032f88c59
commit d611b2cc6c
2 changed files with 15 additions and 10 deletions
+1
View File
@@ -58,6 +58,7 @@ class Card < ApplicationRecord
transaction do transaction do
card.update!(board: new_board) card.update!(board: new_board)
card.events.update_all(board_id: new_board.id) card.events.update_all(board_id: new_board.id)
Event.where(eventable: card.comments).update_all(board_id: new_board.id)
end end
end end
+14 -10
View File
@@ -128,25 +128,29 @@ class CardTest < ActiveSupport::TestCase
test "move cards to a different board" do test "move cards to a different board" do
card = cards(:logo) card = cards(:logo)
old_board = boards(:writebook) old_board = card.board
new_board = boards(:private) new_board = boards(:private)
assert_equal old_board, card.board card.comments.create!(body: "Sensitive information", creator: users(:david))
assert card.events.where(board: old_board).exists? card_events_on_old_board = card.events.where(board: old_board)
comment_events_on_old_board = Event.where(board: old_board, eventable: card.comments)
assert card_events_on_old_board.exists?
assert comment_events_on_old_board.exists?
card.move_to(new_board) card.move_to(new_board)
assert_equal new_board, card.reload.board assert_equal new_board, card.reload.board
events_in_old_board = card.events.where(board: old_board) card_events_on_new_board = card.events.where(board: new_board)
events_in_new_board = card.events.where(board: new_board) comment_events_on_new_board = Event.where(board: new_board, eventable: card.comments)
assert_empty events_in_old_board assert_empty card_events_on_old_board
assert events_in_new_board.exists? assert_empty comment_events_on_old_board
assert card_events_on_new_board.exists?
board_changed_event = events_in_new_board.find { |event| event.action == "card_board_changed" } assert comment_events_on_new_board.exists?
assert board_changed_event assert card_events_on_new_board.find_by(action: "card_board_changed")
end end
test "a card is filled if it has either the title or the description set" do test "a card is filled if it has either the title or the description set" do