mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix db_runtime attribute value after raising ActionView::MissingTemplate exception
This commit is contained in:
parent
dca0b57d03
commit
dd0bbd2ccb
3 changed files with 24 additions and 1 deletions
|
@ -8,6 +8,8 @@ ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
|
|||
|
||||
class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
||||
class LogSubscriberController < ActionController::Base
|
||||
respond_to :html
|
||||
|
||||
def show
|
||||
render :inline => "<%= Project.all %>"
|
||||
end
|
||||
|
@ -16,6 +18,12 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
|||
render :inline => "Zero DB runtime"
|
||||
end
|
||||
|
||||
def create
|
||||
ActiveRecord::LogSubscriber.runtime += 100
|
||||
project = Project.last
|
||||
respond_with(project, location: url_for(action: :show))
|
||||
end
|
||||
|
||||
def redirect
|
||||
Project.all
|
||||
redirect_to :action => 'show'
|
||||
|
@ -64,6 +72,12 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
|
|||
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1])
|
||||
end
|
||||
|
||||
def test_log_with_active_record_when_post
|
||||
post :create
|
||||
wait
|
||||
assert_match(/ActiveRecord: ([1-9][\d.]+)ms\)/, @logger.logged(:info)[2])
|
||||
end
|
||||
|
||||
def test_log_with_active_record_when_redirecting
|
||||
get :redirect
|
||||
wait
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Fix calculation of `db_runtime` property in
|
||||
`ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime`.
|
||||
Previously, after raising `ActionView::MissingTemplate` db_runtime was
|
||||
not populated.
|
||||
Fixes #9215.
|
||||
|
||||
*Igor Fedoronchuk*
|
||||
|
||||
* Schema dumper supports dumping the enabled database extensions to `schema.rb`
|
||||
(currently only supported by postgresql).
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@ module ActiveRecord
|
|||
def cleanup_view_runtime
|
||||
if ActiveRecord::Base.connected?
|
||||
db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime
|
||||
self.db_runtime = (db_runtime || 0) + db_rt_before_render
|
||||
runtime = super
|
||||
db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime
|
||||
self.db_runtime = db_rt_before_render + db_rt_after_render
|
||||
self.db_runtime += db_rt_after_render
|
||||
runtime - db_rt_after_render
|
||||
else
|
||||
super
|
||||
|
|
Loading…
Reference in a new issue