From 7b0dc1fc315edee5bf9f7c5fceb15b4bbb373af1 Mon Sep 17 00:00:00 2001 From: Marco Roth Date: Wed, 14 Sep 2022 21:29:50 +0200 Subject: [PATCH] Make `target` and `targets` attributes optional for Stream actions --- app/helpers/turbo/streams/action_helper.rb | 2 +- test/streams/action_helper_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/helpers/turbo/streams/action_helper.rb b/app/helpers/turbo/streams/action_helper.rb index 6718523f..e57e7ba9 100644 --- a/app/helpers/turbo/streams/action_helper.rb +++ b/app/helpers/turbo/streams/action_helper.rb @@ -19,7 +19,7 @@ def turbo_stream_action_tag(action, target: nil, targets: nil, template: nil, ** elsif targets = convert_to_turbo_stream_dom_id(targets, include_selector: true) tag.turbo_stream(template, **attributes.merge(action: action, targets: targets)) else - raise ArgumentError, "target or targets must be supplied" + tag.turbo_stream(template, **attributes.merge(action: action)) end end diff --git a/test/streams/action_helper_test.rb b/test/streams/action_helper_test.rb index 5be69664..59e503a3 100644 --- a/test/streams/action_helper_test.rb +++ b/test/streams/action_helper_test.rb @@ -63,4 +63,10 @@ class Turbo::ActionHelperTest < ActionCable::Channel::TestCase assert_equal stream, turbo_stream_action_tag("append", target: "message_1", template: "Template", class: { "stream": true, "another-stream": true, "no-stream": false }) end + + test "renders if no 'target' and no 'targets' attributes are provided" do + action = assert_nothing_raised { turbo_stream_action_tag("my_custom_action") } + + assert_equal "", action + end end