提交 dabf4793 编写于 作者: D David Heinemeier Hansson

Merge pull request #23811 from iamvery/string-channel

Ensure actioncable behaves as expected with non-string queues
* Ensure ActionCable behaves correctly for non-string queue names.
*Jay Hayes*
## Rails 5.0.0.beta3 (February 24, 2016) ##
* Added `em_redis_connector` and `redis_connector` to
......
......@@ -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!
......
......@@ -26,7 +26,7 @@ def broadcast(broadcasting, message)
# Returns a broadcaster for a named <tt>broadcasting</tt> that can be reused. Useful when you have an object that
# may need multiple spots to transmit to a specific broadcasting over and over.
def broadcaster_for(broadcasting)
Broadcaster.new(self, broadcasting)
Broadcaster.new(self, String(broadcasting))
end
private
......
......@@ -14,7 +14,12 @@ def subscribed
def send_confirmation
transmit_subscription_confirmation
end
end
class SymbolChannel < ActionCable::Channel::Base
def subscribed
stream_from :channel
end
end
test "streaming start and stop" do
......@@ -28,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
......
require "test_helper"
class BroadcastingTest < ActiveSupport::TestCase
class TestServer
include ActionCable::Server::Broadcasting
end
test "fetching a broadcaster converts the broadcasting queue to a string" do
broadcasting = :test_queue
server = TestServer.new
broadcaster = server.broadcaster_for(broadcasting)
assert_equal "test_queue", broadcaster.broadcasting
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册