Skip to content

Commit 238e32a

Browse files
committed
Fix bind_parameter_test for mysql with unprepared statements
``` Failure: ActiveRecord::BindParameterTest#test_bind_params_to_sql_with_unprepared_statements [test/cases/bind_parameter_test.rb:170]: --- expected +++ actual @@ -1 +1 @@ -"SELECT `authors`.* FROM `authors` WHERE `authors`.`id` IN (1, 2, 3)" +"SELECT `authors`.* FROM `authors` WHERE `authors`.`id` IN ('1', '2', '3')" bin/test test/cases/bind_parameter_test.rb:168 ``` This is because only the Mysql adapter treats numerics with `to_s` in all cases, causing this test to fail. Since this test was never run in CI, we didn't know about it was wrong. I've tried changing the behavior of the abstract Mysql adapter to be similar as PG where `Numeric#finite?` cases pass to super but there are tests for the current behavior and am trying to avoid making any breaking changes in order to fix the prepared statement tests for Mysql.
1 parent 83337df commit 238e32a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

activerecord/test/cases/bind_parameter_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,13 @@ def assert_bind_params_to_sql
238238
#
239239
# SELECT `authors`.* FROM `authors` WHERE `authors`.`id` IN (1, 2, 3)
240240
#
241-
sql = "SELECT #{table}.* FROM #{table} WHERE #{pk} IN (#{bind_params(1..3)})"
241+
if current_adapter?(:Mysql2Adapter)
242+
params = bind_params((1..3).map(&:to_s))
243+
else
244+
params = bind_params(1..3)
245+
end
242246

247+
sql = "SELECT #{table}.* FROM #{table} WHERE #{pk} IN (#{params})"
243248
arel_node = Arel.sql("SELECT #{table}.* FROM #{table} WHERE #{pk} IN (?)", [1, 2, 3])
244249
assert_equal sql, @connection.to_sql(arel_node)
245250
assert_queries_match(sql) { assert_equal 3, @connection.select_all(arel_node).length }

0 commit comments

Comments
 (0)