diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-03-29 23:42:21 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-03-29 23:42:21 -0300 |
commit | 6786718766f10ef25af427a43e47c15ee02dc7e5 (patch) | |
tree | 0e408129980442f97173b456c6ed4c7e6fe72e7b /actioncable/test/channel/log_subscriber_test.rb | |
parent | 8e8c57b412852b5e63afd3b2b3799b87cb789eaa (diff) | |
parent | 09a1321d5b57111edc273f68f428e4ee5471ed5c (diff) | |
download | rails-6786718766f10ef25af427a43e47c15ee02dc7e5.tar.gz rails-6786718766f10ef25af427a43e47c15ee02dc7e5.tar.bz2 rails-6786718766f10ef25af427a43e47c15ee02dc7e5.zip |
Merge pull request #23723 from mwear/action_cable_notifications
Add ActiveSupport::Notification to Channel::Base#perform_action
Diffstat (limited to 'actioncable/test/channel/log_subscriber_test.rb')
-rw-r--r-- | actioncable/test/channel/log_subscriber_test.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/actioncable/test/channel/log_subscriber_test.rb b/actioncable/test/channel/log_subscriber_test.rb new file mode 100644 index 0000000000..18acdc9fbd --- /dev/null +++ b/actioncable/test/channel/log_subscriber_test.rb @@ -0,0 +1,69 @@ +require 'test_helper' +require 'stubs/test_connection' +require 'active_support/log_subscriber/test_helper' +require 'action_cable/channel/log_subscriber' + +class ActionCable::Channel::LogSubscriberTest < ActiveSupport::TestCase + include ActiveSupport::LogSubscriber::TestHelper + + class ChatChannel < ActionCable::Channel::Base + attr_reader :last_action + + def speak(data) + @last_action = [ :speak, data ] + end + + def get_latest + transmit data: 'latest' + end + end + + def setup + super + @connection = TestConnection.new + @channel = ChatChannel.new @connection, "{id: 1}", { id: 1 } + ActionCable::Channel::LogSubscriber.attach_to :action_cable + end + + def test_perform_action + data = {'action' => :speak, 'content' => 'hello'} + @channel.perform_action(data) + wait + + assert_equal(1, logs.size) + assert_match(/Completed #{channel_class}#speak in \d+ms/, logs.first) + end + + def test_transmit + @channel.perform_action('action' => :get_latest) + wait + + assert_equal(2, logs.size) + assert_match(/^#{channel_class} transmitting/, logs.first) + end + + def test_transmit_subscription_confirmation + @channel.stubs(:subscription_confirmation_sent?).returns(false) + @channel.send(:transmit_subscription_confirmation) + wait + + assert_equal(1, logs.size) + assert_equal("#{channel_class} is transmitting the subscription confirmation", logs.first) + end + + def test_transmit_subscription_rejection + @channel.send(:transmit_subscription_rejection) + wait + + assert_equal(1, logs.size) + assert_equal("#{channel_class} is transmitting the subscription rejection", logs.first) + end + + def channel_class + "ActionCable::Channel::LogSubscriberTest::ChatChannel" + end + + def logs + @logs ||= @logger.logged(:info) + end +end |