aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/subscription_adapter
diff options
context:
space:
mode:
authorVladimir Dementyev <dementiev.vm@gmail.com>2018-08-19 19:06:30 -0400
committerVladimir Dementyev <dementiev.vm@gmail.com>2018-08-19 19:06:30 -0400
commitf7dd2d67d6a8b74f2762be51dff4f96983175aee (patch)
treeb19c182aca42342ac0c8c075ad4904e5cdb07080 /actioncable/lib/action_cable/subscription_adapter
parent44007c07098a3c633180881cae9285da4622e63f (diff)
downloadrails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.tar.gz
rails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.tar.bz2
rails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.zip
Add Action Cable test adapter
Diffstat (limited to 'actioncable/lib/action_cable/subscription_adapter')
-rw-r--r--actioncable/lib/action_cable/subscription_adapter/test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/actioncable/lib/action_cable/subscription_adapter/test.rb b/actioncable/lib/action_cable/subscription_adapter/test.rb
new file mode 100644
index 0000000000..52226a7c71
--- /dev/null
+++ b/actioncable/lib/action_cable/subscription_adapter/test.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require_relative "async"
+
+module ActionCable
+ module SubscriptionAdapter
+ # == Test adapter for Action Cable
+ #
+ # The test adapter should be used only in testing. Along with
+ # <tt>ActionCable::TestHelper</tt> it makes a great tool to test your Rails application.
+ #
+ # To use the test adapter set adapter value to +test+ in your +cable.yml+.
+ #
+ # NOTE: Test adapter extends the <tt>ActionCable::SubscriptionsAdapter::Async</tt> adapter,
+ # so it could be used in system tests too.
+ class Test < Async
+ def broadcast(channel, payload)
+ broadcasts(channel) << payload
+ super
+ end
+
+ def broadcasts(channel)
+ channels_data[channel] ||= []
+ end
+
+ def clear_messages(channel)
+ channels_data[channel] = []
+ end
+
+ def clear
+ @channels_data = nil
+ end
+
+ private
+ def channels_data
+ @channels_data ||= {}
+ end
+ end
+ end
+end