提交 046e3265 编写于 作者: J Jay Hayes

Convert stream broadcasting to a string

ActionCable does some things behind the scenes that expects these
"broadcasting"s or "channel"s to be strings. However it's not
immediately obvious that the value must be a string. So adding this
conversion ensures things work as expected.
上级 b4262472
......@@ -72,6 +72,7 @@ module Streams
# Start streaming from the named <tt>broadcasting</tt> pubsub queue. Optionally, you can pass a <tt>callback</tt> that'll be used
# instead of the default of just transmitting the updates straight to the subscriber.
def stream_from(broadcasting, callback = nil)
broadcasting = String(broadcasting)
# Don't send the confirmation until pubsub#subscribe is successful
defer_subscription_confirmation!
......
......@@ -16,6 +16,12 @@ def send_confirmation
end
end
class SymbolChannel < ActionCable::Channel::Base
def subscribed
stream_from :channel
end
end
test "streaming start and stop" do
run_in_eventmachine do
connection = TestConnection.new
......@@ -27,6 +33,17 @@ def send_confirmation
end
end
test "stream from non-string channel" do
run_in_eventmachine do
connection = TestConnection.new
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("channel", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
channel = SymbolChannel.new connection, ""
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe) }
channel.unsubscribe_from_channel
end
end
test "stream_for" do
run_in_eventmachine do
connection = TestConnection.new
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册