diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-10 09:56:50 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-10 09:56:50 -0800 |
commit | 028016ede382de80b9e91a7e13cd5372c2afd4bd (patch) | |
tree | 747a800502b6abede59cc4c0ba6ab436dd613a48 /activerecord | |
parent | 1814298d7590988d354955efdb0bc495b359293b (diff) | |
download | rails-028016ede382de80b9e91a7e13cd5372c2afd4bd.tar.gz rails-028016ede382de80b9e91a7e13cd5372c2afd4bd.tar.bz2 rails-028016ede382de80b9e91a7e13cd5372c2afd4bd.zip |
test cases for bind parameter logging
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/bind_parameter_test.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/activerecord/test/cases/bind_parameter_test.rb b/activerecord/test/cases/bind_parameter_test.rb new file mode 100644 index 0000000000..4532ab6213 --- /dev/null +++ b/activerecord/test/cases/bind_parameter_test.rb @@ -0,0 +1,56 @@ +require 'cases/helper' +require 'models/topic' + +module ActiveRecord + class BindParameterTest < ActiveRecord::TestCase + class LogListener + attr_accessor :calls + + def initialize + @calls = [] + end + + def call(*args) + calls << args + end + end + + fixtures :topics + + def setup + super + @connection = ActiveRecord::Base.connection + @listener = LogListener.new + @pk = Topic.columns.find { |c| c.primary } + ActiveSupport::Notifications.subscribe('sql.active_record', @listener) + end + + def teardown + ActiveSupport::Notifications.unsubscribe(@listener) + end + + def test_binds_are_logged + # FIXME: use skip with minitest + return unless @connection.supports_statement_cache? + + sub = @connection.substitute_for(@pk, []) + binds = [[@pk, 1]] + sql = "select * from topics where id = #{sub}" + + @connection.exec_query(sql, 'SQL', binds) + + message = @listener.calls.find { |args| args[4][:sql] == sql } + assert_equal binds, message[4][:binds] + end + + def test_find_one_uses_binds + # FIXME: use skip with minitest + return unless @connection.supports_statement_cache? + + Topic.find(1) + binds = [[@pk, 1]] + message = @listener.calls.find { |args| args[4][:binds] == binds } + assert message, 'expected a message with binds' + end + end +end |