diff options
author | Vladimir Dementyev <dementiev.vm@gmail.com> | 2018-08-19 19:06:30 -0400 |
---|---|---|
committer | Vladimir Dementyev <dementiev.vm@gmail.com> | 2018-08-19 19:06:30 -0400 |
commit | f7dd2d67d6a8b74f2762be51dff4f96983175aee (patch) | |
tree | b19c182aca42342ac0c8c075ad4904e5cdb07080 /actioncable/lib/action_cable | |
parent | 44007c07098a3c633180881cae9285da4622e63f (diff) | |
download | rails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.tar.gz rails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.tar.bz2 rails-f7dd2d67d6a8b74f2762be51dff4f96983175aee.zip |
Add Action Cable test adapter
Diffstat (limited to 'actioncable/lib/action_cable')
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter.rb | 1 | ||||
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter/test.rb | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/actioncable/lib/action_cable/subscription_adapter.rb b/actioncable/lib/action_cable/subscription_adapter.rb index bcece8d33b..6a9d5c2080 100644 --- a/actioncable/lib/action_cable/subscription_adapter.rb +++ b/actioncable/lib/action_cable/subscription_adapter.rb @@ -5,6 +5,7 @@ module ActionCable extend ActiveSupport::Autoload autoload :Base + autoload :Test autoload :SubscriberMap autoload :ChannelPrefix end 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 |