aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/connection/identifier_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/connection/identifier_test.rb')
-rw-r--r--actioncable/test/connection/identifier_test.rb40
1 files changed, 20 insertions, 20 deletions
diff --git a/actioncable/test/connection/identifier_test.rb b/actioncable/test/connection/identifier_test.rb
index 6b6c8cd31a..707f4bab72 100644
--- a/actioncable/test/connection/identifier_test.rb
+++ b/actioncable/test/connection/identifier_test.rb
@@ -18,52 +18,52 @@ class ActionCable::Connection::IdentifierTest < ActionCable::TestCase
test "connection identifier" do
run_in_eventmachine do
- open_connection_with_stubbed_pubsub
+ open_connection
assert_equal "User#lifo", @connection.connection_identifier
end
end
test "should subscribe to internal channel on open and unsubscribe on close" do
run_in_eventmachine do
- pubsub = mock("pubsub_adapter")
- pubsub.expects(:subscribe).with("action_cable/User#lifo", kind_of(Proc))
- pubsub.expects(:unsubscribe).with("action_cable/User#lifo", kind_of(Proc))
-
server = TestServer.new
- server.stubs(:pubsub).returns(pubsub)
- open_connection server: server
+ open_connection(server)
close_connection
+ wait_for_async
+
+ %w[subscribe unsubscribe].each do |method|
+ pubsub_call = server.pubsub.class.class_variable_get "@@#{method}_called"
+
+ assert_equal "action_cable/User#lifo", pubsub_call[:channel]
+ assert_instance_of Proc, pubsub_call[:callback]
+ end
end
end
test "processing disconnect message" do
run_in_eventmachine do
- open_connection_with_stubbed_pubsub
+ open_connection
- @connection.websocket.expects(:close)
- @connection.process_internal_message "type" => "disconnect"
+ assert_called(@connection.websocket, :close) do
+ @connection.process_internal_message "type" => "disconnect"
+ end
end
end
test "processing invalid message" do
run_in_eventmachine do
- open_connection_with_stubbed_pubsub
+ open_connection
- @connection.websocket.expects(:close).never
- @connection.process_internal_message "type" => "unknown"
+ assert_not_called(@connection.websocket, :close) do
+ @connection.process_internal_message "type" => "unknown"
+ end
end
end
private
- def open_connection_with_stubbed_pubsub
- server = TestServer.new
- server.stubs(:adapter).returns(stub_everything("adapter"))
-
- open_connection server: server
- end
+ def open_connection(server = nil)
+ server ||= TestServer.new
- def open_connection(server:)
env = Rack::MockRequest.env_for "/test", "HTTP_HOST" => "localhost", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket"
@connection = Connection.new(server, env)