Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a38c749d
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,发现更多精彩内容 >>
提交
a38c749d
编写于
1月 02, 2009
作者:
Y
Yehuda Katz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sync 'rails/rails/master'
上级
42b32938
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
287 addition
and
376 deletion
+287
-376
actionpack/CHANGELOG
actionpack/CHANGELOG
+4
-0
actionpack/lib/action_controller/dispatcher.rb
actionpack/lib/action_controller/dispatcher.rb
+0
-1
actionpack/lib/action_controller/integration.rb
actionpack/lib/action_controller/integration.rb
+2
-3
actionpack/lib/action_controller/rescue.rb
actionpack/lib/action_controller/rescue.rb
+2
-2
actionpack/lib/action_view/helpers/asset_tag_helper.rb
actionpack/lib/action_view/helpers/asset_tag_helper.rb
+131
-325
actionpack/lib/action_view/helpers/benchmark_helper.rb
actionpack/lib/action_view/helpers/benchmark_helper.rb
+25
-4
actionpack/test/controller/dispatcher_test.rb
actionpack/test/controller/dispatcher_test.rb
+0
-5
actionpack/test/controller/integration_upload_test.rb
actionpack/test/controller/integration_upload_test.rb
+36
-10
actionpack/test/controller/rescue_test.rb
actionpack/test/controller/rescue_test.rb
+7
-0
actionpack/test/fixtures/multipart/hello.txt
actionpack/test/fixtures/multipart/hello.txt
+1
-0
actionpack/test/template/asset_tag_helper_test.rb
actionpack/test/template/asset_tag_helper_test.rb
+20
-2
actionpack/test/template/benchmark_helper_test.rb
actionpack/test/template/benchmark_helper_test.rb
+50
-24
railties/test/console_app_test.rb
railties/test/console_app_test.rb
+9
-0
未找到文件。
actionpack/CHANGELOG
浏览文件 @
a38c749d
*
2.3.0
[
Edge
]*
*
Added
:
silence
option
to
BenchmarkHelper
#
benchmark
and
turned
log_level
into
a
hash
parameter
and
deprecated
the
old
use
[
DHH
]
*
Fixed
the
AssetTagHelper
cache
to
use
the
computed
asset
host
as
part
of
the
cache
key
instead
of
just
assuming
the
its
a
string
#
1299
[
DHH
]
*
Make
ActionController
#
render
(
string
)
work
as
a
shortcut
for
render
:
file
/:
template
/:
action
=>
string
.
[#
1435
]
[
Pratik
Naik
]
Examples
:
#
Instead
of
render
(:
action
=>
'other_action'
)
...
...
actionpack/lib/action_controller/dispatcher.rb
浏览文件 @
a38c749d
...
...
@@ -91,7 +91,6 @@ def reload_application
run_callbacks
:prepare_dispatch
Routing
::
Routes
.
reload
ActionView
::
Helpers
::
AssetTagHelper
::
AssetTag
::
Cache
.
clear
end
# Cleanup the application by clearing out loaded classes so they can
...
...
actionpack/lib/action_controller/integration.rb
浏览文件 @
a38c749d
...
...
@@ -81,8 +81,8 @@ class MultiPartNeededException < Exception
end
# Create and initialize a new Session instance.
def
initialize
(
app
)
@application
=
app
def
initialize
(
app
=
nil
)
@application
=
app
||
ActionController
::
Dispatcher
.
new
reset!
end
...
...
@@ -591,7 +591,6 @@ def reset!
# can use this method to open multiple sessions that ought to be tested
# simultaneously.
def
open_session
(
application
=
nil
)
application
||=
ActionController
::
Dispatcher
.
new
session
=
Integration
::
Session
.
new
(
application
)
# delegate the fixture accessors back to the test instance
...
...
actionpack/lib/action_controller/rescue.rb
浏览文件 @
a38c749d
...
...
@@ -60,8 +60,8 @@ def self.included(base) #:nodoc:
module
ClassMethods
def
call_with_exception
(
env
,
exception
)
#:nodoc:
request
=
env
[
"actioncontroller.rescue.request"
]
response
=
env
[
"actioncontroller.rescue.response"
]
request
=
env
[
"actioncontroller.rescue.request"
]
||=
Request
.
new
(
env
)
response
=
env
[
"actioncontroller.rescue.response"
]
||=
Response
.
new
new
.
process
(
request
,
response
,
:rescue_action
,
exception
)
end
end
...
...
actionpack/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
a38c749d
此差异已折叠。
点击以展开。
actionpack/lib/action_view/helpers/benchmark_helper.rb
浏览文件 @
a38c749d
...
...
@@ -18,12 +18,33 @@ module BenchmarkHelper
# That would add something like "Process data files (345.2ms)" to the log,
# which you can then use to compare timings when optimizing your code.
#
# You may give an optional logger level as the
second argument
# You may give an optional logger level as the
:level option.
# (:debug, :info, :warn, :error); the default value is :info.
def
benchmark
(
message
=
"Benchmarking"
,
level
=
:info
)
#
# <% benchmark "Low-level files", :level => :debug do %>
# <%= lowlevel_files_operation %>
# <% end %>
#
# Finally, you can pass true as the third argument to silence all log activity
# inside the block. This is great for boiling down a noisy block to just a single statement:
#
# <% benchmark "Process data files", :level => :info, :silence => true do %>
# <%= expensive_and_chatty_files_operation %>
# <% end %>
def
benchmark
(
message
=
"Benchmarking"
,
options
=
{})
if
controller
.
logger
ms
=
Benchmark
.
ms
{
yield
}
controller
.
logger
.
send
(
level
,
'%s (%.1fms)'
%
[
message
,
ms
])
if
options
.
is_a?
(
Symbol
)
ActiveSupport
::
Deprecation
.
warn
(
"use benchmark('
#{
message
}
', :level => :
#{
options
}
) instead"
,
caller
)
options
=
{
:level
=>
options
,
:silence
=>
false
}
else
options
.
assert_valid_keys
(
:level
,
:silence
)
options
[
:level
]
||=
:info
end
result
=
nil
ms
=
Benchmark
.
ms
{
result
=
options
[
:silence
]
?
controller
.
logger
.
silence
{
yield
}
:
yield
}
controller
.
logger
.
send
(
options
[
:level
],
'%s (%.1fms)'
%
[
message
,
ms
])
result
else
yield
end
...
...
actionpack/test/controller/dispatcher_test.rb
浏览文件 @
a38c749d
...
...
@@ -32,11 +32,6 @@ def test_reloads_routes_before_dispatch_if_in_loading_mode
dispatch
(
false
)
end
def
test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode
ActionView
::
Helpers
::
AssetTagHelper
::
AssetTag
::
Cache
.
expects
(
:clear
).
once
dispatch
(
false
)
end
def
test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
ActionController
::
Routing
::
Routes
.
expects
(
:reload
).
never
ActiveSupport
::
Dependencies
.
expects
(
:clear
).
never
...
...
actionpack/test/controller/integration_upload_test.rb
浏览文件 @
a38c749d
...
...
@@ -10,6 +10,10 @@ def update
SessionUploadTest
.
last_request_type
=
ActionController
::
Base
.
param_parsers
[
request
.
content_type
]
render
:text
=>
"got here"
end
def
read
render
:text
=>
"File:
#{
params
[
:uploaded_data
].
read
}
"
end
end
class
SessionUploadTest
<
ActionController
::
IntegrationTest
...
...
@@ -19,21 +23,43 @@ class << self
attr_accessor
:last_request_type
end
# def setup
# @session = ActionController::Integration::Session.new
# end
def
test_post_with_upload
uses_mocha
"test_post_with_upload"
do
ActiveSupport
::
Dependencies
.
stubs
(
:load?
).
returns
(
false
)
def
test_upload_and_read_file
with_test_routing
do
post
'/read'
,
:uploaded_data
=>
fixture_file_upload
(
FILES_DIR
+
"/hello.txt"
,
"text/plain"
)
assert_equal
"File: Hello"
,
response
.
body
end
end
# The lint wrapper is used in integration tests
# instead of a normal StringIO class
InputWrapper
=
Rack
::
Lint
::
InputWrapper
def
test_post_with_upload_with_unrewindable_input
InputWrapper
.
any_instance
.
expects
(
:rewind
).
raises
(
Errno
::
ESPIPE
)
with_test_routing
do
post
'/read'
,
:uploaded_data
=>
fixture_file_upload
(
FILES_DIR
+
"/hello.txt"
,
"text/plain"
)
assert_equal
"File: Hello"
,
response
.
body
end
end
def
test_post_with_upload_with_params_parsing
with_test_routing
do
params
=
{
:uploaded_data
=>
fixture_file_upload
(
FILES_DIR
+
"/mona_lisa.jpg"
,
"image/jpg"
)
}
post
'/update'
,
params
,
:location
=>
'blah'
assert_equal
(
:multipart_form
,
SessionUploadTest
.
last_request_type
)
end
end
private
def
with_test_routing
with_routing
do
|
set
|
set
.
draw
do
|
map
|
map
.
update
'update'
,
:controller
=>
"upload_test"
,
:action
=>
"update"
,
:method
=>
:post
map
.
read
'read'
,
:controller
=>
"upload_test"
,
:action
=>
"read"
,
:method
=>
:post
end
params
=
{
:uploaded_data
=>
fixture_file_upload
(
FILES_DIR
+
"/mona_lisa.jpg"
,
"image/jpg"
)
}
post
'/update'
,
params
,
:location
=>
'blah'
assert_equal
(
:multipart_form
,
SessionUploadTest
.
last_request_type
)
yield
end
end
end
end
actionpack/test/controller/rescue_test.rb
浏览文件 @
a38c749d
...
...
@@ -390,6 +390,13 @@ def test_rescue_dispatcher_exceptions
assert_equal
"no way"
,
@response
.
body
end
def
test_rescue_dispatcher_exceptions_without_request_set
@request
.
env
[
'REQUEST_URI'
]
=
'/no_way'
response
=
RescueController
.
call_with_exception
(
@request
.
env
,
ActionController
::
RoutingError
.
new
(
"Route not found"
))
assert_kind_of
ActionController
::
Response
,
response
assert_equal
"no way"
,
response
.
body
end
protected
def
with_all_requests_local
(
local
=
true
)
old_local
,
ActionController
::
Base
.
consider_all_requests_local
=
...
...
actionpack/test/fixtures/multipart/hello.txt
0 → 100644
浏览文件 @
a38c749d
Hello
\ No newline at end of file
actionpack/test/template/asset_tag_helper_test.rb
浏览文件 @
a38c749d
...
...
@@ -38,8 +38,6 @@ def host_with_port() 'localhost' end
@controller
.
request
=
@request
ActionView
::
Helpers
::
AssetTagHelper
::
reset_javascript_include_default
AssetTag
::
Cache
.
clear
AssetCollection
::
Cache
.
clear
end
def
teardown
...
...
@@ -281,6 +279,26 @@ def test_should_not_modify_source_string
assert_equal
copy
,
source
end
def
test_caching_image_path_with_caching_and_proc_asset_host_using_request
ENV
[
'RAILS_ASSET_ID'
]
=
''
ActionController
::
Base
.
asset_host
=
Proc
.
new
do
|
source
,
request
|
if
request
.
ssl?
"
#{
request
.
protocol
}#{
request
.
host_with_port
}
"
else
"
#{
request
.
protocol
}
assets
#{
source
.
length
}
.example.com"
end
end
ActionController
::
Base
.
perform_caching
=
true
@controller
.
request
.
stubs
(
:ssl?
).
returns
(
false
)
assert_equal
"http://assets15.example.com/images/xml.png"
,
image_path
(
"xml.png"
)
@controller
.
request
.
stubs
(
:ssl?
).
returns
(
true
)
assert_equal
"http://localhost/images/xml.png"
,
image_path
(
"xml.png"
)
end
def
test_caching_javascript_include_tag_when_caching_on
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionController
::
Base
.
asset_host
=
'http://a0.example.com'
...
...
actionpack/test/template/benchmark_helper_test.rb
浏览文件 @
a38c749d
...
...
@@ -4,32 +4,25 @@
class
BenchmarkHelperTest
<
ActionView
::
TestCase
tests
ActionView
::
Helpers
::
BenchmarkHelper
class
MockLogger
attr_reader
:logged
def
initialize
@logged
=
[]
end
def
method_missing
(
method
,
*
args
)
@logged
<<
[
method
,
args
]
end
def
teardown
controller
.
logger
.
send
(
:clear_buffer
)
end
def
controller
@controller
||=
Struct
.
new
(
:logger
).
new
(
MockLogger
.
new
)
logger
=
ActiveSupport
::
BufferedLogger
.
new
(
StringIO
.
new
)
logger
.
auto_flushing
=
false
@controller
||=
Struct
.
new
(
:logger
).
new
(
logger
)
end
def
test_without_block
assert_raise
(
LocalJumpError
)
{
benchmark
}
assert
controller
.
logger
.
logged
.
empty?
assert
buffer
.
empty?
end
def
test_defaults
i_was_run
=
false
benchmark
{
i_was_run
=
true
}
assert
i_was_run
assert
1
,
controller
.
logger
.
logged
.
size
assert_last_logged
end
...
...
@@ -37,24 +30,57 @@ def test_with_message
i_was_run
=
false
benchmark
(
'test_run'
)
{
i_was_run
=
true
}
assert
i_was_run
assert
1
,
controller
.
logger
.
logged
.
size
assert_last_logged
'test_run'
end
def
test_with_message_and_level
def
test_with_message_and_
deprecated_
level
i_was_run
=
false
benchmark
(
'debug_run'
,
:debug
)
{
i_was_run
=
true
}
assert_deprecated
do
benchmark
(
'debug_run'
,
:debug
)
{
i_was_run
=
true
}
end
assert
i_was_run
assert
1
,
controller
.
logger
.
logged
.
size
assert_last_logged
'debug_run'
,
:debug
assert_last_logged
'debug_run'
end
def
test_within_level
controller
.
logger
.
level
=
ActiveSupport
::
BufferedLogger
::
DEBUG
benchmark
(
'included_debug_run'
,
:level
=>
:debug
)
{
}
assert_last_logged
'included_debug_run'
end
def
test_outside_level
controller
.
logger
.
level
=
ActiveSupport
::
BufferedLogger
::
ERROR
benchmark
(
'skipped_debug_run'
,
:level
=>
:debug
)
{
}
assert_no_match
(
/skipped_debug_run/
,
buffer
.
last
)
ensure
controller
.
logger
.
level
=
ActiveSupport
::
BufferedLogger
::
DEBUG
end
def
test_without_silencing
benchmark
(
'debug_run'
,
:silence
=>
false
)
do
controller
.
logger
.
info
"not silenced!"
end
assert_equal
2
,
buffer
.
size
end
def
test_with_silencing
benchmark
(
'debug_run'
,
:silence
=>
true
)
do
controller
.
logger
.
info
"silenced!"
end
assert_equal
1
,
buffer
.
size
end
private
def
assert_last_logged
(
message
=
'Benchmarking'
,
level
=
:info
)
last
=
controller
.
logger
.
logged
.
last
assert
2
,
last
.
size
assert_equal
level
,
last
.
first
assert
1
,
last
[
1
].
size
assert
last
[
1
][
0
]
=~
/^
#{
message
}
\(.*\)$/
def
buffer
controller
.
logger
.
send
(
:buffer
)
end
def
assert_last_logged
(
message
=
'Benchmarking'
)
assert
_match
(
/^
#{
message
}
\(.*\)$/
,
buffer
.
last
)
end
end
railties/test/console_app_test.rb
浏览文件 @
a38c749d
...
...
@@ -14,6 +14,15 @@ class ApplicationController < ActionController::Base; end
Test
::
Unit
.
run
=
false
class
ConsoleAppTest
<
Test
::
Unit
::
TestCase
def
test_app_method_should_return_integration_session
assert_nothing_thrown
do
console_session
=
app
assert_not_nil
console_session
assert_instance_of
ActionController
::
Integration
::
Session
,
console_session
end
end
uses_mocha
'console reload test'
do
def
test_reload_should_fire_preparation_callbacks
a
=
b
=
c
=
nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录