diff --git a/app/models/concerns/turbo/broadcastable.rb b/app/models/concerns/turbo/broadcastable.rb index f0476654..229eeb2f 100644 --- a/app/models/concerns/turbo/broadcastable.rb +++ b/app/models/concerns/turbo/broadcastable.rb @@ -383,8 +383,8 @@ def broadcast_refresh_to(*streamables, **attributes) end # Same as #broadcast_refresh_to, 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 action, allowing for dynamic dispatch, instead of using the concrete action methods. Examples: @@ -447,8 +447,8 @@ def broadcast_refresh_later_to(*streamables, **attributes) end # Same as #broadcast_refresh_later_to, 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 broadcast_action_to but run asynchronously via a Turbo::Streams::BroadcastJob. diff --git a/test/streams/broadcastable_test.rb b/test/streams/broadcastable_test.rb index 39b508ff..a3f095e5 100644 --- a/test/streams/broadcastable_test.rb +++ b/test/streams/broadcastable_test.rb @@ -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 @@ -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"