Files
once-campfire/test/test_helpers/turbo_test_helper.rb
T
Kevin McConnell df76a227dc Hello world
First open source release of Campfire 🎉
2025-08-21 09:31:59 +01:00

18 lines
654 B
Ruby

module TurboTestHelper
def assert_rendered_turbo_stream_broadcast(*streambles, action:, target:, &block)
streams = find_broadcasts_for(*streambles)
target = ActionView::RecordIdentifier.dom_id(*target)
assert_select Nokogiri::HTML.fragment(streams), %(turbo-stream[action="#{action}"][target="#{target}"]), &block
end
private
def find_broadcasts_for(*streambles)
broadcasting = streambles.collect do |streamble|
streamble.try(:to_gid_param) || streamble
end.join(":")
broadcasts = ActionCable.server.pubsub.broadcasts(broadcasting)
broadcasts.collect { |b| JSON.parse(b) }.join("\n\n")
end
end