Skip to content

Commit

Permalink
activerecord: add log sql with unnamed bind test
Browse files Browse the repository at this point in the history
  • Loading branch information
ushi-as committed May 2, 2022
1 parent d82885d commit 976a543
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions activerecord/test/cases/bind_parameter_test.rb
Expand Up @@ -156,6 +156,11 @@ def test_logs_binds_after_type_cast
assert_logs_binds(binds)
end

def test_logs_unnamed_binds
binds = ["abcd"]
assert_logs_unnamed_binds(binds)
end

def test_bind_params_to_sql_with_prepared_statements
assert_bind_params_to_sql
end
Expand Down Expand Up @@ -281,6 +286,38 @@ def debug(str)
assert_match %r(\[\["id", 10\]\]\z), logger.debugs.first
end

def assert_logs_unnamed_binds(binds)
payload = {
name: "SQL",
sql: "select * from topics where title = $1",
binds: binds,
type_casted_binds: @connection.send(:type_casted_binds, binds)
}

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 %r(\[\[nil, "abcd"\]\]\z), logger.debugs.first
end

def assert_filtered_log_binds(binds)
payload = {
name: "SQL",
Expand Down

0 comments on commit 976a543

Please sign in to comment.