Merge pull request #1931 from basecamp/pin-card-refresh

Update pinned cards when the title changes
This commit is contained in:
Jorge Manrubia
2025-12-05 10:14:39 +01:00
committed by GitHub
5 changed files with 60 additions and 9 deletions
+11
View File
@@ -3,5 +3,16 @@ module Card::Broadcastable
included do
broadcasts_refreshes
before_update :remember_if_preview_changed
end
private
def remember_if_preview_changed
@preview_changed ||= title_changed? || column_id_changed? || board_id_changed?
end
def preview_changed?
@preview_changed
end
end
-5
View File
@@ -19,7 +19,6 @@ module Card::Eventable
def touch_last_active_at
# Not using touch so that we can detect attribute change on callbacks
update!(last_active_at: Time.current)
broadcast_activity
end
private
@@ -36,8 +35,4 @@ module Card::Eventable
def create_system_comment_for(event)
SystemCommenter.new(self, event).comment
end
def broadcast_activity
broadcast_render_later_to self, :activity, partial: "card/display/refresh_activity", locals: { card: self }
end
end
+9
View File
@@ -3,6 +3,8 @@ module Card::Pinnable
included do
has_many :pins, dependent: :destroy
after_update_commit :broadcast_pin_updates, if: :preview_changed?
end
def pinned_by?(user)
@@ -20,4 +22,11 @@ module Card::Pinnable
def unpin_by(user)
pins.find_by(user: user).tap { it.destroy }
end
private
def broadcast_pin_updates
pins.find_each do |pin|
pin.broadcast_replace_later_to [ pin.user, :pins_tray ], partial: "my/pins/pin"
end
end
end
@@ -1,4 +0,0 @@
<%= turbo_stream.remove dom_id(card, "bubble") %>
<%= turbo_stream.replace dom_id(card, :card_closure_toggle) do %>
<%= render "cards/container/closure", card: card %>
<% end %>
+40
View File
@@ -0,0 +1,40 @@
require "test_helper"
class Card::PinnableTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
end
test "broadcasts pin update when title changes" do
assert_broadcasted_pin_update do
cards(:logo).update!(title: "New title")
end
end
test "broadcasts pin update when column changes" do
assert_broadcasted_pin_update do
cards(:logo).update!(column: columns(:writebook_in_progress))
end
end
test "broadcasts pin update when board changes" do
assert_broadcasted_pin_update do
cards(:logo).update!(board: boards(:private), column: nil)
end
end
test "does not broadcast pin update when other properties change" do
perform_enqueued_jobs do
assert_turbo_stream_broadcasts([ pins(:logo_kevin).user, :pins_tray ], count: 0) do
cards(:logo).update!(last_active_at: Time.current)
end
end
end
private
def assert_broadcasted_pin_update(&block)
perform_enqueued_jobs do
assert_turbo_stream_broadcasts([ pins(:logo_kevin).user, :pins_tray ], &block)
end
end
end