Skip to content

Commit

Permalink
Make target and targets attributes optional for Stream actions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Sep 14, 2022
1 parent 50fb92f commit 7b0dc1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/turbo/streams/action_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions test/streams/action_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<turbo-stream action=\"my_custom_action\"><template></template></turbo-stream>", action
end
end

0 comments on commit 7b0dc1f

Please sign in to comment.