diff --git a/app/models/turbo/streams/tag_builder.rb b/app/models/turbo/streams/tag_builder.rb index 99a2aa47..b6032ab5 100644 --- a/app/models/turbo/streams/tag_builder.rb +++ b/app/models/turbo/streams/tag_builder.rb @@ -228,6 +228,18 @@ def prepend_all(targets, content = nil, **rendering, &block) action_all :prepend, targets, content, **rendering, &block end + # Creates a `turbo-stream` tag with an `[action="refresh"`] attribute and a + # `[request-id]` attribute that defaults to `Turbo.current_request_id`: + # + # turbo_stream.refresh + # # => + # + # turbo_stream.refresh request_id: "abc123" + # # => + def refresh(...) + turbo_stream_refresh_tag(...) + end + # Send an action of the type name to target. Options described in the concrete methods. def action(name, target, content = nil, allow_inferred_rendering: true, **rendering, &block) template = render_template(target, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block) diff --git a/test/streams/streams_helper_test.rb b/test/streams/streams_helper_test.rb index e8511dfb..1105cd57 100644 --- a/test/streams/streams_helper_test.rb +++ b/test/streams/streams_helper_test.rb @@ -35,6 +35,18 @@ class Turbo::StreamsHelperTest < ActionView::TestCase turbo_stream_from("messages", channel: "NonExistentChannel", data: {payload: 1}) end + test "turbo_stream.refresh" do + assert_dom_equal <<~HTML, turbo_stream.refresh + + HTML + assert_dom_equal <<~HTML, Turbo.with_request_id("abc123") { turbo_stream.refresh } + + HTML + assert_dom_equal <<~HTML, turbo_stream.refresh(request_id: "def456") + + HTML + end + test "custom turbo_stream builder actions" do assert_dom_equal <<~HTML.strip, turbo_stream.highlight("an-id")