aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/channel/base_test.rb40
-rw-r--r--test/test_helper.rb2
2 files changed, 40 insertions, 2 deletions
diff --git a/test/channel/base_test.rb b/test/channel/base_test.rb
index aa31d23297..e7944ff06b 100644
--- a/test/channel/base_test.rb
+++ b/test/channel/base_test.rb
@@ -3,7 +3,22 @@ require 'stubs/test_connection'
require 'stubs/room'
class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
- class ChatChannel < ActionCable::Channel::Base
+ class ActionCable::Channel::Base
+ def kick
+ @last_action = [ :kick ]
+ end
+
+ def topic
+ end
+ end
+
+ class BasicChannel < ActionCable::Channel::Base
+ def chatters
+ @last_action = [ :chatters ]
+ end
+ end
+
+ class ChatChannel < BasicChannel
attr_reader :room, :last_action
on_subscribe :toggle_subscribed
on_unsubscribe :toggle_subscribed
@@ -29,6 +44,10 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
@last_action = [ :speak, data ]
end
+ def topic(data)
+ @last_action = [ :topic, data ]
+ end
+
def subscribed?
@subscribed
end
@@ -87,11 +106,28 @@ class ActionCable::Channel::BaseTest < ActiveSupport::TestCase
assert_equal [ :speak, data ], @channel.last_action
end
- test "try calling a private method" do
+ test "should not dispatch a private method" do
@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
+ 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!" }
+
+ @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
+ assert_equal [ :chatters ], @channel.last_action
+ end
+
test "transmitting data" do
@channel.perform_action 'action' => :get_latest
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 759ea18524..5640178f34 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -10,6 +10,8 @@ Bundler.require :default, :test
require 'puma'
require 'mocha/mini_test'
+require 'rack/mock'
+
require 'action_cable'
ActiveSupport.test_order = :sorted