Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b9825801
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,发现更多精彩内容 >>
提交
b9825801
编写于
8月 24, 2015
作者:
K
Kasper Timm Hansen
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21321 from rodzyn/removing_mocha
Get rid of mocha tests in actionpack - part 1
上级
a256a579
3a161e65
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
103 addition
and
78 deletion
+103
-78
actionpack/test/abstract/translation_test.rb
actionpack/test/abstract/translation_test.rb
+15
-7
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+1
-0
actionpack/test/controller/render_test.rb
actionpack/test/controller/render_test.rb
+4
-4
actionpack/test/controller/request_forgery_protection_test.rb
...onpack/test/controller/request_forgery_protection_test.rb
+46
-33
actionpack/test/controller/test_case_test.rb
actionpack/test/controller/test_case_test.rb
+10
-8
actionpack/test/dispatch/cookies_test.rb
actionpack/test/dispatch/cookies_test.rb
+3
-1
actionpack/test/dispatch/exception_wrapper_test.rb
actionpack/test/dispatch/exception_wrapper_test.rb
+0
-2
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+5
-6
actionpack/test/dispatch/session/cookie_store_test.rb
actionpack/test/dispatch/session/cookie_store_test.rb
+18
-14
actionpack/test/dispatch/test_request_test.rb
actionpack/test/dispatch/test_request_test.rb
+1
-3
未找到文件。
actionpack/test/abstract/translation_test.rb
浏览文件 @
b9825801
...
...
@@ -24,7 +24,6 @@ def setup
},
},
})
@controller
.
stubs
(
action_name: :index
)
end
def
test_action_controller_base_responds_to_translate
...
...
@@ -44,26 +43,35 @@ def test_action_controller_base_responds_to_l
end
def
test_lazy_lookup
@controller
.
stub
:action_name
,
:index
do
assert_equal
'bar'
,
@controller
.
t
(
'.foo'
)
end
end
def
test_lazy_lookup_with_symbol
@controller
.
stub
:action_name
,
:index
do
assert_equal
'bar'
,
@controller
.
t
(
:'.foo'
)
end
end
def
test_lazy_lookup_fallback
@controller
.
stub
:action_name
,
:index
do
assert_equal
'no_action_tr'
,
@controller
.
t
(
:'.no_action'
)
end
end
def
test_default_translation
@controller
.
stub
:action_name
,
:index
do
assert_equal
'bar'
,
@controller
.
t
(
'one.two'
)
end
end
def
test_localize
time
,
expected
=
Time
.
gm
(
2000
),
'Sat, 01 Jan 2000 00:00:00 +0000'
I18n
.
stub
s
(
:localize
).
with
(
time
).
returns
(
expected
)
I18n
.
stub
:localize
,
expected
do
assert_equal
expected
,
@controller
.
l
(
time
)
end
end
end
end
end
actionpack/test/abstract_unit.rb
浏览文件 @
b9825801
...
...
@@ -397,6 +397,7 @@ def jruby_skip(message = '')
end
require
'mocha/setup'
# FIXME: stop using mocha
require
'minitest/mock'
class
ForkingExecutor
class
Server
...
...
actionpack/test/controller/render_test.rb
浏览文件 @
b9825801
require
'abstract_unit'
require
'controller/fake_models'
require
'pathname'
class
TestControllerWithExtraEtags
<
ActionController
::
Base
etag
{
nil
}
...
...
@@ -295,10 +294,11 @@ def test_render_nothing_deprecated
def
test_date_header_when_expires_in
time
=
Time
.
mktime
(
2011
,
10
,
30
)
Time
.
stub
s
(
:now
).
returns
(
time
)
Time
.
stub
:now
,
time
do
get
:conditional_hello_with_expires_in
assert_equal
Time
.
now
.
httpdate
,
@response
.
headers
[
"Date"
]
end
end
end
class
LastModifiedRenderTest
<
ActionController
::
TestCase
...
...
actionpack/test/controller/request_forgery_protection_test.rb
浏览文件 @
b9825801
require
'abstract_unit'
require
'digest/sha1'
require
"active_support/log_subscriber/test_helper"
# common controller actions
...
...
@@ -133,7 +132,6 @@ def form_authenticity_param
module
RequestForgeryProtectionTests
def
setup
@token
=
"cf50faa3fe97702ca1ae"
@controller
.
stubs
(
:form_authenticity_token
).
returns
(
@token
)
@controller
.
stubs
(
:valid_authenticity_token?
).
with
{
|
_
,
t
|
t
==
@token
}.
returns
(
true
)
@controller
.
stubs
(
:valid_authenticity_token?
).
with
{
|
_
,
t
|
t
!=
@token
}.
returns
(
false
)
@old_request_forgery_protection_token
=
ActionController
::
Base
.
request_forgery_protection_token
...
...
@@ -145,18 +143,22 @@ def teardown
end
def
test_should_render_form_with_token_tag
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
do
get
:index
end
assert_select
'form>input[name=?][value=?]'
,
'custom_authenticity_token'
,
@token
end
end
def
test_should_render_button_to_with_token_tag
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
do
get
:show_button
end
assert_select
'form>input[name=?][value=?]'
,
'custom_authenticity_token'
,
@token
end
end
def
test_should_render_form_without_token_tag_if_remote
assert_not_blocked
do
...
...
@@ -199,18 +201,22 @@ def test_should_render_form_with_token_tag_if_remote_and_external_authenticity_t
end
def
test_should_render_form_with_token_tag_if_remote_and_authenticity_token_requested
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
do
get
:form_for_remote_with_token
end
assert_select
'form>input[name=?][value=?]'
,
'custom_authenticity_token'
,
@token
end
end
def
test_should_render_form_with_token_tag_with_authenticity_token_requested
@controller
.
stub
:form_authenticity_token
,
@token
do
assert_not_blocked
do
get
:form_for_with_token
end
assert_select
'form>input[name=?][value=?]'
,
'custom_authenticity_token'
,
@token
end
end
def
test_should_allow_get
assert_not_blocked
{
get
:index
}
...
...
@@ -402,12 +408,13 @@ class RequestForgeryProtectionControllerUsingResetSessionTest < ActionController
end
test
'should emit a csrf-param meta tag and a csrf-token meta tag'
do
@controller
.
stub
s
(
:form_authenticity_token
).
returns
(
@token
+
'<=?'
)
@controller
.
stub
:form_authenticity_token
,
@token
+
'<=?'
do
get
:meta
assert_select
'meta[name=?][content=?]'
,
'csrf-param'
,
'custom_authenticity_token'
assert_select
'meta[name=?]'
,
'csrf-token'
assert_match
(
/cf50faa3fe97702ca1ae<=\?/
,
@response
.
body
)
end
end
end
class
RequestForgeryProtectionControllerUsingNullSessionTest
<
ActionController
::
TestCase
...
...
@@ -485,31 +492,37 @@ class FreeCookieControllerTest < ActionController::TestCase
def
setup
@controller
=
FreeCookieController
.
new
@token
=
"cf50faa3fe97702ca1ae"
SecureRandom
.
stubs
(
:base64
).
returns
(
@token
)
super
end
def
test_should_not_render_form_with_token_tag
SecureRandom
.
stub
:base64
,
@token
do
get
:index
assert_select
'form>div>input[name=?][value=?]'
,
'authenticity_token'
,
@token
,
false
end
end
def
test_should_not_render_button_to_with_token_tag
SecureRandom
.
stub
:base64
,
@token
do
get
:show_button
assert_select
'form>div>input[name=?][value=?]'
,
'authenticity_token'
,
@token
,
false
end
end
def
test_should_allow_all_methods_without_token
SecureRandom
.
stub
:base64
,
@token
do
[
:post
,
:patch
,
:put
,
:delete
].
each
do
|
method
|
assert_nothing_raised
{
send
(
method
,
:index
)}
end
end
end
test
'should not emit a csrf-token meta tag'
do
SecureRandom
.
stub
:base64
,
@token
do
get
:meta
assert
@response
.
body
.
blank?
end
end
end
class
CustomAuthenticityParamControllerTest
<
ActionController
::
TestCase
...
...
@@ -529,11 +542,11 @@ def teardown
def
test_should_not_warn_if_form_authenticity_param_matches_form_authenticity_token
ActionController
::
Base
.
logger
=
@logger
@controller
.
stubs
(
:valid_authenticity_token?
).
returns
(
:true
)
begin
@controller
.
stub
:valid_authenticity_token?
,
:true
do
post
:index
,
params:
{
custom_token_name:
'foobar'
}
assert_equal
0
,
@logger
.
logged
(
:warn
).
size
end
ensure
ActionController
::
Base
.
logger
=
@old_logger
end
...
...
actionpack/test/controller/test_case_test.rb
浏览文件 @
b9825801
...
...
@@ -4,6 +4,8 @@
require
'rails/engine'
class
TestCaseTest
<
ActionController
::
TestCase
def
self
.
fixture_path
;
end
;
class
TestController
<
ActionController
::
Base
def
no_op
render
plain:
'dummy'
...
...
@@ -849,11 +851,11 @@ def test_test_uploaded_file
end
def
test_fixture_path_is_accessed_from_self_instead_of_active_support_test_case
TestCaseTest
.
stubs
(
:fixture_path
).
returns
(
FILES_DIR
)
TestCaseTest
.
stub
:fixture_path
,
FILES_DIR
do
uploaded_file
=
fixture_file_upload
(
'/mona_lisa.jpg'
,
'image/png'
)
assert_equal
File
.
open
(
"
#{
FILES_DIR
}
/mona_lisa.jpg"
,
READ_PLAIN
).
read
,
uploaded_file
.
read
end
end
def
test_test_uploaded_file_with_binary
filename
=
'mona_lisa.jpg'
...
...
@@ -893,13 +895,13 @@ def test_fixture_file_upload
end
def
test_fixture_file_upload_relative_to_fixture_path
TestCaseTest
.
stub
s
(
:fixture_path
).
returns
(
FILES_DIR
)
TestCaseTest
.
stub
:fixture_path
,
FILES_DIR
do
uploaded_file
=
fixture_file_upload
(
"mona_lisa.jpg"
,
"image/jpg"
)
assert_equal
File
.
open
(
"
#{
FILES_DIR
}
/mona_lisa.jpg"
,
READ_PLAIN
).
read
,
uploaded_file
.
read
end
end
def
test_fixture_file_upload_ignores_nil_fixture_path
TestCaseTest
.
stubs
(
:fixture_path
).
returns
(
nil
)
uploaded_file
=
fixture_file_upload
(
"
#{
FILES_DIR
}
/mona_lisa.jpg"
,
"image/jpg"
)
assert_equal
File
.
open
(
"
#{
FILES_DIR
}
/mona_lisa.jpg"
,
READ_PLAIN
).
read
,
uploaded_file
.
read
end
...
...
actionpack/test/dispatch/cookies_test.rb
浏览文件 @
b9825801
...
...
@@ -321,10 +321,12 @@ def test_setting_cookie_with_secure
end
def
test_setting_cookie_with_secure_when_always_write_cookie_is_true
ActionDispatch
::
Cookies
::
CookieJar
.
any_instance
.
stubs
(
:always_write_cookie
).
returns
(
true
)
old_cookie
,
@request
.
cookie_jar
.
always_write_cookie
=
@request
.
cookie_jar
.
always_write_cookie
,
true
get
:authenticate_with_secure
assert_cookie_header
"user_name=david; path=/; secure"
assert_equal
({
"user_name"
=>
"david"
},
@response
.
cookies
)
ensure
@request
.
cookie_jar
.
always_write_cookie
=
old_cookie
end
def
test_not_setting_cookie_with_secure
...
...
actionpack/test/dispatch/exception_wrapper_test.rb
浏览文件 @
b9825801
...
...
@@ -17,8 +17,6 @@ def backtrace
end
setup
do
Rails
.
stubs
(
:root
).
returns
(
Pathname
.
new
(
'.'
))
@cleaner
=
ActiveSupport
::
BacktraceCleaner
.
new
@cleaner
.
add_silencer
{
|
line
|
line
!~
/^lib/
}
end
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
b9825801
# encoding: UTF-8
require
'erb'
require
'abstract_unit'
require
'controller/fake_controllers'
...
...
@@ -4190,12 +4189,12 @@ def app; APP end
include
Routes
.
url_helpers
test
"url helpers do not ignore nil parameters when using non-optimized routes"
do
Routes
.
stubs
(
:optimize_routes_generation?
).
returns
(
false
)
Routes
.
stub
:optimize_routes_generation?
,
false
do
get
"/categories/1"
assert_response
:success
assert_raises
(
ActionController
::
UrlGenerationError
)
{
product_path
(
nil
)
}
end
end
end
class
TestUrlConstraints
<
ActionDispatch
::
IntegrationTest
...
...
actionpack/test/dispatch/session/cookie_store_test.rb
浏览文件 @
b9825801
...
...
@@ -274,7 +274,9 @@ def test_session_store_with_expire_after
with_test_route_set
(
:expire_after
=>
5
.
hours
)
do
# First request accesses the session
time
=
Time
.
local
(
2008
,
4
,
24
)
Time
.
stubs
(
:now
).
returns
(
time
)
cookie_body
=
nil
Time
.
stub
:now
,
time
do
expected_expiry
=
(
time
+
5
.
hours
).
gmtime
.
strftime
(
"%a, %d %b %Y %H:%M:%S -0000"
)
cookies
[
SessionKey
]
=
SignedBar
...
...
@@ -285,10 +287,11 @@ def test_session_store_with_expire_after
cookie_body
=
response
.
body
assert_equal
"_myapp_session=
#{
cookie_body
}
; path=/; expires=
#{
expected_expiry
}
; HttpOnly"
,
headers
[
'Set-Cookie'
]
end
# Second request does not access the session
time
=
Time
.
local
(
2008
,
4
,
25
)
Time
.
stub
s
(
:now
).
returns
(
time
)
Time
.
stub
:now
,
time
do
expected_expiry
=
(
time
+
5
.
hours
).
gmtime
.
strftime
(
"%a, %d %b %Y %H:%M:%S -0000"
)
get
'/no_session_access'
...
...
@@ -298,6 +301,7 @@ def test_session_store_with_expire_after
headers
[
'Set-Cookie'
]
end
end
end
def
test_session_store_with_explicit_domain
with_test_route_set
(
:domain
=>
"example.es"
)
do
...
...
actionpack/test/dispatch/test_request_test.rb
浏览文件 @
b9825801
...
...
@@ -53,10 +53,8 @@ class TestRequestTest < ActiveSupport::TestCase
assert_cookies
({
"user_name"
=>
"david"
},
req
.
cookie_jar
)
end
test
"does not complain when Rails.application is nil"
do
Rails
.
stubs
(
:application
).
returns
(
nil
)
test
"does not complain when there is no application config"
do
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
false
,
req
.
env
.
empty?
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录