diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-31 07:08:49 -0700 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-03-31 07:08:49 -0700 |
commit | 9a83ef38912063db127a3918b0f155d5d3acfe3b (patch) | |
tree | e6225bc33dcc1dcefdfefca4537bde07bc8df94a /actioncable/test/stubs/test_connection.rb | |
parent | 903f447e436a7c909c3afc552f27bbbc1b4770c8 (diff) | |
parent | b168eb5819fa5fea940c9865d5c9a3ec5ba2a7ec (diff) | |
download | rails-9a83ef38912063db127a3918b0f155d5d3acfe3b.tar.gz rails-9a83ef38912063db127a3918b0f155d5d3acfe3b.tar.bz2 rails-9a83ef38912063db127a3918b0f155d5d3acfe3b.zip |
Merge pull request #24233 from jeremy/cable/encoding
Cable message encoding
Diffstat (limited to 'actioncable/test/stubs/test_connection.rb')
-rw-r--r-- | actioncable/test/stubs/test_connection.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/actioncable/test/stubs/test_connection.rb b/actioncable/test/stubs/test_connection.rb index 8ba284fdc6..885450dda6 100644 --- a/actioncable/test/stubs/test_connection.rb +++ b/actioncable/test/stubs/test_connection.rb @@ -3,24 +3,31 @@ require 'stubs/user' class TestConnection attr_reader :identifiers, :logger, :current_user, :server, :transmissions - def initialize(user = User.new("lifo")) + delegate :pubsub, to: :server + + def initialize(user = User.new("lifo"), coder: ActiveSupport::JSON, subscription_adapter: SuccessAdapter) + @coder = coder @identifiers = [ :current_user ] @current_user = user @logger = ActiveSupport::TaggedLogging.new ActiveSupport::Logger.new(StringIO.new) - @server = TestServer.new + @server = TestServer.new(subscription_adapter: subscription_adapter) @transmissions = [] end - def pubsub - SuccessAdapter.new(server) + def transmit(cable_message) + @transmissions << encode(cable_message) end - def transmit(data) - @transmissions << data + def last_transmission + decode @transmissions.last if @transmissions.any? end - def last_transmission - @transmissions.last + def decode(websocket_message) + @coder.decode websocket_message + end + + def encode(cable_message) + @coder.encode cable_message end end |