Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty streamable array #528

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions app/channels/turbo/streams/stream_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def verified_stream_name_from_params
private
def stream_name_from(streamables)
if streamables.is_a?(Array)
if streamables.compact_blank.empty?
raise ArgumentError, "At least one streamable must be provided. You passed #{streamables.inspect}"
end
streamables.map { |streamable| stream_name_from(streamable) }.join(":")
else
streamables.then { |streamable| streamable.try(:to_gid_param) || streamable.to_param }
Expand Down
8 changes: 8 additions & 0 deletions test/broadcastable/test_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class Turbo::Broadcastable::TestHelper::CaptureTurboStreamBroadcastsTest < Activ
class Turbo::Broadcastable::TestHelper::AssertTurboStreamBroadcastsTest < ActiveSupport::TestCase
include Turbo::Broadcastable::TestHelper

test "#an exception is raised when the argument is nil" do
message = Message.new(id: 1)

assert_raises ArgumentError do
message.broadcast_replace_to nil
end
end

test "#assert_turbo_stream_broadcasts passes when there is a broadcast" do
message = Message.new(id: 1)

Expand Down