提交 87f407db 编写于 作者: I Ilia Kasianenko

Add Missing ActiveSupport::Rescuable to ActionCable::Channel

[timthez, Ilia Kasianenko]
上级 c4f37cc8
# frozen_string_literal: true
require "set"
require "active_support/rescuable"
module ActionCable
module Channel
......@@ -99,6 +100,7 @@ class Base
include Streams
include Naming
include Broadcasting
include ActiveSupport::Rescuable
attr_reader :params, :connection, :identifier
delegate :logger, to: :connection
......@@ -267,6 +269,8 @@ def dispatch_action(action, data)
else
public_send action
end
rescue Exception => exception
rescue_with_handler(exception) || raise
end
def action_signature(action, data)
......
......@@ -26,6 +26,9 @@ class ChatChannel < BasicChannel
after_subscribe :toggle_subscribed
after_unsubscribe :toggle_subscribed
class SomeCustomError < StandardError; end
rescue_from SomeCustomError, with: :error_handler
def initialize(*)
@subscribed = false
super
......@@ -68,10 +71,18 @@ def receive
@last_action = [ :receive ]
end
def error_action
raise SomeCustomError
end
private
def rm_rf
@last_action = [ :rm_rf ]
end
def error_handler
@last_action = [ :error_action ]
end
end
setup do
......@@ -168,7 +179,7 @@ def rm_rf
end
test "actions available on Channel" do
available_actions = %w(room last_action subscribed unsubscribed toggle_subscribed leave speak subscribed? get_latest receive chatters topic).to_set
available_actions = %w(room last_action subscribed unsubscribed toggle_subscribed leave speak subscribed? get_latest receive chatters topic error_action).to_set
assert_equal available_actions, ChatChannel.action_methods
end
......@@ -256,6 +267,11 @@ def rm_rf
end
end
test "behaves like rescuable" do
@channel.perform_action "action" => :error_action
assert_equal [ :error_action ], @channel.last_action
end
private
def assert_logged(message)
old_logger = @connection.logger
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册