From 2f4d690247b4263d6abb553405059aa1e0358f7e Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Mon, 20 May 2024 12:08:33 +0100 Subject: [PATCH] Coerced some explain tests --- test/cases/coerced_tests.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index a69a52308..2f31184ba 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -2684,3 +2684,30 @@ def type_for_attribute_is_not_aware_of_custom_types_coerced end end end + +require "models/car" +class ExplainTest < ActiveRecord::TestCase + # Expected query slightly different from because of 'sp_executesql' and query parameters. + coerce_tests! :test_relation_explain_with_first + def test_relation_explain_with_first_coerced + expected_query = capture_sql { + Car.all.first + }.first[/EXEC sp_executesql N'(.*?) NEXT/, 1] + message = Car.all.explain.first + assert_match(/^EXPLAIN/, message) + assert_match(expected_query, message) + end + + # Expected query slightly different from because of 'sp_executesql' and query parameters. + coerce_tests! :test_relation_explain_with_last + def test_relation_explain_with_last_coerced + expected_query = capture_sql { + Car.all.last + }.first[/EXEC sp_executesql N'(.*?) NEXT/, 1] + expected_query = expected_query + message = Car.all.explain.last + + assert_match(/^EXPLAIN/, message) + assert_match(expected_query, message) + end +end