aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2018-07-28 16:17:56 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2018-07-28 16:17:56 +0200
commit8741052ba25722283ea057f6f022f16b1931ce3e (patch)
treee72280f4be6767806625e35ddc7e84b613e8a8ad /activerecord
parent845cbb4bb2869444379354a87f83553faaadc961 (diff)
downloadrails-8741052ba25722283ea057f6f022f16b1931ce3e.tar.gz
rails-8741052ba25722283ea057f6f022f16b1931ce3e.tar.bz2
rails-8741052ba25722283ea057f6f022f16b1931ce3e.zip
Don't expose configuration for a test.
Clean up some concepts in the code while we're here.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb30
-rw-r--r--activerecord/test/cases/log_subscriber_test.rb5
2 files changed, 12 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index 51ae1fdb45..1ae6840921 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -100,33 +100,21 @@ module ActiveRecord
end
def log_query_source
- line = extract_callstack(caller_locations)
+ location = extract_query_source_location(caller_locations)
- if line
- source_line, line_number = line.path, line.lineno
- if defined?(::Rails.root)
- app_root = "#{::Rails.root}/"
- source_line = source_line.sub(app_root, "")
- end
+ if location
+ source = "#{location.path}:#{location.lineno}"
+ source = source.sub("#{::Rails.root}/", "") if defined?(::Rails.root)
- logger.debug(" ↳ #{ source_line }:#{ line_number }")
+ logger.debug(" ↳ #{source}")
end
end
- def extract_callstack(callstack)
- callstack.find do |frame|
- frame.absolute_path && !ignored_callstack(frame.absolute_path)
- end
- end
-
- RAILS_GEM_ROOT = File.expand_path("../../..", __dir__) + "/"
+ RAILS_GEM_ROOT = File.expand_path("../../..", __dir__) + "/"
+ PATHS_TO_IGNORE = /\A(#{RAILS_GEM_ROOT}|#{RbConfig::CONFIG["rubylibdir"]})/
- class_attribute :ignored_callstack_paths, default: [RAILS_GEM_ROOT, RbConfig::CONFIG["rubylibdir"]]
-
- def ignored_callstack(path)
- ignored_callstack_paths.any? do |ignored_path|
- path.start_with?(ignored_path)
- end
+ def extract_query_source_location(locations)
+ locations.find { |line| line.absolute_path && !line.absolute_path.match?(PATHS_TO_IGNORE) }
end
end
end
diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb
index 3f26eaa88d..f0126fdb0d 100644
--- a/activerecord/test/cases/log_subscriber_test.rb
+++ b/activerecord/test/cases/log_subscriber_test.rb
@@ -185,13 +185,14 @@ class LogSubscriberTest < ActiveRecord::TestCase
def test_verbose_query_with_ignored_callstack
ActiveRecord::Base.verbose_query_logs = true
- ActiveRecord::LogSubscriber.ignored_callstack_paths.push("/")
+
logger = TestDebugLogSubscriber.new
+ def logger.extract_query_source_location(*); nil; end
+
logger.sql(Event.new(0, sql: "hi mom!"))
assert_equal 1, @logger.logged(:debug).size
assert_no_match(/↳/, @logger.logged(:debug).last)
ensure
- ActiveRecord::LogSubscriber.ignored_callstack_paths.delete("/")
ActiveRecord::Base.verbose_query_logs = false
end