diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-10 13:34:33 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-10 13:34:33 -0800 |
commit | 2f49cd91b7fdf18a559216fa725d039a5cd78ff1 (patch) | |
tree | 7dfa3f01b96319d653801a1687ffd495f7b1ca4b /activerecord/test | |
parent | 028016ede382de80b9e91a7e13cd5372c2afd4bd (diff) | |
download | rails-2f49cd91b7fdf18a559216fa725d039a5cd78ff1.tar.gz rails-2f49cd91b7fdf18a559216fa725d039a5cd78ff1.tar.bz2 rails-2f49cd91b7fdf18a559216fa725d039a5cd78ff1.zip |
bind parameters are logged to debug log
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/bind_parameter_test.rb | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/activerecord/test/cases/bind_parameter_test.rb b/activerecord/test/cases/bind_parameter_test.rb index 4532ab6213..83001f44f9 100644 --- a/activerecord/test/cases/bind_parameter_test.rb +++ b/activerecord/test/cases/bind_parameter_test.rb @@ -3,6 +3,8 @@ require 'models/topic' module ActiveRecord class BindParameterTest < ActiveRecord::TestCase + fixtures :topics + class LogListener attr_accessor :calls @@ -15,8 +17,6 @@ module ActiveRecord end end - fixtures :topics - def setup super @connection = ActiveRecord::Base.connection @@ -52,5 +52,39 @@ module ActiveRecord message = @listener.calls.find { |args| args[4][:binds] == binds } assert message, 'expected a message with binds' end + + def test_logs_bind_vars + # FIXME: use skip with minitest + return unless @connection.supports_statement_cache? + + pk = Topic.columns.find { |x| x.primary } + + payload = { + :name => 'SQL', + :sql => 'select * from topics where id = ?', + :binds => [[pk, 10]] + } + event = ActiveSupport::Notifications::Event.new( + 'foo', + Time.now, + Time.now, + 123, + payload) + + logger = Class.new(ActiveRecord::LogSubscriber) { + attr_reader :debugs + def initialize + super + @debugs = [] + end + + def debug str + @debugs << str + end + }.new + + logger.sql event + assert_match("{#{pk.name.inspect} => #{10.inspect}}", logger.debugs.first) + end end end |