Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c45e3e74
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c45e3e74
编写于
12月 31, 2018
作者:
G
George Claghorn
提交者:
GitHub
12月 31, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34740 from sponomarev/feature/assert_has_stream
Add streams assert methods to ActionCable channel test case
上级
04d09120
9c8d4850
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
6 deletion
+73
-6
actioncable/lib/action_cable/channel/test_case.rb
actioncable/lib/action_cable/channel/test_case.rb
+45
-4
actioncable/test/channel/test_case_test.rb
actioncable/test/channel/test_case_test.rb
+28
-2
未找到文件。
actioncable/lib/action_cable/channel/test_case.rb
浏览文件 @
c45e3e74
...
...
@@ -84,7 +84,18 @@ def transmit(cable_message)
# assert subscription.confirmed?
#
# # Asserts that the channel subscribes connection to a stream
# assert_equal "chat_1", streams.last
# assert_has_stream "chat_1"
#
# # Asserts that the channel subscribes connection to a specific
# # stream created for a model
# assert_has_stream_for Room.find(1)
# end
#
# def test_does_not_stream_with_incorrect_room_number
# subscribe room_number: -1
#
# # Asserts that not streams was started
# assert_no_streams
# end
#
# def test_does_not_subscribe_without_room_number
...
...
@@ -115,8 +126,6 @@ def transmit(cable_message)
# An instance of the current channel, created when you call `subscribe`.
# <b>transmissions</b>::
# A list of all messages that have been transmitted into the channel.
# <b>streams</b>::
# A list of all created streams subscriptions (as identifiers) for the subscription.
#
#
# == Channel is automatically inferred
...
...
@@ -167,7 +176,6 @@ module Behavior
class_attribute
:_channel_class
attr_reader
:connection
,
:subscription
delegate
:streams
,
to: :subscription
ActiveSupport
.
run_load_hooks
(
:action_cable_channel_test_case
,
self
)
end
...
...
@@ -251,6 +259,39 @@ def assert_broadcast_on(stream_or_object, *args)
super
(
broadcasting_for
(
stream_or_object
),
*
args
)
end
# Asserts that no streams have been started.
#
# def test_assert_no_started_stream
# subscribe
# assert_no_streams
# end
#
def
assert_no_streams
assert
subscription
.
streams
.
empty?
,
"No streams started was expected, but
#{
subscription
.
streams
.
count
}
found"
end
# Asserts that the specified stream has been started.
#
# def test_assert_started_stream
# subscribe
# assert_has_stream 'messages'
# end
#
def
assert_has_stream
(
stream
)
assert
subscription
.
streams
.
include?
(
stream
),
"Stream
#{
stream
}
has not been started"
end
# Asserts that the specified stream for a model has started.
#
# def test_assert_started_stream_for
# subscribe id: 42
# assert_has_stream_for User.find(42)
# end
#
def
assert_has_stream_for
(
object
)
assert_has_stream
(
broadcasting_for
(
object
))
end
private
def
check_subscribed!
raise
"Must be subscribed!"
if
subscription
.
nil?
||
subscription
.
rejected?
...
...
actioncable/test/channel/test_case_test.rb
浏览文件 @
c45e3e74
...
...
@@ -93,13 +93,39 @@ class StreamsTestChannelTest < ActionCable::Channel::TestCase
def
test_stream_without_params
subscribe
assert_
equal
"test_0"
,
streams
.
last
assert_
has_stream
"test_0"
end
def
test_stream_with_params
subscribe
id:
42
assert_equal
"test_42"
,
streams
.
last
assert_has_stream
"test_42"
end
end
class
StreamsForTestChannel
<
ActionCable
::
Channel
::
Base
def
subscribed
stream_for
User
.
new
(
params
[
:id
])
end
end
class
StreamsForTestChannelTest
<
ActionCable
::
Channel
::
TestCase
def
test_stream_with_params
subscribe
id:
42
assert_has_stream_for
User
.
new
(
42
)
end
end
class
NoStreamsTestChannel
<
ActionCable
::
Channel
::
Base
def
subscribed
;
end
# no-op
end
class
NoStreamsTestChannelTest
<
ActionCable
::
Channel
::
TestCase
def
test_stream_with_params
subscribe
assert_no_streams
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录