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
8 changes: 4 additions & 4 deletions app/models/concerns/turbo/broadcastable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ def broadcast_refresh_to(*streamables, **attributes)
end

# Same as <tt>#broadcast_refresh_to</tt>, but the designated stream is automatically set to the current model.
def broadcast_refresh
broadcast_refresh_to self
def broadcast_refresh(**attributes)
broadcast_refresh_to self, **attributes
end

# Broadcast a named <tt>action</tt>, allowing for dynamic dispatch, instead of using the concrete action methods. Examples:
Expand Down Expand Up @@ -447,8 +447,8 @@ def broadcast_refresh_later_to(*streamables, **attributes)
end

# Same as <tt>#broadcast_refresh_later_to</tt>, but the designated stream is automatically set to the current model.
def broadcast_refresh_later
broadcast_refresh_later_to self
def broadcast_refresh_later(**attributes)
broadcast_refresh_later_to self, **attributes
end

# Same as <tt>broadcast_action_to</tt> but run asynchronously via a <tt>Turbo::Streams::BroadcastJob</tt>.
Expand Down
17 changes: 17 additions & 0 deletions test/streams/broadcastable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def to_partial_path
end
end

test "broadcasting refresh now forwards attributes" do
assert_broadcast_on @message.to_gid_param, turbo_stream_refresh_tag(method: :morph, scroll: :preserve) do
@message.broadcast_refresh method: :morph, scroll: :preserve
end
end

test "broadcasting refresh later is debounced" do
with_production_debouncer do
assert_broadcast_on @message.to_gid_param, turbo_stream_refresh_tag do
Expand All @@ -167,6 +173,17 @@ def to_partial_path
end
end

test "broadcasting refresh later forwards attributes" do
with_production_debouncer do
assert_broadcast_on @message.to_gid_param, turbo_stream_refresh_tag(method: :morph, scroll: :preserve) do
perform_enqueued_jobs do
@message.broadcast_refresh_later method: :morph, scroll: :preserve
Turbo::StreamsChannel.refresh_debouncer_for(@message).wait
end
end
end
end

test "broadcasting action to stream now" do
assert_broadcast_on "stream", turbo_stream_action_tag("prepend", target: "messages", template: render(@message)) do
@message.broadcast_action_to "stream", action: "prepend"
Expand Down