Class: ActionCable::Connection::TestServer

Inherits:
Object
  • Object
show all
Defined in:
lib/action_cable/connection/test_case.rb

Overview

TestServer provides test pub/sub and executor implementations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ TestServer

Returns a new instance of TestServer.



109
110
111
112
# File 'lib/action_cable/connection/test_case.rb', line 109

def initialize(server)
  @streams = Hash.new { |h, k| h[k] = [] }
  @config = server.config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



107
108
109
# File 'lib/action_cable/connection/test_case.rb', line 107

def config
  @config
end

#streamsObject (readonly)

Returns the value of attribute streams.



107
108
109
# File 'lib/action_cable/connection/test_case.rb', line 107

def streams
  @streams
end

Instance Method Details

#post(&work) ⇒ Object

Inline async calls



120
121
# File 'lib/action_cable/connection/test_case.rb', line 120

def post(&work) = work.call
# We don't support timers in unit tests yet

#subscribe(stream, callback, success_callback = nil) ⇒ Object

Pub/sub interface ==



125
126
127
128
# File 'lib/action_cable/connection/test_case.rb', line 125

def subscribe(stream, callback, success_callback = nil)
  @streams[stream] << callback
  success_callback&.call
end

#timer(_every) ⇒ Object

We don’t support timers in unit tests yet



122
# File 'lib/action_cable/connection/test_case.rb', line 122

def timer(_every) = nil

#unsubscribe(stream, callback) ⇒ Object



130
131
132
133
# File 'lib/action_cable/connection/test_case.rb', line 130

def unsubscribe(stream, callback)
  @streams[stream].delete(callback)
  @streams.delete(stream) if @streams[stream].empty?
end