aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/stubs
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/stubs')
-rw-r--r--actioncable/test/stubs/global_id.rb10
-rw-r--r--actioncable/test/stubs/room.rb18
-rw-r--r--actioncable/test/stubs/test_adapter.rb14
-rw-r--r--actioncable/test/stubs/test_connection.rb35
-rw-r--r--actioncable/test/stubs/test_server.rb32
-rw-r--r--actioncable/test/stubs/user.rb17
6 files changed, 126 insertions, 0 deletions
diff --git a/actioncable/test/stubs/global_id.rb b/actioncable/test/stubs/global_id.rb
new file mode 100644
index 0000000000..15fab6b8a7
--- /dev/null
+++ b/actioncable/test/stubs/global_id.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class GlobalID
+ attr_reader :uri
+ delegate :to_param, :to_s, to: :uri
+
+ def initialize(gid, options = {})
+ @uri = gid
+ end
+end
diff --git a/actioncable/test/stubs/room.rb b/actioncable/test/stubs/room.rb
new file mode 100644
index 0000000000..df7236f408
--- /dev/null
+++ b/actioncable/test/stubs/room.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class Room
+ attr_reader :id, :name
+
+ def initialize(id, name = "Campfire")
+ @id = id
+ @name = name
+ end
+
+ def to_global_id
+ GlobalID.new("Room##{id}-#{name}")
+ end
+
+ def to_gid_param
+ to_global_id.to_param
+ end
+end
diff --git a/actioncable/test/stubs/test_adapter.rb b/actioncable/test/stubs/test_adapter.rb
new file mode 100644
index 0000000000..3b25c9168f
--- /dev/null
+++ b/actioncable/test/stubs/test_adapter.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+class SuccessAdapter < ActionCable::SubscriptionAdapter::Base
+ def broadcast(channel, payload)
+ end
+
+ def subscribe(channel, callback, success_callback = nil)
+ @@subscribe_called = { channel: channel, callback: callback, success_callback: success_callback }
+ end
+
+ def unsubscribe(channel, callback)
+ @@unsubscribe_called = { channel: channel, callback: callback }
+ end
+end
diff --git a/actioncable/test/stubs/test_connection.rb b/actioncable/test/stubs/test_connection.rb
new file mode 100644
index 0000000000..155c68e38c
--- /dev/null
+++ b/actioncable/test/stubs/test_connection.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require "stubs/user"
+
+class TestConnection
+ attr_reader :identifiers, :logger, :current_user, :server, :subscriptions, :transmissions
+
+ 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(subscription_adapter: subscription_adapter)
+ @transmissions = []
+ end
+
+ def transmit(cable_message)
+ @transmissions << encode(cable_message)
+ end
+
+ def last_transmission
+ decode @transmissions.last if @transmissions.any?
+ end
+
+ def decode(websocket_message)
+ @coder.decode websocket_message
+ end
+
+ def encode(cable_message)
+ @coder.encode cable_message
+ end
+end
diff --git a/actioncable/test/stubs/test_server.rb b/actioncable/test/stubs/test_server.rb
new file mode 100644
index 0000000000..0bc4625e28
--- /dev/null
+++ b/actioncable/test/stubs/test_server.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require "ostruct"
+
+class TestServer
+ include ActionCable::Server::Connections
+ include ActionCable::Server::Broadcasting
+
+ attr_reader :logger, :config, :mutex
+
+ def initialize(subscription_adapter: SuccessAdapter)
+ @logger = ActiveSupport::TaggedLogging.new ActiveSupport::Logger.new(StringIO.new)
+
+ @config = OpenStruct.new(log_tags: [], subscription_adapter: subscription_adapter)
+
+ @mutex = Monitor.new
+ end
+
+ def pubsub
+ @pubsub ||= @config.subscription_adapter.new(self)
+ end
+
+ def event_loop
+ @event_loop ||= ActionCable::Connection::StreamEventLoop.new.tap do |loop|
+ loop.instance_variable_set(:@executor, Concurrent.global_io_executor)
+ end
+ end
+
+ def worker_pool
+ @worker_pool ||= ActionCable::Server::Worker.new(max_size: 5)
+ end
+end
diff --git a/actioncable/test/stubs/user.rb b/actioncable/test/stubs/user.rb
new file mode 100644
index 0000000000..7894d1d9ae
--- /dev/null
+++ b/actioncable/test/stubs/user.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class User
+ attr_reader :name
+
+ def initialize(name)
+ @name = name
+ end
+
+ def to_global_id
+ GlobalID.new("User##{name}")
+ end
+
+ def to_gid_param
+ to_global_id.to_param
+ end
+end