Skip to content

Commit 83337df

Browse files
committed
Disable these EXPLAIN tests if using mysql2 and prepared statements are enabled
This is because these tests will never pass, due to the EXPLAIN output of MySQL always showing the final result of the query without the binds. ``` Failure: ExplainTest#test_relation_explain_with_last [test/cases/explain_test.rb:108]: Expected /SELECT\ `cars`\.\*\ FROM\ `cars`\ ORDER\ BY\ `cars`\.`id`\ DESC\ LIMIT\ \?/ to match EXPLAIN SELECT `cars`.* FROM `cars` ORDER BY `cars`.`id` DESC LIMIT 1 +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+---------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+---------------------+ | 1 | SIMPLE | cars | NULL | index | NULL | PRIMARY | 8 | NULL | 1 | 100.0 | Backward index scan | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+---------------------+ 1 row in set (0.00 sec) . bin/test test/cases/explain_test.rb:102 F Failure: ExplainTest#test_relation_explain_with_first [test/cases/explain_test.rb:99]: Expected /SELECT\ `cars`\.\*\ FROM\ `cars`\ ORDER\ BY\ `cars`\.`id`\ ASC\ LIMIT\ \?/ to match EXPLAIN SELECT `cars`.* FROM `cars` ORDER BY `cars`.`id` ASC LIMIT 1 +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------+ | 1 | SIMPLE | cars | NULL | index | NULL | PRIMARY | 8 | NULL | 1 | 100.0 | NULL | +----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------+ 1 row in set (0.00 sec) . bin/test test/cases/explain_test.rb:93 ```
1 parent 3865f87 commit 83337df

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

activerecord/test/cases/explain_test.rb

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,26 @@ def test_relation_explain_with_sum
8989
assert_match(expected_query, message)
9090
end
9191

92-
def test_relation_explain_with_first
93-
expected_query = capture_sql {
94-
Car.all.first
95-
}.first
96-
message = Car.all.explain.first
97-
assert_match(/^EXPLAIN/, message)
98-
assert_match(expected_query, message)
99-
end
92+
unless current_adapter?(:Mysql2Adapter) && ActiveRecord::Base.lease_connection.prepared_statements
93+
def test_relation_explain_with_first
94+
expected_query = capture_sql {
95+
Car.all.first
96+
}.first
97+
message = Car.all.explain.first
98+
assert_match(/^EXPLAIN/, message)
99+
puts expected_query
100+
puts message
101+
assert_match(expected_query, message)
102+
end
100103

101-
def test_relation_explain_with_last
102-
expected_query = capture_sql {
103-
Car.all.last
104-
}.first
105-
message = Car.all.explain.last
106-
assert_match(/^EXPLAIN/, message)
107-
assert_match(expected_query, message)
104+
def test_relation_explain_with_last
105+
expected_query = capture_sql {
106+
Car.all.last
107+
}.first
108+
message = Car.all.explain.last
109+
assert_match(/^EXPLAIN/, message)
110+
assert_match(expected_query, message)
111+
end
108112
end
109113

110114
def test_relation_explain_with_pluck

0 commit comments

Comments
 (0)