1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #34686 from got2be/actioncable-channel-rescuable

Add Missing ActiveSupport::Rescuable to ActionCable::Channel
This commit is contained in:
Kasper Timm Hansen 2018-12-12 15:30:44 +01:00 committed by GitHub
commit 0fc6804c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "set" require "set"
require "active_support/rescuable"
module ActionCable module ActionCable
module Channel module Channel
@ -99,6 +100,7 @@ module ActionCable
include Streams include Streams
include Naming include Naming
include Broadcasting include Broadcasting
include ActiveSupport::Rescuable
attr_reader :params, :connection, :identifier attr_reader :params, :connection, :identifier
delegate :logger, to: :connection delegate :logger, to: :connection
@ -267,6 +269,8 @@ module ActionCable
else else
public_send action public_send action
end end
rescue Exception => exception
rescue_with_handler(exception) || raise
end end
def action_signature(action, data) def action_signature(action, data)

View file

@ -26,6 +26,9 @@ class ActionCable::Channel::BaseTest < ActionCable::TestCase
after_subscribe :toggle_subscribed after_subscribe :toggle_subscribed
after_unsubscribe :toggle_subscribed after_unsubscribe :toggle_subscribed
class SomeCustomError < StandardError; end
rescue_from SomeCustomError, with: :error_handler
def initialize(*) def initialize(*)
@subscribed = false @subscribed = false
super super
@ -68,10 +71,18 @@ class ActionCable::Channel::BaseTest < ActionCable::TestCase
@last_action = [ :receive ] @last_action = [ :receive ]
end end
def error_action
raise SomeCustomError
end
private private
def rm_rf def rm_rf
@last_action = [ :rm_rf ] @last_action = [ :rm_rf ]
end end
def error_handler
@last_action = [ :error_action ]
end
end end
setup do setup do
@ -168,7 +179,7 @@ class ActionCable::Channel::BaseTest < ActionCable::TestCase
end end
test "actions available on Channel" do 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 assert_equal available_actions, ChatChannel.action_methods
end end
@ -256,6 +267,11 @@ class ActionCable::Channel::BaseTest < ActionCable::TestCase
end end
end end
test "behaves like rescuable" do
@channel.perform_action "action" => :error_action
assert_equal [ :error_action ], @channel.last_action
end
private private
def assert_logged(message) def assert_logged(message)
old_logger = @connection.logger old_logger = @connection.logger