Permalink
Browse files

Merge pull request #8838 from yahonda/8806_3-2-stable

Ignore binds payload with nil column in AR log subscriber
  • Loading branch information...
2 parents 45b17ce + 3d1a879 commit 8313f3c5771bfaa3325446d2bbe29c405f8b22c4 @rafaelfranca rafaelfranca committed Jan 9, 2013
Showing with 27 additions and 13 deletions.
  1. +5 −1 activerecord/lib/active_record/log_subscriber.rb
  2. +22 −12 activerecord/test/cases/log_subscriber_test.rb
@@ -32,7 +32,11 @@ def sql(event)
unless (payload[:binds] || []).empty?
binds = " " + payload[:binds].map { |col,v|
- [col.name, v]
+ if col
+ [col.name, v]
+ else
+ [nil, v]
+ end
}.inspect
end
@@ -7,6 +7,19 @@ class LogSubscriberTest < ActiveRecord::TestCase
include ActiveSupport::LogSubscriber::TestHelper
include ActiveSupport::BufferedLogger::Severity
+ class TestDebugLogSubscriber < ActiveRecord::LogSubscriber
+ attr_reader :debugs
+
+ def initialize
+ @debugs = []
+ super
+ end
+
+ def debug message
+ @debugs << message
+ end
+ end
+
fixtures :posts
def setup
@@ -32,18 +45,7 @@ def set_logger(logger)
def test_schema_statements_are_ignored
event = Struct.new(:duration, :payload)
- logger = Class.new(ActiveRecord::LogSubscriber) {
- attr_accessor :debugs
-
- def initialize
- @debugs = []
- super
- end
-
- def debug message
- @debugs << message
- end
- }.new
+ logger = TestDebugLogSubscriber.new
assert_equal 0, logger.debugs.length
logger.sql(event.new(0, { :sql => 'hi mom!' }))
@@ -56,6 +58,14 @@ def debug message
assert_equal 2, logger.debugs.length
end
+ def test_ignore_binds_payload_with_nil_column
+ event = Struct.new(:duration, :payload)
+
+ logger = TestDebugLogSubscriber.new
+ logger.sql(event.new(0, :sql => 'hi mom!', :binds => [[nil, 1]]))
+ assert_equal 1, logger.debugs.length
+ end
+
def test_basic_query_logging
Developer.all
wait

0 comments on commit 8313f3c

Please sign in to comment.