aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/channel
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/channel')
-rw-r--r--actioncable/test/channel/base_test.rb64
-rw-r--r--actioncable/test/channel/broadcasting_test.rb8
-rw-r--r--actioncable/test/channel/naming_test.rb2
-rw-r--r--actioncable/test/channel/periodic_timers_test.rb20
-rw-r--r--actioncable/test/channel/rejection_test.rb9
-rw-r--r--actioncable/test/channel/stream_test.rb34
6 files changed, 68 insertions, 69 deletions
diff --git a/actioncable/test/channel/base_test.rb b/actioncable/test/channel/base_test.rb
index daa782eeb3..2bb3214f74 100644
--- a/actioncable/test/channel/base_test.rb
+++ b/actioncable/test/channel/base_test.rb
@@ -1,6 +1,6 @@
-require 'test_helper'
-require 'stubs/test_connection'
-require 'stubs/room'
+require "test_helper"
+require "stubs/test_connection"
+require "stubs/room"
class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
class ActionCable::Channel::Base
@@ -58,7 +58,7 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
end
def get_latest
- transmit data: 'latest'
+ transmit data: "latest"
end
def receive
@@ -74,7 +74,7 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
setup do
@user = User.new "lifo"
@connection = TestConnection.new(@user)
- @channel = ChatChannel.new @connection, "{id: 1}", { id: 1 }
+ @channel = ChatChannel.new @connection, "{id: 1}", id: 1
end
test "should subscribe to a channel on initialize" do
@@ -104,49 +104,49 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
end
test "callable action without any argument" do
- @channel.perform_action 'action' => :leave
+ @channel.perform_action "action" => :leave
assert_equal [ :leave ], @channel.last_action
end
test "callable action with arguments" do
- data = { 'action' => :speak, 'content' => "Hello World" }
+ data = { "action" => :speak, "content" => "Hello World" }
@channel.perform_action data
assert_equal [ :speak, data ], @channel.last_action
end
test "should not dispatch a private method" do
- @channel.perform_action 'action' => :rm_rf
+ @channel.perform_action "action" => :rm_rf
assert_nil @channel.last_action
end
test "should not dispatch a public method defined on Base" do
- @channel.perform_action 'action' => :kick
+ @channel.perform_action "action" => :kick
assert_nil @channel.last_action
end
test "should dispatch a public method defined on Base and redefined on channel" do
- data = { 'action' => :topic, 'content' => "This is Sparta!" }
+ data = { "action" => :topic, "content" => "This is Sparta!" }
@channel.perform_action data
assert_equal [ :topic, data ], @channel.last_action
end
test "should dispatch calling a public method defined in an ancestor" do
- @channel.perform_action 'action' => :chatters
+ @channel.perform_action "action" => :chatters
assert_equal [ :chatters ], @channel.last_action
end
test "should dispatch receive action when perform_action is called with empty action" do
- data = { 'content' => 'hello' }
+ data = { "content" => "hello" }
@channel.perform_action data
assert_equal [ :receive ], @channel.last_action
end
test "transmitting data" do
- @channel.perform_action 'action' => :get_latest
+ @channel.perform_action "action" => :get_latest
- expected = { "identifier" => "{id: 1}", "message" => { "data" => "latest" }}
+ expected = { "identifier" => "{id: 1}", "message" => { "data" => "latest" } }
assert_equal expected, @connection.last_transmission
end
@@ -162,7 +162,7 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
test "invalid action on Channel" do
assert_logged("Unable to process ActionCable::Channel::BaseTest::ChatChannel#invalid_action") do
- @channel.perform_action 'action' => :invalid_action
+ @channel.perform_action "action" => :invalid_action
end
end
@@ -173,12 +173,12 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
events << ActiveSupport::Notifications::Event.new(*args)
end
- data = {'action' => :speak, 'content' => 'hello'}
+ data = { "action" => :speak, "content" => "hello" }
@channel.perform_action data
assert_equal 1, events.length
- assert_equal 'perform_action.action_cable', events[0].name
- assert_equal 'ActionCable::Channel::BaseTest::ChatChannel', events[0].payload[:channel_class]
+ assert_equal "perform_action.action_cable", events[0].name
+ assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
assert_equal :speak, events[0].payload[:action]
assert_equal data, events[0].payload[:data]
ensure
@@ -189,27 +189,27 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
test "notification for transmit" do
begin
events = []
- ActiveSupport::Notifications.subscribe 'transmit.action_cable' do |*args|
+ ActiveSupport::Notifications.subscribe "transmit.action_cable" do |*args|
events << ActiveSupport::Notifications::Event.new(*args)
end
- @channel.perform_action 'action' => :get_latest
- expected_data = {data: 'latest'}
+ @channel.perform_action "action" => :get_latest
+ expected_data = { data: "latest" }
assert_equal 1, events.length
- assert_equal 'transmit.action_cable', events[0].name
- assert_equal 'ActionCable::Channel::BaseTest::ChatChannel', events[0].payload[:channel_class]
+ assert_equal "transmit.action_cable", events[0].name
+ assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
assert_equal expected_data, events[0].payload[:data]
assert_nil events[0].payload[:via]
ensure
- ActiveSupport::Notifications.unsubscribe 'transmit.action_cable'
+ ActiveSupport::Notifications.unsubscribe "transmit.action_cable"
end
end
test "notification for transmit_subscription_confirmation" do
begin
events = []
- ActiveSupport::Notifications.subscribe 'transmit_subscription_confirmation.action_cable' do |*args|
+ ActiveSupport::Notifications.subscribe "transmit_subscription_confirmation.action_cable" do |*args|
events << ActiveSupport::Notifications::Event.new(*args)
end
@@ -217,27 +217,27 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
@channel.send(:transmit_subscription_confirmation)
assert_equal 1, events.length
- assert_equal 'transmit_subscription_confirmation.action_cable', events[0].name
- assert_equal 'ActionCable::Channel::BaseTest::ChatChannel', events[0].payload[:channel_class]
+ assert_equal "transmit_subscription_confirmation.action_cable", events[0].name
+ assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
ensure
- ActiveSupport::Notifications.unsubscribe 'transmit_subscription_confirmation.action_cable'
+ ActiveSupport::Notifications.unsubscribe "transmit_subscription_confirmation.action_cable"
end
end
test "notification for transmit_subscription_rejection" do
begin
events = []
- ActiveSupport::Notifications.subscribe 'transmit_subscription_rejection.action_cable' do |*args|
+ ActiveSupport::Notifications.subscribe "transmit_subscription_rejection.action_cable" do |*args|
events << ActiveSupport::Notifications::Event.new(*args)
end
@channel.send(:transmit_subscription_rejection)
assert_equal 1, events.length
- assert_equal 'transmit_subscription_rejection.action_cable', events[0].name
- assert_equal 'ActionCable::Channel::BaseTest::ChatChannel', events[0].payload[:channel_class]
+ assert_equal "transmit_subscription_rejection.action_cable", events[0].name
+ assert_equal "ActionCable::Channel::BaseTest::ChatChannel", events[0].payload[:channel_class]
ensure
- ActiveSupport::Notifications.unsubscribe 'transmit_subscription_rejection.action_cable'
+ ActiveSupport::Notifications.unsubscribe "transmit_subscription_rejection.action_cable"
end
end
diff --git a/actioncable/test/channel/broadcasting_test.rb b/actioncable/test/channel/broadcasting_test.rb
index 1de04243e5..3476c1db31 100644
--- a/actioncable/test/channel/broadcasting_test.rb
+++ b/actioncable/test/channel/broadcasting_test.rb
@@ -1,6 +1,6 @@
-require 'test_helper'
-require 'stubs/test_connection'
-require 'stubs/room'
+require "test_helper"
+require "stubs/test_connection"
+require "stubs/room"
class ActionCable::Channel::BroadcastingTest < ActiveSupport::TestCase
class ChatChannel < ActionCable::Channel::Base
@@ -11,7 +11,7 @@ class ActionCable::Channel::BroadcastingTest < ActiveSupport::TestCase
end
test "broadcasts_to" do
- ActionCable.stubs(:server).returns mock().tap { |m| m.expects(:broadcast).with('action_cable:channel:broadcasting_test:chat:Room#1-Campfire', "Hello World") }
+ ActionCable.stubs(:server).returns mock().tap { |m| m.expects(:broadcast).with("action_cable:channel:broadcasting_test:chat:Room#1-Campfire", "Hello World") }
ChatChannel.broadcast_to(Room.new(1), "Hello World")
end
diff --git a/actioncable/test/channel/naming_test.rb b/actioncable/test/channel/naming_test.rb
index 89ef6ad8b0..08f0e7be48 100644
--- a/actioncable/test/channel/naming_test.rb
+++ b/actioncable/test/channel/naming_test.rb
@@ -1,4 +1,4 @@
-require 'test_helper'
+require "test_helper"
class ActionCable::Channel::NamingTest < ActiveSupport::TestCase
class ChatChannel < ActionCable::Channel::Base
diff --git a/actioncable/test/channel/periodic_timers_test.rb b/actioncable/test/channel/periodic_timers_test.rb
index 03464003cf..529abb9535 100644
--- a/actioncable/test/channel/periodic_timers_test.rb
+++ b/actioncable/test/channel/periodic_timers_test.rb
@@ -1,7 +1,7 @@
-require 'test_helper'
-require 'stubs/test_connection'
-require 'stubs/room'
-require 'active_support/time'
+require "test_helper"
+require "stubs/test_connection"
+require "stubs/room"
+require "active_support/time"
class ActionCable::Channel::PeriodicTimersTest < ActiveSupport::TestCase
class ChatChannel < ActionCable::Channel::Base
@@ -36,22 +36,22 @@ class ActionCable::Channel::PeriodicTimersTest < ActiveSupport::TestCase
end
end
- test 'disallow negative and zero periods' do
- [ 0, 0.0, 0.seconds, -1, -1.seconds, 'foo', :foo, Object.new ].each do |invalid|
+ test "disallow negative and zero periods" do
+ [ 0, 0.0, 0.seconds, -1, -1.seconds, "foo", :foo, Object.new ].each do |invalid|
assert_raise ArgumentError, /Expected every:/ do
ChatChannel.periodically :send_updates, every: invalid
end
end
end
- test 'disallow block and arg together' do
+ test "disallow block and arg together" do
assert_raise ArgumentError, /not both/ do
ChatChannel.periodically(:send_updates, every: 1) { ping }
end
end
- test 'disallow unknown args' do
- [ 'send_updates', Object.new, nil ].each do |invalid|
+ test "disallow unknown args" do
+ [ "send_updates", Object.new, nil ].each do |invalid|
assert_raise ArgumentError, /Expected a Symbol/ do
ChatChannel.periodically invalid, every: 1
end
@@ -60,7 +60,7 @@ class ActionCable::Channel::PeriodicTimersTest < ActiveSupport::TestCase
test "timer start and stop" do
@connection.server.event_loop.expects(:timer).times(3).returns(stub(shutdown: nil))
- channel = ChatChannel.new @connection, "{id: 1}", { id: 1 }
+ channel = ChatChannel.new @connection, "{id: 1}", id: 1
channel.unsubscribe_from_channel
assert_equal [], channel.send(:active_periodic_timers)
diff --git a/actioncable/test/channel/rejection_test.rb b/actioncable/test/channel/rejection_test.rb
index 15db57d6ba..0d2ac1c129 100644
--- a/actioncable/test/channel/rejection_test.rb
+++ b/actioncable/test/channel/rejection_test.rb
@@ -1,6 +1,6 @@
-require 'test_helper'
-require 'stubs/test_connection'
-require 'stubs/room'
+require "test_helper"
+require "stubs/test_connection"
+require "stubs/room"
class ActionCable::Channel::RejectionTest < ActiveSupport::TestCase
class SecretChannel < ActionCable::Channel::Base
@@ -16,10 +16,9 @@ class ActionCable::Channel::RejectionTest < ActiveSupport::TestCase
test "subscription rejection" do
@connection.expects(:subscriptions).returns mock().tap { |m| m.expects(:remove_subscription).with instance_of(SecretChannel) }
- @channel = SecretChannel.new @connection, "{id: 1}", { id: 1 }
+ @channel = SecretChannel.new @connection, "{id: 1}", id: 1
expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
assert_equal expected, @connection.last_transmission
end
-
end
diff --git a/actioncable/test/channel/stream_test.rb b/actioncable/test/channel/stream_test.rb
index 38543920d3..da26f81a5c 100644
--- a/actioncable/test/channel/stream_test.rb
+++ b/actioncable/test/channel/stream_test.rb
@@ -1,6 +1,6 @@
-require 'test_helper'
-require 'stubs/test_connection'
-require 'stubs/room'
+require "test_helper"
+require "stubs/test_connection"
+require "stubs/room"
module ActionCable::StreamTests
class Connection < ActionCable::Connection::Base
@@ -25,11 +25,11 @@ module ActionCable::StreamTests
private def pick_coder(coder)
case coder
- when nil, 'json'
+ when nil, "json"
ActiveSupport::JSON
- when 'custom'
+ when "custom"
DummyEncoder
- when 'none'
+ when "none"
nil
end
end
@@ -38,7 +38,7 @@ module ActionCable::StreamTests
module DummyEncoder
extend self
def encode(*) '{ "foo": "encoded" }' end
- def decode(*) { foo: 'decoded' } end
+ def decode(*) { foo: "decoded" } end
end
class SymbolChannel < ActionCable::Channel::Base
@@ -52,7 +52,7 @@ module ActionCable::StreamTests
run_in_eventmachine do
connection = TestConnection.new
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("test_room_1", kind_of(Proc), kind_of(Proc)).returns stub_everything(:pubsub) }
- channel = ChatChannel.new connection, "{id: 1}", { id: 1 }
+ channel = ChatChannel.new connection, "{id: 1}", id: 1
connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe) }
channel.unsubscribe_from_channel
@@ -84,7 +84,7 @@ module ActionCable::StreamTests
run_in_eventmachine do
connection = TestConnection.new
- ChatChannel.new connection, "{id: 1}", { id: 1 }
+ ChatChannel.new connection, "{id: 1}", id: 1
assert_nil connection.last_transmission
wait_for_async
@@ -114,7 +114,7 @@ module ActionCable::StreamTests
end
end
- require 'action_cable/subscription_adapter/inline'
+ require "action_cable/subscription_adapter/inline"
class UserCallbackChannel < ActionCable::Channel::Base
def subscribed
@@ -130,13 +130,13 @@ module ActionCable::StreamTests
@server.config.allowed_request_origins = %w( http://rubyonrails.com )
end
- test 'custom encoder' do
+ test "custom encoder" do
run_in_eventmachine do
connection = open_connection
subscribe_to connection, identifiers: { id: 1 }
connection.websocket.expects(:transmit)
- @server.broadcast 'test_room_1', { foo: 'bar' }, coder: DummyEncoder
+ @server.broadcast "test_room_1", { foo: "bar" }, coder: DummyEncoder
wait_for_async
wait_for_executor connection.server.worker_pool.executor
end
@@ -145,9 +145,9 @@ module ActionCable::StreamTests
test "user supplied callbacks are run through the worker pool" do
run_in_eventmachine do
connection = open_connection
- receive(connection, command: 'subscribe', channel: UserCallbackChannel.name, identifiers: { id: 1 })
+ receive(connection, command: "subscribe", channel: UserCallbackChannel.name, identifiers: { id: 1 })
- @server.broadcast 'channel', {}
+ @server.broadcast "channel", {}
wait_for_async
refute Thread.current[:ran_callback], "User callback was not run through the worker pool"
end
@@ -155,11 +155,11 @@ module ActionCable::StreamTests
private
def subscribe_to(connection, identifiers:)
- receive connection, command: 'subscribe', identifiers: identifiers
+ receive connection, command: "subscribe", identifiers: identifiers
end
def open_connection
- env = Rack::MockRequest.env_for '/test', 'HTTP_HOST' => 'localhost', 'HTTP_CONNECTION' => 'upgrade', 'HTTP_UPGRADE' => 'websocket', 'HTTP_ORIGIN' => 'http://rubyonrails.com'
+ env = Rack::MockRequest.env_for "/test", "HTTP_HOST" => "localhost", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket", "HTTP_ORIGIN" => "http://rubyonrails.com"
Connection.new(@server, env).tap do |connection|
connection.process
@@ -170,7 +170,7 @@ module ActionCable::StreamTests
end
end
- def receive(connection, command:, identifiers:, channel: 'ActionCable::StreamTests::ChatChannel')
+ def receive(connection, command:, identifiers:, channel: "ActionCable::StreamTests::ChatChannel")
identifier = JSON.generate(channel: channel, **identifiers)
connection.dispatch_websocket_message JSON.generate(command: command, identifier: identifier)
wait_for_async