Skip to content
Merged
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/channels/turbo/streams/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def broadcast_prepend_to(*streamables, **opts)
broadcast_action_to(*streamables, action: :prepend, **opts)
end

def broadcast_refresh_to(*streamables, **opts)
broadcast_stream_to(*streamables, content: turbo_stream_refresh_tag)
def broadcast_refresh_to(*streamables, **attributes)
broadcast_stream_to(*streamables, content: turbo_stream_refresh_tag(**attributes))
end

def broadcast_action_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering)
Expand Down
8 changes: 4 additions & 4 deletions app/models/concerns/turbo/broadcastable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ def broadcast_prepend(target: broadcast_target_default, **rendering)
#
# # Sends <turbo-stream action="refresh"></turbo-stream> to the stream named "identity:2:clearances"
# clearance.broadcast_refresh_to examiner.identity, :clearances
def broadcast_refresh_to(*streamables)
Turbo::StreamsChannel.broadcast_refresh_to(*streamables) unless suppressed_turbo_broadcasts?
def broadcast_refresh_to(*streamables, **attributes)
Turbo::StreamsChannel.broadcast_refresh_to(*streamables, **attributes) unless suppressed_turbo_broadcasts?
end

# Same as <tt>#broadcast_refresh_to</tt>, but the designated stream is automatically set to the current model.
Expand Down Expand Up @@ -442,8 +442,8 @@ def broadcast_prepend_later(target: broadcast_target_default, **rendering)
end

# Same as <tt>broadcast_refresh_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
def broadcast_refresh_later_to(*streamables)
Turbo::StreamsChannel.broadcast_refresh_later_to(*streamables, request_id: Turbo.current_request_id) unless suppressed_turbo_broadcasts?
def broadcast_refresh_later_to(*streamables, **attributes)
Turbo::StreamsChannel.broadcast_refresh_later_to(*streamables, request_id: Turbo.current_request_id, **attributes) unless suppressed_turbo_broadcasts?
end

# Same as <tt>#broadcast_refresh_later_to</tt>, but the designated stream is automatically set to the current model.
Expand Down
16 changes: 16 additions & 0 deletions test/streams/streams_channel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ class Turbo::StreamsChannelTest < ActionCable::Channel::TestCase
end
end

test "broadcasting refresh now" do
Turbo.with_request_id("123") do
assert_broadcast_on "stream", turbo_stream_refresh_tag(request_id: nil) do
Turbo::StreamsChannel.broadcast_refresh_to "stream", request_id: nil
end

assert_broadcast_on "stream", turbo_stream_refresh_tag(request_id: "123") do
Turbo::StreamsChannel.broadcast_refresh_to "stream"
end

assert_broadcast_on "stream", turbo_stream_refresh_tag(request_id: "456", refresh: "morph") do
Turbo::StreamsChannel.broadcast_refresh_to "stream", request_id: "456", refresh: "morph"
end
end
end

test "broadcasting action now" do
options = { partial: "messages/message", locals: { message: "hello!" } }

Expand Down