跳至内容 跳至搜索
命名空间
方法
C
D
包含模块

常量

DEFAULT_PATH = "/cable"
 

属性

[R] connection

实例公共方法

connect(path = ActionCable.server.config.mount_path, **request_params)

执行连接尝试,对正在测试的连接执行 connect

接受请求路径作为第一个参数,以及以下请求选项

  • params – URL 参数 (Hash)

  • headers – 请求头 (Hash)

  • session – 会话数据 (Hash)

  • env – 其他 Rack 环境配置 (Hash)

# File actioncable/lib/action_cable/connection/test_case.rb, line 195
def connect(path = ActionCable.server.config.mount_path, **request_params)
  path ||= DEFAULT_PATH

  connection = self.class.connection_class.allocate
  connection.singleton_class.include(TestConnection)
  connection.send(:initialize, build_test_request(path, **request_params))
  connection.connect if connection.respond_to?(:connect)

  # Only set instance variable if connected successfully
  @connection = connection
end

cookies()

# File actioncable/lib/action_cable/connection/test_case.rb, line 215
def cookies
  @cookie_jar ||= TestCookieJar.new
end

disconnect()

对正在测试的连接执行 disconnect

# File actioncable/lib/action_cable/connection/test_case.rb, line 208
def disconnect
  raise "Must be connected!" if connection.nil?

  connection.disconnect if connection.respond_to?(:disconnect)
  @connection = nil
end