Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3875f5fc
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,发现更多精彩内容 >>
未验证
提交
3875f5fc
编写于
5月 31, 2018
作者:
R
Rafael França
提交者:
GitHub
5月 31, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33034 from utilum/remove_mocha_from_action_cable
Remove mocha from action cable
上级
565ce0ea
76f14043
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
120 addition
and
52 deletion
+120
-52
actioncable/test/channel/base_test.rb
actioncable/test/channel/base_test.rb
+7
-5
actioncable/test/channel/broadcasting_test.rb
actioncable/test/channel/broadcasting_test.rb
+13
-2
actioncable/test/channel/periodic_timers_test.rb
actioncable/test/channel/periodic_timers_test.rb
+19
-5
actioncable/test/channel/rejection_test.rb
actioncable/test/channel/rejection_test.rb
+26
-13
actioncable/test/channel/stream_test.rb
actioncable/test/channel/stream_test.rb
+32
-13
actioncable/test/connection/client_socket_test.rb
actioncable/test/connection/client_socket_test.rb
+4
-3
actioncable/test/connection/identifier_test.rb
actioncable/test/connection/identifier_test.rb
+8
-5
actioncable/test/connection/stream_test.rb
actioncable/test/connection/stream_test.rb
+6
-4
actioncable/test/stubs/test_adapter.rb
actioncable/test/stubs/test_adapter.rb
+4
-0
actioncable/test/stubs/test_connection.rb
actioncable/test/stubs/test_connection.rb
+1
-1
actioncable/test/test_helper.rb
actioncable/test/test_helper.rb
+0
-1
未找到文件。
actioncable/test/channel/base_test.rb
浏览文件 @
3875f5fc
# frozen_string_literal: true
require
"test_helper"
require
"minitest/mock"
require
"stubs/test_connection"
require
"stubs/room"
...
...
@@ -226,12 +227,13 @@ def rm_rf
events
<<
ActiveSupport
::
Notifications
::
Event
.
new
(
*
args
)
end
@channel
.
stub
s
(
:subscription_confirmation_sent?
).
returns
(
false
)
@channel
.
send
(
:transmit_subscription_confirmation
)
@channel
.
stub
(
:subscription_confirmation_sent?
,
false
)
do
@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
1
,
events
.
length
assert_equal
"transmit_subscription_confirmation.action_cable"
,
events
[
0
].
name
assert_equal
"ActionCable::Channel::BaseTest::ChatChannel"
,
events
[
0
].
payload
[
:channel_class
]
end
ensure
ActiveSupport
::
Notifications
.
unsubscribe
"transmit_subscription_confirmation.action_cable"
end
...
...
actioncable/test/channel/broadcasting_test.rb
浏览文件 @
3875f5fc
# frozen_string_literal: true
require
"test_helper"
require
"active_support/testing/method_call_assertions"
require
"stubs/test_connection"
require
"stubs/room"
class
ActionCable::Channel::BroadcastingTest
<
ActiveSupport
::
TestCase
include
ActiveSupport
::
Testing
::
MethodCallAssertions
class
ChatChannel
<
ActionCable
::
Channel
::
Base
end
...
...
@@ -13,8 +16,16 @@ class ChatChannel < ActionCable::Channel::Base
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"
)
}
ChatChannel
.
broadcast_to
(
Room
.
new
(
1
),
"Hello World"
)
assert_called_with
(
ActionCable
.
server
,
:broadcast
,
[
"action_cable:channel:broadcasting_test:chat:Room#1-Campfire"
,
"Hello World"
]
)
do
ChatChannel
.
broadcast_to
(
Room
.
new
(
1
),
"Hello World"
)
end
end
test
"broadcasting_for with an object"
do
...
...
actioncable/test/channel/periodic_timers_test.rb
浏览文件 @
3875f5fc
...
...
@@ -4,8 +4,11 @@
require
"stubs/test_connection"
require
"stubs/room"
require
"active_support/time"
require
"active_support/testing/method_call_assertions"
class
ActionCable::Channel::PeriodicTimersTest
<
ActiveSupport
::
TestCase
include
ActiveSupport
::
Testing
::
MethodCallAssertions
class
ChatChannel
<
ActionCable
::
Channel
::
Base
# Method name arg
periodically
:send_updates
,
every:
1
...
...
@@ -64,11 +67,22 @@ def ping
end
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
mock
=
Minitest
::
Mock
.
new
3
.
times
{
mock
.
expect
(
:shutdown
,
nil
)
}
assert_called
(
@connection
.
server
.
event_loop
,
:timer
,
times:
3
,
returns:
mock
)
do
channel
=
ChatChannel
.
new
@connection
,
"{id: 1}"
,
id:
1
channel
.
subscribe_to_channel
channel
.
unsubscribe_from_channel
assert_equal
[],
channel
.
send
(
:active_periodic_timers
)
end
channel
.
subscribe_to_channel
channel
.
unsubscribe_from_channel
assert_equal
[],
channel
.
send
(
:active_periodic_timers
)
assert
mock
.
verify
end
end
actioncable/test/channel/rejection_test.rb
浏览文件 @
3875f5fc
# frozen_string_literal: true
require
"test_helper"
require
"minitest/mock"
require
"stubs/test_connection"
require
"stubs/room"
...
...
@@ -20,24 +21,36 @@ def secret_action
end
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
.
subscribe_to_channel
subscriptions
=
Minitest
::
Mock
.
new
subscriptions
.
expect
(
:remove_subscription
,
SecretChannel
,
[
SecretChannel
])
expected
=
{
"identifier"
=>
"{id: 1}"
,
"type"
=>
"reject_subscription"
}
assert_equal
expected
,
@connection
.
last_transmission
@connection
.
stub
(
:subscriptions
,
subscriptions
)
do
@channel
=
SecretChannel
.
new
@connection
,
"{id: 1}"
,
id:
1
@channel
.
subscribe_to_channel
expected
=
{
"identifier"
=>
"{id: 1}"
,
"type"
=>
"reject_subscription"
}
assert_equal
expected
,
@connection
.
last_transmission
end
assert
subscriptions
.
verify
end
test
"does not execute action if subscription is rejected"
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
.
subscribe_to_channel
subscriptions
=
Minitest
::
Mock
.
new
subscriptions
.
expect
(
:remove_subscription
,
SecretChannel
,
[
SecretChannel
])
expected
=
{
"identifier"
=>
"{id: 1}"
,
"type"
=>
"reject_subscription"
}
assert_equal
expected
,
@connection
.
last_transmission
assert_equal
1
,
@connection
.
transmissions
.
size
@connection
.
stub
(
:subscriptions
,
subscriptions
)
do
@channel
=
SecretChannel
.
new
@connection
,
"{id: 1}"
,
id:
1
@channel
.
subscribe_to_channel
expected
=
{
"identifier"
=>
"{id: 1}"
,
"type"
=>
"reject_subscription"
}
assert_equal
expected
,
@connection
.
last_transmission
assert_equal
1
,
@connection
.
transmissions
.
size
@channel
.
perform_action
(
"action"
=>
:secret_action
)
assert_equal
1
,
@connection
.
transmissions
.
size
end
@channel
.
perform_action
(
"action"
=>
:secret_action
)
assert_equal
1
,
@connection
.
transmissions
.
size
assert
subscriptions
.
verify
end
end
actioncable/test/channel/stream_test.rb
浏览文件 @
3875f5fc
...
...
@@ -2,6 +2,7 @@
require
"test_helper"
require
"active_support/testing/method_call_assertions"
require
"minitest/mock"
require
"stubs/test_connection"
require
"stubs/room"
...
...
@@ -54,40 +55,58 @@ class StreamTest < ActionCable::TestCase
test
"streaming start and stop"
do
run_in_eventmachine
do
connection
=
TestConnection
.
new
connection
.
pubsub
.
expects
(
:subscribe
).
with
(
"test_room_1"
,
kind_of
(
Proc
),
kind_of
(
Proc
))
channel
=
ChatChannel
.
new
connection
,
"{id: 1}"
,
id:
1
channel
.
subscribe_to_channel
pubsub
=
Minitest
::
Mock
.
new
connection
.
pubsub
wait_for_async
pubsub
.
expect
(
:subscribe
,
nil
,
[
"test_room_1"
,
Proc
,
Proc
])
pubsub
.
expect
(
:unsubscribe
,
nil
,
[
"test_room_1"
,
Proc
])
connection
.
stub
(
:pubsub
,
pubsub
)
do
channel
=
ChatChannel
.
new
connection
,
"{id: 1}"
,
id:
1
channel
.
subscribe_to_channel
connection
.
pubsub
.
expects
(
:unsubscribe
)
channel
.
unsubscribe_from_channel
wait_for_async
channel
.
unsubscribe_from_channel
end
assert
pubsub
.
verify
end
end
test
"stream from non-string channel"
do
run_in_eventmachine
do
connection
=
TestConnection
.
new
connection
.
pubsub
.
expects
(
:subscribe
).
with
(
"channel"
,
kind_of
(
Proc
),
kind_of
(
Proc
))
pubsub
=
Minitest
::
Mock
.
new
connection
.
pubsub
channel
=
SymbolChannel
.
new
connection
,
""
channel
.
subscribe_to_channel
pubsub
.
expect
(
:subscribe
,
nil
,
[
"channel"
,
Proc
,
Proc
])
pubsub
.
expect
(
:unsubscribe
,
nil
,
[
"channel"
,
Proc
])
wait_for_async
connection
.
stub
(
:pubsub
,
pubsub
)
do
channel
=
SymbolChannel
.
new
connection
,
""
channel
.
subscribe_to_channel
wait_for_async
channel
.
unsubscribe_from_channel
end
connection
.
pubsub
.
expects
(
:unsubscribe
)
channel
.
unsubscribe_from_channel
assert
pubsub
.
verify
end
end
test
"stream_for"
do
run_in_eventmachine
do
connection
=
TestConnection
.
new
connection
.
pubsub
.
expects
(
:subscribe
).
with
(
"action_cable:stream_tests:chat:Room#1-Campfire"
,
kind_of
(
Proc
),
kind_of
(
Proc
))
channel
=
ChatChannel
.
new
connection
,
""
channel
.
subscribe_to_channel
channel
.
stream_for
Room
.
new
(
1
)
wait_for_async
pubsub_call
=
channel
.
pubsub
.
class
.
class_variable_get
"@@subscribe_called"
assert_equal
"action_cable:stream_tests:chat:Room#1-Campfire"
,
pubsub_call
[
:channel
]
assert_instance_of
Proc
,
pubsub_call
[
:callback
]
assert_instance_of
Proc
,
pubsub_call
[
:success_callback
]
end
end
...
...
actioncable/test/connection/client_socket_test.rb
浏览文件 @
3875f5fc
...
...
@@ -43,10 +43,11 @@ def on_error(message)
# Internal hax = :(
client
=
connection
.
websocket
.
send
(
:websocket
)
client
.
instance_variable_get
(
"@stream"
).
expects
(
:write
).
raises
(
"foo"
)
client
.
instance_variable_get
(
"@stream"
).
stub
(
:write
,
proc
{
raise
"foo"
})
do
assert_not_called
(
client
,
:client_gone
)
do
client
.
write
(
"boo"
)
assert_not_called
(
client
,
:client_gone
)
do
client
.
write
(
"boo"
)
end
end
assert_equal
%w[ foo ]
,
connection
.
errors
end
...
...
actioncable/test/connection/identifier_test.rb
浏览文件 @
3875f5fc
...
...
@@ -30,13 +30,16 @@ def connect
run_in_eventmachine
do
server
=
TestServer
.
new
server
.
pubsub
.
expects
(
:subscribe
)
.
with
(
"action_cable/User#lifo"
,
kind_of
(
Proc
))
server
.
pubsub
.
expects
(
:unsubscribe
)
.
with
(
"action_cable/User#lifo"
,
kind_of
(
Proc
))
open_connection
(
server
)
close_connection
wait_for_async
%w[subscribe unsubscribe]
.
each
do
|
method
|
pubsub_call
=
server
.
pubsub
.
class
.
class_variable_get
"@@
#{
method
}
_called"
assert_equal
"action_cable/User#lifo"
,
pubsub_call
[
:channel
]
assert_instance_of
Proc
,
pubsub_call
[
:callback
]
end
end
end
...
...
actioncable/test/connection/stream_test.rb
浏览文件 @
3875f5fc
...
...
@@ -2,6 +2,7 @@
require
"test_helper"
require
"active_support/testing/method_call_assertions"
require
"minitest/mock"
require
"stubs/test_server"
class
ActionCable::Connection::StreamTest
<
ActionCable
::
TestCase
...
...
@@ -44,10 +45,11 @@ def on_error(message)
# Internal hax = :(
client
=
connection
.
websocket
.
send
(
:websocket
)
client
.
instance_variable_get
(
"@stream"
).
instance_variable_get
(
"@rack_hijack_io"
).
expects
(
:write
).
raises
(
closed_exception
,
"foo"
)
assert_called
(
client
,
:client_gone
)
do
client
.
write
(
"boo"
)
rack_hijack_io
=
client
.
instance_variable_get
(
"@stream"
).
instance_variable_get
(
"@rack_hijack_io"
)
rack_hijack_io
.
stub
(
:write
,
proc
{
raise
(
closed_exception
,
"foo"
)
})
do
assert_called
(
client
,
:client_gone
)
do
client
.
write
(
"boo"
)
end
end
assert_equal
[],
connection
.
errors
end
...
...
actioncable/test/stubs/test_adapter.rb
浏览文件 @
3875f5fc
# frozen_string_literal: true
class
SuccessAdapter
<
ActionCable
::
SubscriptionAdapter
::
Base
class
<<
self
;
attr_accessor
:subscribe_called
,
:unsubscribe_called
end
def
broadcast
(
channel
,
payload
)
end
def
subscribe
(
channel
,
callback
,
success_callback
=
nil
)
@@subscribe_called
=
{
channel:
channel
,
callback:
callback
,
success_callback:
success_callback
}
end
def
unsubscribe
(
channel
,
callback
)
@@unsubscribe_called
=
{
channel:
channel
,
callback:
callback
}
end
end
actioncable/test/stubs/test_connection.rb
浏览文件 @
3875f5fc
...
...
@@ -3,7 +3,7 @@
require
"stubs/user"
class
TestConnection
attr_reader
:identifiers
,
:logger
,
:current_user
,
:server
,
:transmissions
attr_reader
:identifiers
,
:logger
,
:current_user
,
:server
,
:
subscriptions
,
:
transmissions
delegate
:pubsub
,
to: :server
...
...
actioncable/test/test_helper.rb
浏览文件 @
3875f5fc
...
...
@@ -4,7 +4,6 @@
require
"active_support/testing/autorun"
require
"puma"
require
"mocha/minitest"
require
"rack/mock"
begin
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录