diff options
author | Yasuo Honda <yasuo.honda@gmail.com> | 2013-01-09 03:30:37 +0900 |
---|---|---|
committer | Yasuo Honda <yasuo.honda@gmail.com> | 2013-01-09 06:18:14 +0900 |
commit | 3d1a879f4cf9931a81477b63f9f999d52bac771c (patch) | |
tree | 80f9b95134535058a417cfda5edd0558568a3f68 /activerecord | |
parent | 48810a52dfba26cef127168af447a9620d4555c3 (diff) | |
download | rails-3d1a879f4cf9931a81477b63f9f999d52bac771c.tar.gz rails-3d1a879f4cf9931a81477b63f9f999d52bac771c.tar.bz2 rails-3d1a879f4cf9931a81477b63f9f999d52bac771c.zip |
Ignore binds payload with nil column in AR log subscriber
Some tests were raising the following error:
Could not log "sql.active_record" event. NoMethodError: undefined method
`type' for nil:NilClass`
Due to the way binds were being logged, the column info was considered
always present, but that is not true for some of the tests listed in the
issue.
Closes #8806.
Conflicts:
activerecord/lib/active_record/log_subscriber.rb
activerecord/test/cases/log_subscriber_test.rb
Conflict resolution:
- Revert ruby 1.9 style hash to support ruby 1.8
- Do not include 8f59ffce into 3-2-stable
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/log_subscriber_test.rb | 34 |
2 files changed, 27 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index a25f2c7bca..2b6488f183 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -32,7 +32,11 @@ module ActiveRecord unless (payload[:binds] || []).empty? binds = " " + payload[:binds].map { |col,v| - [col.name, v] + if col + [col.name, v] + else + [nil, v] + end }.inspect end diff --git a/activerecord/test/cases/log_subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb index e24a5ca5aa..10ee86de4a 100644 --- a/activerecord/test/cases/log_subscriber_test.rb +++ b/activerecord/test/cases/log_subscriber_test.rb @@ -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 @@ class LogSubscriberTest < ActiveRecord::TestCase 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 @@ class LogSubscriberTest < ActiveRecord::TestCase 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 |