From dd0bbd2ccb9c813902ae263dd4cc21f85af0bdc4 Mon Sep 17 00:00:00 2001 From: Igor Date: Fri, 8 Feb 2013 00:54:46 +0200 Subject: [PATCH] fix db_runtime attribute value after raising ActionView::MissingTemplate exception --- .../test/activerecord/controller_runtime_test.rb | 14 ++++++++++++++ activerecord/CHANGELOG.md | 8 ++++++++ .../active_record/railties/controller_runtime.rb | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index 1df826fe2bf59..368bec1c70aba 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -8,6 +8,8 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase class LogSubscriberController < ActionController::Base + respond_to :html + def show render :inline => "<%= Project.all %>" end @@ -16,6 +18,12 @@ def zero 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 @@ def test_runtime_reset_before_requests 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 diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 55fa9cae812d9..bb32d16fc1982 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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). diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index 7695eacbffa7d..af4840476c02d 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -21,9 +21,10 @@ def process_action(action, *args) 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