Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
da5978c2
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,体验更适合开发者的 AI 搜索 >>
提交
da5978c2
编写于
1月 13, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add subscriber for ActionPack and move all logging inside it.
上级
8d78a82d
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
378 addition
and
182 deletion
+378
-182
actionpack/lib/action_controller.rb
actionpack/lib/action_controller.rb
+1
-1
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+4
-1
actionpack/lib/action_controller/caching.rb
actionpack/lib/action_controller/caching.rb
+0
-11
actionpack/lib/action_controller/metal/filter_parameter_logging.rb
...k/lib/action_controller/metal/filter_parameter_logging.rb
+3
-14
actionpack/lib/action_controller/metal/instrumentation.rb
actionpack/lib/action_controller/metal/instrumentation.rb
+77
-0
actionpack/lib/action_controller/metal/redirecting.rb
actionpack/lib/action_controller/metal/redirecting.rb
+0
-2
actionpack/lib/action_controller/metal/streaming.rb
actionpack/lib/action_controller/metal/streaming.rb
+0
-4
actionpack/lib/action_controller/railtie.rb
actionpack/lib/action_controller/railtie.rb
+3
-8
actionpack/lib/action_controller/railties/subscriber.rb
actionpack/lib/action_controller/railties/subscriber.rb
+62
-0
actionpack/lib/action_view/railtie.rb
actionpack/lib/action_view/railtie.rb
+10
-1
actionpack/lib/action_view/railties/subscriber.rb
actionpack/lib/action_view/railties/subscriber.rb
+24
-0
actionpack/lib/action_view/template/text.rb
actionpack/lib/action_view/template/text.rb
+1
-1
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+0
-26
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+0
-14
actionpack/test/controller/filter_params_test.rb
actionpack/test/controller/filter_params_test.rb
+0
-12
actionpack/test/controller/logging_test.rb
actionpack/test/controller/logging_test.rb
+0
-81
actionpack/test/controller/subscriber_test.rb
actionpack/test/controller/subscriber_test.rb
+108
-0
actionpack/test/template/subscriber_test.rb
actionpack/test/template/subscriber_test.rb
+74
-0
activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
...d/lib/active_record/connection_adapters/sqlite_adapter.rb
+1
-1
activerecord/lib/active_record/railties/subscriber.rb
activerecord/lib/active_record/railties/subscriber.rb
+1
-1
activerecord/test/cases/subscriber_test.rb
activerecord/test/cases/subscriber_test.rb
+2
-2
activesupport/lib/active_support/deprecation/behaviors.rb
activesupport/lib/active_support/deprecation/behaviors.rb
+1
-1
railties/lib/rails/subscriber/test_helper.rb
railties/lib/rails/subscriber/test_helper.rb
+6
-1
未找到文件。
actionpack/lib/action_controller.rb
浏览文件 @
da5978c2
...
@@ -23,7 +23,7 @@ module ActionController
...
@@ -23,7 +23,7 @@ module ActionController
autoload
:Helpers
autoload
:Helpers
autoload
:HideActions
autoload
:HideActions
autoload
:HttpAuthentication
autoload
:HttpAuthentication
autoload
:
Logger
autoload
:
Instrumentation
autoload
:MimeResponds
autoload
:MimeResponds
autoload
:RackDelegation
autoload
:RackDelegation
autoload
:Redirecting
autoload
:Redirecting
...
...
actionpack/lib/action_controller/base.rb
浏览文件 @
da5978c2
...
@@ -15,7 +15,6 @@ class Base < Metal
...
@@ -15,7 +15,6 @@ class Base < Metal
include
ActionController
::
Renderers
::
All
include
ActionController
::
Renderers
::
All
include
ActionController
::
ConditionalGet
include
ActionController
::
ConditionalGet
include
ActionController
::
RackDelegation
include
ActionController
::
RackDelegation
include
ActionController
::
Logger
include
ActionController
::
Configuration
include
ActionController
::
Configuration
# Legacy modules
# Legacy modules
...
@@ -36,6 +35,10 @@ class Base < Metal
...
@@ -36,6 +35,10 @@ class Base < Metal
include
ActionController
::
FilterParameterLogging
include
ActionController
::
FilterParameterLogging
include
ActionController
::
Translation
include
ActionController
::
Translation
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
include
ActionController
::
Instrumentation
# TODO: Extract into its own module
# TODO: Extract into its own module
# This should be moved together with other normalizing behavior
# This should be moved together with other normalizing behavior
module
ImplicitRender
module
ImplicitRender
...
...
actionpack/lib/action_controller/caching.rb
浏览文件 @
da5978c2
...
@@ -60,17 +60,6 @@ module ClassMethods
...
@@ -60,17 +60,6 @@ module ClassMethods
def
cache_configured?
def
cache_configured?
perform_caching
&&
cache_store
perform_caching
&&
cache_store
end
end
def
log_event
(
name
,
before
,
after
,
instrumenter_id
,
payload
)
if
name
.
to_s
=~
/action_controller\.((read|write|expire|exist)_(fragment|page)\??)/
key_or_path
=
payload
[
:key
]
||
payload
[
:path
]
human_name
=
$1
.
humanize
duration
=
(
after
-
before
)
*
1000
logger
.
info
(
"
#{
human_name
}
#{
key_or_path
.
inspect
}
(%.1fms)"
%
duration
)
else
super
end
end
end
end
def
caching_allowed?
def
caching_allowed?
...
...
actionpack/lib/action_controller/metal/filter_parameter_logging.rb
浏览文件 @
da5978c2
...
@@ -2,6 +2,8 @@ module ActionController
...
@@ -2,6 +2,8 @@ module ActionController
module
FilterParameterLogging
module
FilterParameterLogging
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
INTERNAL_PARAMS
=
%w(controller action format _method only_path)
module
ClassMethods
module
ClassMethods
# Replace sensitive parameter data from the request log.
# Replace sensitive parameter data from the request log.
# Filters parameters that have any of the arguments as a substring.
# Filters parameters that have any of the arguments as a substring.
...
@@ -48,25 +50,12 @@ def filter_parameter_logging(*filter_words, &block)
...
@@ -48,25 +50,12 @@ def filter_parameter_logging(*filter_words, &block)
filtered_params
[
key
]
=
value
filtered_params
[
key
]
=
value
end
end
filtered_params
filtered_params
.
except!
(
*
INTERNAL_PARAMS
)
end
end
protected
:filter_parameters
protected
:filter_parameters
end
end
protected
# Overwrite log_process_action to include parameters information.
# If this method is invoked, it means logger is defined, so don't
# worry with such scenario here.
def
log_process_action
(
controller
)
#:nodoc:
params
=
controller
.
send
(
:filter_parameters
,
controller
.
request
.
params
)
logger
.
info
" Parameters:
#{
params
.
inspect
}
"
unless
params
.
empty?
super
end
end
end
INTERNAL_PARAMS
=
[
:controller
,
:action
,
:format
,
:_method
,
:only_path
]
protected
protected
def
filter_parameters
(
params
)
def
filter_parameters
(
params
)
...
...
actionpack/lib/action_controller/metal/
logger
.rb
→
actionpack/lib/action_controller/metal/
instrumentation
.rb
浏览文件 @
da5978c2
require
'abstract_controller/logger'
require
'abstract_controller/logger'
module
ActionController
module
ActionController
# Adds instrumentation to <tt>process_action</tt> and a <tt>log_event</tt> method
# Adds instrumentation to several ends in ActionController::Base. It also provides
# responsible to log events from ActiveSupport::Notifications. This module handles
# some hooks related with process_action logging and view runtime.
# :process_action and :render_template events but allows any other module to hook
module
Instrumentation
# into log_event and provide its own logging facilities (as in ActionController::Caching).
module
Logger
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
...
@@ -14,7 +12,7 @@ module Logger
...
@@ -14,7 +12,7 @@ module Logger
attr_internal
:view_runtime
attr_internal
:view_runtime
def
process_action
(
action
)
def
process_action
(
action
,
*
args
)
ActiveSupport
::
Notifications
.
instrument
(
"action_controller.process_action"
,
ActiveSupport
::
Notifications
.
instrument
(
"action_controller.process_action"
,
:controller
=>
self
,
:action
=>
action
)
do
:controller
=>
self
,
:action
=>
action
)
do
super
super
...
@@ -35,8 +33,27 @@ def render(*args, &block)
...
@@ -35,8 +33,27 @@ def render(*args, &block)
end
end
end
end
# If you want to remove any time taken into account in :view_runtime
def
send_file
(
path
,
options
=
{})
# wrongly, you can do it here:
ActiveSupport
::
Notifications
.
instrument
(
"action_controller.send_file"
,
options
.
merge
(
:path
=>
path
))
do
super
end
end
def
send_data
(
data
,
options
=
{})
ActiveSupport
::
Notifications
.
instrument
(
"action_controller.send_data"
,
options
)
do
super
end
end
def
redirect_to
(
*
args
)
super
ActiveSupport
::
Notifications
.
instrument
(
"action_controller.redirect_to"
,
:status
=>
self
.
status
,
:location
=>
self
.
location
)
end
# A hook which allows you to clean up any time taken into account in
# views wrongly, like database querying time.
#
#
# def cleanup_view_runtime
# def cleanup_view_runtime
# super - time_taken_in_something_expensive
# super - time_taken_in_something_expensive
...
@@ -48,46 +65,13 @@ def cleanup_view_runtime #:nodoc:
...
@@ -48,46 +65,13 @@ def cleanup_view_runtime #:nodoc:
end
end
module
ClassMethods
module
ClassMethods
# This is the hook invoked by ActiveSupport::Notifications.subscribe.
# A hook which allows other frameworks to log what happened during
# If you need to log any event, overwrite the method and do it here.
# controller process action.
def
log_event
(
name
,
before
,
after
,
instrumenter_id
,
payload
)
#:nodoc:
if
name
==
"action_controller.process_action"
duration
=
[(
after
-
before
)
*
1000
,
0.01
].
max
controller
=
payload
[
:controller
]
request
=
controller
.
request
logger
.
info
"
\n
Processed
#{
controller
.
class
.
name
}
#
#{
payload
[
:action
]
}
"
\
"to
#{
request
.
formats
}
(for
#{
request
.
remote_ip
}
at
#{
before
.
to_s
(
:db
)
}
) "
\
"[
#{
request
.
method
.
to_s
.
upcase
}
]"
log_process_action
(
controller
)
message
=
"Completed in %.0fms"
%
duration
message
<<
" |
#{
controller
.
response
.
status
}
"
message
<<
" [
#{
request
.
request_uri
rescue
"unknown"
}
]
\n\n
"
logger
.
info
(
message
)
elsif
name
==
"action_view.render_template"
duration
=
(
after
-
before
)
*
1000
message
=
"Rendered
#{
from_rails_root
(
payload
[
:identifier
])
}
"
message
<<
" within
#{
from_rails_root
(
payload
[
:layout
])
}
"
if
payload
[
:layout
]
message
<<
(
" (%.1fms)"
%
duration
)
logger
.
info
(
message
)
end
end
protected
# A hook which allows logging what happened during controller process action.
# :api: plugin
# :api: plugin
def
log_process_action
(
controller
)
#:nodoc:
def
log_process_action
(
controller
)
#:nodoc:
view_runtime
=
controller
.
send
:view_runtime
view_runtime
=
controller
.
send
:view_runtime
logger
.
info
(
" View runtime: %.1fms"
%
view_runtime
.
to_f
)
if
view_runtime
logger
.
info
(
" View runtime: %.1fms"
%
view_runtime
.
to_f
)
if
view_runtime
end
end
def
from_rails_root
(
string
)
defined?
(
Rails
.
root
)
?
string
.
sub
(
"
#{
Rails
.
root
}
/app/views/"
,
""
)
:
string
end
end
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/metal/redirecting.rb
浏览文件 @
da5978c2
...
@@ -57,8 +57,6 @@ def redirect_to(options = {}, response_status = {}) #:doc:
...
@@ -57,8 +57,6 @@ def redirect_to(options = {}, response_status = {}) #:doc:
self
.
status
=
_extract_redirect_to_status
(
options
,
response_status
)
self
.
status
=
_extract_redirect_to_status
(
options
,
response_status
)
self
.
location
=
_compute_redirect_to_location
(
options
)
self
.
location
=
_compute_redirect_to_location
(
options
)
self
.
response_body
=
"<html><body>You are being <a href=
\"
#{
ERB
::
Util
.
h
(
location
)
}
\"
>redirected</a>.</body></html>"
self
.
response_body
=
"<html><body>You are being <a href=
\"
#{
ERB
::
Util
.
h
(
location
)
}
\"
>redirected</a>.</body></html>"
logger
.
info
(
"Redirected to
#{
location
}
"
)
if
logger
&&
logger
.
info?
end
end
private
private
...
...
actionpack/lib/action_controller/metal/streaming.rb
浏览文件 @
da5978c2
...
@@ -88,13 +88,11 @@ def send_file(path, options = {}) #:doc:
...
@@ -88,13 +88,11 @@ def send_file(path, options = {}) #:doc:
@performed_render
=
false
@performed_render
=
false
if
options
[
:x_sendfile
]
if
options
[
:x_sendfile
]
logger
.
info
"Sending
#{
X_SENDFILE_HEADER
}
header
#{
path
}
"
if
logger
head
options
[
:status
],
X_SENDFILE_HEADER
=>
path
head
options
[
:status
],
X_SENDFILE_HEADER
=>
path
else
else
if
options
[
:stream
]
if
options
[
:stream
]
# TODO : Make render :text => proc {} work with the new base
# TODO : Make render :text => proc {} work with the new base
render
:status
=>
options
[
:status
],
:text
=>
Proc
.
new
{
|
response
,
output
|
render
:status
=>
options
[
:status
],
:text
=>
Proc
.
new
{
|
response
,
output
|
logger
.
info
"Streaming file
#{
path
}
"
unless
logger
.
nil?
len
=
options
[
:buffer_size
]
||
4096
len
=
options
[
:buffer_size
]
||
4096
File
.
open
(
path
,
'rb'
)
do
|
file
|
File
.
open
(
path
,
'rb'
)
do
|
file
|
while
buf
=
file
.
read
(
len
)
while
buf
=
file
.
read
(
len
)
...
@@ -103,7 +101,6 @@ def send_file(path, options = {}) #:doc:
...
@@ -103,7 +101,6 @@ def send_file(path, options = {}) #:doc:
end
end
}
}
else
else
logger
.
info
"Sending file
#{
path
}
"
unless
logger
.
nil?
File
.
open
(
path
,
'rb'
)
{
|
file
|
render
:status
=>
options
[
:status
],
:text
=>
file
.
read
}
File
.
open
(
path
,
'rb'
)
{
|
file
|
render
:status
=>
options
[
:status
],
:text
=>
file
.
read
}
end
end
end
end
...
@@ -141,7 +138,6 @@ def send_file(path, options = {}) #:doc:
...
@@ -141,7 +138,6 @@ def send_file(path, options = {}) #:doc:
# data to the browser, then use <tt>render :text => proc { ... }</tt>
# data to the browser, then use <tt>render :text => proc { ... }</tt>
# instead. See ActionController::Base#render for more information.
# instead. See ActionController::Base#render for more information.
def
send_data
(
data
,
options
=
{})
#:doc:
def
send_data
(
data
,
options
=
{})
#:doc:
logger
.
info
"Sending data
#{
options
[
:filename
]
}
"
if
logger
send_file_headers!
options
.
merge
(
:length
=>
data
.
bytesize
)
send_file_headers!
options
.
merge
(
:length
=>
data
.
bytesize
)
render
:status
=>
options
[
:status
],
:text
=>
data
render
:status
=>
options
[
:status
],
:text
=>
data
end
end
...
...
actionpack/lib/action_controller/railtie.rb
浏览文件 @
da5978c2
...
@@ -5,6 +5,9 @@ module ActionController
...
@@ -5,6 +5,9 @@ module ActionController
class
Railtie
<
Rails
::
Railtie
class
Railtie
<
Rails
::
Railtie
plugin_name
:action_controller
plugin_name
:action_controller
require
"action_controller/railties/subscriber"
subscriber
ActionController
::
Railties
::
Subscriber
.
new
initializer
"action_controller.set_configs"
do
|
app
|
initializer
"action_controller.set_configs"
do
|
app
|
app
.
config
.
action_controller
.
each
do
|
k
,
v
|
app
.
config
.
action_controller
.
each
do
|
k
,
v
|
ActionController
::
Base
.
send
"
#{
k
}
="
,
v
ActionController
::
Base
.
send
"
#{
k
}
="
,
v
...
@@ -86,13 +89,5 @@ def name
...
@@ -86,13 +89,5 @@ def name
end
end
end
end
initializer
"action_controller.notifications"
do
|
app
|
require
'active_support/notifications'
ActiveSupport
::
Notifications
.
subscribe
do
|*
args
|
ActionController
::
Base
.
log_event
(
*
args
)
if
ActionController
::
Base
.
logger
end
end
end
end
end
end
actionpack/lib/action_controller/railties/subscriber.rb
0 → 100644
浏览文件 @
da5978c2
module
ActionController
module
Railties
class
Subscriber
<
Rails
::
Subscriber
def
process_action
(
event
)
controller
=
event
.
payload
[
:controller
]
request
=
controller
.
request
info
"
\n
Processed
#{
controller
.
class
.
name
}
#
#{
event
.
payload
[
:action
]
}
"
\
"to
#{
request
.
formats
}
(for
#{
request
.
remote_ip
}
at
#{
event
.
time
.
to_s
(
:db
)
}
) "
\
"[
#{
request
.
method
.
to_s
.
upcase
}
]"
params
=
controller
.
send
(
:filter_parameters
,
request
.
params
)
info
" Parameters:
#{
params
.
inspect
}
"
unless
params
.
empty?
ActionController
::
Base
.
log_process_action
(
controller
)
message
=
"Completed in %.0fms"
%
event
.
duration
message
<<
" |
#{
controller
.
response
.
status
}
"
message
<<
" [
#{
request
.
request_uri
rescue
"unknown"
}
]
\n\n
"
info
(
message
)
end
def
send_file
(
event
)
message
=
if
event
.
payload
[
:x_sendfile
]
header
=
ActionController
::
Streaming
::
X_SENDFILE_HEADER
"Sending
#{
header
}
header %s"
elsif
event
.
payload
[
:stream
]
"Streaming file %s"
else
"Sending file %s"
end
message
<<
" (%.1fms)"
info
(
message
%
[
event
.
payload
[
:path
],
event
.
duration
])
end
def
redirect_to
(
event
)
info
"Redirected to
#{
event
.
payload
[
:location
]
}
with status
#{
event
.
payload
[
:status
]
}
"
end
def
send_data
(
event
)
info
(
"Sending data %s (%.1fms)"
%
[
event
.
payload
[
:filename
],
event
.
duration
])
end
%w(write_fragment read_fragment exist_fragment?
expire_fragment expire_page write_page)
.
each
do
|
method
|
class_eval
<<-
METHOD
,
__FILE__
,
__LINE__
+
1
def
#{
method
}
(event)
key_or_path = event.payload[:key] || event.payload[:path]
human_name =
#{
method
.
to_s
.
humanize
.
inspect
}
info("
\#
{human_name}
\#
{key_or_path.inspect} (%.1fms)" % event.duration)
end
METHOD
end
def
logger
ActionController
::
Base
.
logger
end
end
end
end
\ No newline at end of file
actionpack/lib/action_view/railtie.rb
浏览文件 @
da5978c2
require
"action_view"
require
"action_view"
require
"rails"
require
"rails"
\ No newline at end of file
module
ActionView
class
Railtie
<
Rails
::
Railtie
plugin_name
:action_view
require
"action_view/railties/subscriber"
subscriber
ActionView
::
Railties
::
Subscriber
.
new
end
end
\ No newline at end of file
actionpack/lib/action_view/railties/subscriber.rb
0 → 100644
浏览文件 @
da5978c2
module
ActionView
module
Railties
class
Subscriber
<
Rails
::
Subscriber
def
render_template
(
event
)
message
=
"Rendered
#{
from_rails_root
(
event
.
payload
[
:identifier
])
}
"
message
<<
" within
#{
from_rails_root
(
event
.
payload
[
:layout
])
}
"
if
event
.
payload
[
:layout
]
message
<<
(
" (%.1fms)"
%
event
.
duration
)
info
(
message
)
end
alias
:render_partial
:render_template
alias
:render_collection
:render_template
def
logger
ActionController
::
Base
.
logger
end
protected
def
from_rails_root
(
string
)
string
.
sub
(
"
#{
Rails
.
root
}
/"
,
""
).
sub
(
/^app\/views\//
,
""
)
end
end
end
end
\ No newline at end of file
actionpack/lib/action_view/template/text.rb
浏览文件 @
da5978c2
...
@@ -13,7 +13,7 @@ def details
...
@@ -13,7 +13,7 @@ def details
end
end
def
identifier
def
identifier
self
'text template'
end
end
def
inspect
def
inspect
...
...
actionpack/test/abstract_unit.rb
浏览文件 @
da5978c2
...
@@ -48,14 +48,6 @@
...
@@ -48,14 +48,6 @@
FIXTURE_LOAD_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
)
FIXTURE_LOAD_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
)
FIXTURES
=
Pathname
.
new
(
FIXTURE_LOAD_PATH
)
FIXTURES
=
Pathname
.
new
(
FIXTURE_LOAD_PATH
)
# Turn on notifications
require
'active_support/notifications'
Thread
.
abort_on_exception
=
true
ActiveSupport
::
Notifications
.
subscribe
do
|*
args
|
ActionController
::
Base
.
log_event
(
*
args
)
if
ActionController
::
Base
.
logger
end
module
SetupOnce
module
SetupOnce
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
...
@@ -93,24 +85,6 @@ class ActiveSupport::TestCase
...
@@ -93,24 +85,6 @@ class ActiveSupport::TestCase
end
end
end
end
class
MockLogger
attr_accessor
:level
def
initialize
@level
=
Logger
::
DEBUG
@logged
=
[]
end
def
method_missing
(
method
,
*
args
,
&
blk
)
@logged
<<
args
.
first
@logged
<<
blk
.
call
if
block_given?
end
def
logged
@logged
.
compact
.
map
{
|
l
|
l
.
to_s
.
strip
}
end
end
class
ActionController::IntegrationTest
<
ActiveSupport
::
TestCase
class
ActionController::IntegrationTest
<
ActiveSupport
::
TestCase
def
self
.
build_app
(
routes
=
nil
)
def
self
.
build_app
(
routes
=
nil
)
ActionDispatch
::
MiddlewareStack
.
new
{
|
middleware
|
ActionDispatch
::
MiddlewareStack
.
new
{
|
middleware
|
...
...
actionpack/test/controller/caching_test.rb
浏览文件 @
da5978c2
...
@@ -629,20 +629,6 @@ def test_fragment_for
...
@@ -629,20 +629,6 @@ def test_fragment_for
assert_equal
'generated till now -> fragment content'
,
buffer
assert_equal
'generated till now -> fragment content'
,
buffer
end
end
def
test_fragment_for_logging
# Wait pending notifications to be published
ActiveSupport
::
Notifications
.
notifier
.
wait
@controller
.
logger
=
MockLogger
.
new
fragment_computed
=
false
@controller
.
fragment_for
(
'buffer'
,
'expensive'
)
{
fragment_computed
=
true
}
ActiveSupport
::
Notifications
.
notifier
.
wait
assert
fragment_computed
assert_match
/Exist fragment\? "views\/expensive"/
,
@controller
.
logger
.
logged
[
0
]
assert_match
/Write fragment "views\/expensive"/
,
@controller
.
logger
.
logged
[
1
]
end
end
end
class
FunctionalCachingController
<
ActionController
::
Base
class
FunctionalCachingController
<
ActionController
::
Base
...
...
actionpack/test/controller/filter_params_test.rb
浏览文件 @
da5978c2
...
@@ -66,18 +66,6 @@ def test_filter_parameters_is_protected
...
@@ -66,18 +66,6 @@ def test_filter_parameters_is_protected
assert_raise
(
NoMethodError
)
{
@controller
.
filter_parameters
([{
'password'
=>
'[FILTERED]'
}])
}
assert_raise
(
NoMethodError
)
{
@controller
.
filter_parameters
([{
'password'
=>
'[FILTERED]'
}])
}
end
end
def
test_filter_parameters_inside_logs
FilterParamController
.
filter_parameter_logging
(
:lifo
,
:amount
)
get
:payment
,
:lifo
=>
'Pratik'
,
:amount
=>
'420'
,
:step
=>
'1'
ActiveSupport
::
Notifications
.
notifier
.
wait
filtered_params_logs
=
logs
.
detect
{
|
l
|
l
=~
/\AParameters/
}
assert
filtered_params_logs
.
index
(
'"amount"=>"[FILTERED]"'
)
assert
filtered_params_logs
.
index
(
'"lifo"=>"[FILTERED]"'
)
assert
filtered_params_logs
.
index
(
'"step"=>"1"'
)
end
private
private
def
set_logger
def
set_logger
...
...
actionpack/test/controller/logging_test.rb
已删除
100644 → 0
浏览文件 @
8d78a82d
require
'abstract_unit'
module
Another
class
LoggingController
<
ActionController
::
Base
layout
"layouts/standard"
def
show
render
:nothing
=>
true
end
def
with_layout
render
:template
=>
"test/hello_world"
,
:layout
=>
true
end
end
end
class
LoggingTest
<
ActionController
::
TestCase
tests
Another
::
LoggingController
def
setup
super
wait
# Wait pending notifications to be published
set_logger
end
def
get
(
*
args
)
super
wait
end
def
wait
ActiveSupport
::
Notifications
.
notifier
.
wait
end
def
test_logging_without_parameters
get
:show
assert_equal
4
,
logs
.
size
assert_nil
logs
.
detect
{
|
l
|
l
=~
/Parameters/
}
end
def
test_logging_with_parameters
get
:show
,
:id
=>
'10'
assert_equal
5
,
logs
.
size
params
=
logs
.
detect
{
|
l
|
l
=~
/Parameters/
}
assert_equal
'Parameters: {"id"=>"10"}'
,
params
end
def
test_log_controller_with_namespace_and_action
get
:show
assert_match
/Processed\sAnother::LoggingController#show/
,
logs
[
1
]
end
def
test_log_view_runtime
get
:show
assert_match
/View runtime/
,
logs
[
2
]
end
def
test_log_completed_status_and_request_uri
get
:show
last
=
logs
.
last
assert_match
/Completed/
,
last
assert_match
/200/
,
last
assert_match
/another\/logging\/show/
,
last
end
def
test_logger_prints_layout_and_template_rendering_info
get
:with_layout
logged
=
logs
.
find
{
|
l
|
l
=~
/render/i
}
assert_match
/Rendered (.*)test\/hello_world.erb within (.*)layouts\/standard.html.erb/
,
logged
end
private
def
set_logger
@controller
.
logger
=
MockLogger
.
new
end
def
logs
@logs
||=
@controller
.
logger
.
logged
end
end
actionpack/test/controller/subscriber_test.rb
0 → 100644
浏览文件 @
da5978c2
require
"abstract_unit"
require
"rails/subscriber/test_helper"
require
"action_controller/railties/subscriber"
module
Another
class
SubscribersController
<
ActionController
::
Base
def
show
render
:nothing
=>
true
end
def
redirector
redirect_to
"http://foo.bar/"
end
end
end
module
ActionControllerSubscriberTest
Rails
::
Subscriber
.
add
(
:action_controller
,
ActionController
::
Railties
::
Subscriber
.
new
)
def
self
.
included
(
base
)
base
.
tests
Another
::
SubscribersController
end
def
wait
sleep
(
0.01
)
super
end
def
setup
@old_logger
=
ActionController
::
Base
.
logger
super
end
def
teardown
super
ActionController
::
Base
.
logger
=
@old_logger
end
def
set_logger
(
logger
)
ActionController
::
Base
.
logger
=
logger
end
def
test_process_action
get
:show
wait
assert_equal
3
,
@logger
.
logged
(
:info
).
size
assert_match
/Processed\sAnother::SubscribersController#show/
,
@logger
.
logged
(
:info
)[
0
]
end
def
test_process_action_without_parameters
get
:show
wait
assert_nil
@logger
.
logged
(
:info
).
detect
{
|
l
|
l
=~
/Parameters/
}
end
def
test_process_action_with_parameters
get
:show
,
:id
=>
'10'
wait
assert_equal
4
,
@logger
.
logged
(
:info
).
size
assert_equal
'Parameters: {"id"=>"10"}'
,
@logger
.
logged
(
:info
)[
1
]
end
def
test_process_action_with_view_runtime
get
:show
wait
assert_match
/View runtime/
,
@logger
.
logged
(
:info
)[
1
]
end
def
test_process_action_with_status_and_request_uri
get
:show
wait
last
=
@logger
.
logged
(
:info
).
last
assert_match
/Completed/
,
last
assert_match
/200/
,
last
assert_match
/another\/subscribers\/show/
,
last
end
def
test_process_action_with_filter_parameters
Another
::
SubscribersController
.
filter_parameter_logging
(
:lifo
,
:amount
)
get
:show
,
:lifo
=>
'Pratik'
,
:amount
=>
'420'
,
:step
=>
'1'
wait
params
=
@logger
.
logged
(
:info
)[
1
]
assert_match
/"amount"=>"\[FILTERED\]"/
,
params
assert_match
/"lifo"=>"\[FILTERED\]"/
,
params
assert_match
/"step"=>"1"/
,
params
end
def
test_redirect_to
get
:redirector
wait
assert_equal
3
,
@logger
.
logged
(
:info
).
size
assert_equal
"Redirected to http://foo.bar/ with status 302"
,
@logger
.
logged
(
:info
)[
0
]
end
class
SyncSubscriberTest
<
ActionController
::
TestCase
include
Rails
::
Subscriber
::
SyncTestHelper
include
ActionControllerSubscriberTest
end
class
AsyncSubscriberTest
<
ActionController
::
TestCase
include
Rails
::
Subscriber
::
AsyncTestHelper
include
ActionControllerSubscriberTest
end
end
actionpack/test/template/subscriber_test.rb
0 → 100644
浏览文件 @
da5978c2
require
"abstract_unit"
require
"rails/subscriber/test_helper"
require
"action_view/railties/subscriber"
require
"controller/fake_models"
module
ActionViewSubscriberTest
Rails
::
Subscriber
.
add
(
:action_view
,
ActionView
::
Railties
::
Subscriber
.
new
)
def
setup
@old_logger
=
ActionController
::
Base
.
logger
@view
=
ActionView
::
Base
.
new
(
ActionController
::
Base
.
view_paths
,
{})
Rails
.
stubs
(
:root
).
returns
(
File
.
expand_path
(
FIXTURE_LOAD_PATH
))
super
end
def
teardown
super
ActionController
::
Base
.
logger
=
@old_logger
end
def
set_logger
(
logger
)
ActionController
::
Base
.
logger
=
logger
end
def
test_render_file_template
@view
.
render
(
:file
=>
"test/hello_world.erb"
)
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Rendered test\/hello_world\.erb/
,
@logger
.
logged
(
:info
).
last
end
def
test_render_text_template
@view
.
render
(
:text
=>
"OMG"
)
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Rendered text template/
,
@logger
.
logged
(
:info
).
last
end
def
test_render_inline_template
@view
.
render
(
:inline
=>
"<%= 'OMG' %>"
)
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Rendered inline template/
,
@logger
.
logged
(
:info
).
last
end
def
test_render_partial_template
@view
.
render
(
:partial
=>
"test/customer"
)
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Rendered test\/_customer.erb/
,
@logger
.
logged
(
:info
).
last
end
def
test_render_collection_template
@view
.
render
(
:partial
=>
"test/customer"
,
:collection
=>
[
Customer
.
new
(
"david"
),
Customer
.
new
(
"mary"
)
])
wait
assert_equal
1
,
@logger
.
logged
(
:info
).
size
assert_match
/Rendered test\/_customer.erb/
,
@logger
.
logged
(
:info
).
last
end
class
SyncSubscriberTest
<
ActiveSupport
::
TestCase
include
Rails
::
Subscriber
::
SyncTestHelper
include
ActionViewSubscriberTest
end
class
AsyncSubscriberTest
<
ActiveSupport
::
TestCase
include
Rails
::
Subscriber
::
AsyncTestHelper
include
ActionViewSubscriberTest
end
end
\ No newline at end of file
activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
浏览文件 @
da5978c2
...
@@ -14,7 +14,7 @@ def parse_sqlite_config!(config)
...
@@ -14,7 +14,7 @@ def parse_sqlite_config!(config)
# Allow database path relative to Rails.root, but only if
# Allow database path relative to Rails.root, but only if
# the database path is not the special path that tells
# the database path is not the special path that tells
# Sqlite to build a database only in memory.
# Sqlite to build a database only in memory.
if
Object
.
const_defined?
(
:Rails
)
&&
':memory:'
!=
config
[
:database
]
if
defined?
(
Rails
.
root
)
&&
':memory:'
!=
config
[
:database
]
config
[
:database
]
=
File
.
expand_path
(
config
[
:database
],
Rails
.
root
)
config
[
:database
]
=
File
.
expand_path
(
config
[
:database
],
Rails
.
root
)
end
end
end
end
...
...
activerecord/lib/active_record/railties/subscriber.rb
浏览文件 @
da5978c2
...
@@ -12,7 +12,7 @@ def sql(event)
...
@@ -12,7 +12,7 @@ def sql(event)
name
=
color
(
name
,
:magenta
,
true
)
name
=
color
(
name
,
:magenta
,
true
)
end
end
debug
"
#{
name
}
#{
sql
}
"
debug
"
#{
name
}
#{
sql
}
"
end
end
def
odd?
def
odd?
...
...
activerecord/test/cases/subscriber_test.rb
浏览文件 @
da5978c2
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
module
SubscriberTest
module
SubscriberTest
Rails
::
Subscriber
.
add
(
:active_record
,
ActiveRecord
::
Railties
::
Subscriber
.
new
)
Rails
::
Subscriber
.
add
(
:active_record
,
ActiveRecord
::
Railties
::
Subscriber
.
new
)
def
s
uper
def
s
etup
@old_logger
=
ActiveRecord
::
Base
.
logger
@old_logger
=
ActiveRecord
::
Base
.
logger
super
super
end
end
...
@@ -17,7 +17,7 @@ def teardown
...
@@ -17,7 +17,7 @@ def teardown
end
end
def
set_logger
(
logger
)
def
set_logger
(
logger
)
ActiveRecord
::
Base
.
logger
=
@
logger
ActiveRecord
::
Base
.
logger
=
logger
end
end
def
test_basic_query_logging
def
test_basic_query_logging
...
...
activesupport/lib/active_support/deprecation/behaviors.rb
浏览文件 @
da5978c2
...
@@ -12,7 +12,7 @@ def behavior
...
@@ -12,7 +12,7 @@ def behavior
end
end
def
default_behavior
def
default_behavior
Deprecation
::
DEFAULT_BEHAVIORS
[
defined?
(
Rails
)
?
Rails
.
env
.
to_s
:
'test'
]
Deprecation
::
DEFAULT_BEHAVIORS
[
defined?
(
Rails
.
env
)
?
Rails
.
env
.
to_s
:
'test'
]
end
end
end
end
...
...
railties/lib/rails/subscriber/test_helper.rb
浏览文件 @
da5978c2
require
'rails'
require
'rails/subscriber'
require
'rails/subscriber'
require
'active_support/notifications'
module
Rails
module
Rails
class
Subscriber
class
Subscriber
...
@@ -101,6 +101,11 @@ module AsyncTestHelper
...
@@ -101,6 +101,11 @@ module AsyncTestHelper
def
queue
def
queue
ActiveSupport
::
Notifications
::
Fanout
.
new
(
false
)
ActiveSupport
::
Notifications
::
Fanout
.
new
(
false
)
end
end
def
wait
sleep
(
0.01
)
super
end
end
end
end
end
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录