Skip to content

Commit dabf479

Browse files
author
David Heinemeier Hansson
committed
Merge pull request rails#23811 from iamvery/string-channel
Ensure actioncable behaves as expected with non-string queues
2 parents 2280c84 + bbe5937 commit dabf479

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

actioncable/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Ensure ActionCable behaves correctly for non-string queue names.
2+
3+
*Jay Hayes*
4+
15
## Rails 5.0.0.beta3 (February 24, 2016) ##
26

37
* Added `em_redis_connector` and `redis_connector` to

actioncable/lib/action_cable/channel/streams.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module Streams
7272
# Start streaming from the named <tt>broadcasting</tt> pubsub queue. Optionally, you can pass a <tt>callback</tt> that'll be used
7373
# instead of the default of just transmitting the updates straight to the subscriber.
7474
def stream_from(broadcasting, callback = nil)
75+
broadcasting = String(broadcasting)
7576
# Don't send the confirmation until pubsub#subscribe is successful
7677
defer_subscription_confirmation!
7778

actioncable/lib/action_cable/server/broadcasting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def broadcast(broadcasting, message)
2626
# Returns a broadcaster for a named <tt>broadcasting</tt> that can be reused. Useful when you have an object that
2727
# may need multiple spots to transmit to a specific broadcasting over and over.
2828
def broadcaster_for(broadcasting)
29-
Broadcaster.new(self, broadcasting)
29+
Broadcaster.new(self, String(broadcasting))
3030
end
3131

3232
private

actioncable/test/channel/stream_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ def subscribed
1414
def send_confirmation
1515
transmit_subscription_confirmation
1616
end
17+
end
1718

19+
class SymbolChannel < ActionCable::Channel::Base
20+
def subscribed
21+
stream_from :channel
22+
end
1823
end
1924

2025
test "streaming start and stop" do
@@ -28,6 +33,17 @@ def send_confirmation
2833
end
2934
end
3035

36+
test "stream from non-string channel" do
37+
run_in_eventmachine do
38+
connection = TestConnection.new
39+
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("channel", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
40+
channel = SymbolChannel.new connection, ""
41+
42+
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe) }
43+
channel.unsubscribe_from_channel
44+
end
45+
end
46+
3147
test "stream_for" do
3248
run_in_eventmachine do
3349
connection = TestConnection.new
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "test_helper"
2+
3+
class BroadcastingTest < ActiveSupport::TestCase
4+
class TestServer
5+
include ActionCable::Server::Broadcasting
6+
end
7+
8+
test "fetching a broadcaster converts the broadcasting queue to a string" do
9+
broadcasting = :test_queue
10+
server = TestServer.new
11+
broadcaster = server.broadcaster_for(broadcasting)
12+
13+
assert_equal "test_queue", broadcaster.broadcasting
14+
end
15+
end

0 commit comments

Comments
 (0)