Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support broadcast_remove_to with options #642

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/concerns/turbo/broadcastable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def suppressed_turbo_broadcasts?
#
# # Sends <turbo-stream action="remove" target="clearance_5"></turbo-stream> to the stream named "identity:2:clearances"
# clearance.broadcast_remove_to examiner.identity, :clearances
def broadcast_remove_to(*streamables, target: self)
Turbo::StreamsChannel.broadcast_remove_to(*streamables, target: target) unless suppressed_turbo_broadcasts?
def broadcast_remove_to(*streamables, **rendering)
Turbo::StreamsChannel.broadcast_remove_to(*streamables, target: self, **rendering) unless suppressed_turbo_broadcasts?
end

# Same as <tt>#broadcast_remove_to</tt>, but the designated stream is automatically set to the current model.
Expand Down
12 changes: 12 additions & 0 deletions test/streams/broadcastable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ class Turbo::BroadcastableTest < ActionCable::Channel::TestCase
end
end

test "broadcasting remove to stream now with a targets" do
assert_broadcast_on "stream", turbo_stream_action_tag("remove", target: 'message_1') do
@message.broadcast_remove_to "stream", target: 'message_1'
end
end

test "broadcasting remove to stream now with multiple targets" do
assert_broadcast_on "stream", turbo_stream_action_tag("remove", target: nil, targets: '.message_1') do
@message.broadcast_remove_to "stream", target: nil, targets: ".message_1"
end
end

test "broadcasting remove now" do
assert_broadcast_on @message.to_gid_param, turbo_stream_action_tag("remove", target: "message_1") do
@message.broadcast_remove
Expand Down
Loading