Class: ActionCable::Connection::TestSocket

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

Defined Under Namespace

Classes: Request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ TestSocket

Returns a new instance of TestSocket.



85
86
87
88
89
90
91
92
93
94
# File 'lib/action_cable/connection/test_case.rb', line 85

def initialize(request)
  inner_logger = ActiveSupport::Logger.new(StringIO.new)
  tagged_logging = ActiveSupport::TaggedLogging.new(inner_logger)
  @logger = ActionCable::Server::TaggedLoggerProxy.new(tagged_logging, tags: [])
  @request = request
  @env = request.env
  @connection = nil
  @closed = false
  @transmissions = []
end

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



59
60
61
# File 'lib/action_cable/connection/test_case.rb', line 59

def closed
  @closed
end

#envObject (readonly)

Returns the value of attribute env.



59
60
61
# File 'lib/action_cable/connection/test_case.rb', line 59

def env
  @env
end

#loggerObject (readonly)

Returns the value of attribute logger.



59
60
61
# File 'lib/action_cable/connection/test_case.rb', line 59

def logger
  @logger
end

#requestObject (readonly)

Returns the value of attribute request.



59
60
61
# File 'lib/action_cable/connection/test_case.rb', line 59

def request
  @request
end

#transmissionsObject (readonly)

Returns the value of attribute transmissions.



59
60
61
# File 'lib/action_cable/connection/test_case.rb', line 59

def transmissions
  @transmissions
end

Class Method Details

.build_request(path, params: nil, headers: {}, session: {}, env: {}, cookies: nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/action_cable/connection/test_case.rb', line 62

def build_request(path, params: nil, headers: {}, session: {}, env: {}, cookies: nil)
  wrapped_headers = ActionDispatch::Http::Headers.from_hash(headers)

  uri = URI.parse(path)

  query_string = params.nil? ? uri.query : params.to_query

  request_env = {
    "QUERY_STRING" => query_string,
    "PATH_INFO" => uri.path
  }.merge(env)

  if wrapped_headers.present?
    ActionDispatch::Http::Headers.from_hash(request_env).merge!(wrapped_headers)
  end

  Request.create(request_env).tap do |request|
    request.session = session.with_indifferent_access
    request.cookie_jar = cookies
  end
end

Instance Method Details

#closeObject



100
101
102
# File 'lib/action_cable/connection/test_case.rb', line 100

def close
  @closed = true
end

#transmit(data) ⇒ Object



96
97
98
# File 'lib/action_cable/connection/test_case.rb', line 96

def transmit(data)
  @transmissions << data.with_indifferent_access
end