2015-01-15 12:28:02 -05:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ServerTest < ActionCableTest
|
|
|
|
|
|
|
|
class ChatChannel < ActionCable::Channel::Base
|
|
|
|
def self.matches?(identifier)
|
|
|
|
identifier[:channel] == 'chat' && identifier[:user_id].to_i.nonzero?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-28 14:16:54 -04:00
|
|
|
class ChatServer < ActionCable::Server::Base
|
2015-01-15 12:28:02 -05:00
|
|
|
register_channels ChatChannel
|
|
|
|
end
|
|
|
|
|
|
|
|
def app
|
|
|
|
ChatServer
|
|
|
|
end
|
|
|
|
|
|
|
|
test "channel registration" do
|
2015-07-05 16:34:23 -04:00
|
|
|
assert_equal ChatServer.channel_classes, Set.new([ ChatChannel ])
|
2015-01-15 12:28:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "subscribing to a channel with valid params" do
|
|
|
|
ws = Faye::WebSocket::Client.new(websocket_url)
|
|
|
|
|
|
|
|
ws.on(:message) do |message|
|
|
|
|
puts message.inspect
|
|
|
|
end
|
|
|
|
|
2015-06-19 13:05:06 -04:00
|
|
|
ws.send command: 'subscribe', identifier: { channel: 'chat'}.to_json
|
2015-01-15 12:28:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "subscribing to a channel with invalid params" do
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|