@@ -1585,7 +1585,47 @@ def test_has_primary_key_coerced
15851585end
15861586
15871587class ReloadModelsTest < ActiveRecord ::TestCase
1588- # Skip test on Windows. The number of arguements passed to `IO.popen` in
1588+ # Skip test on Windows. The number of arguments passed to `IO.popen` in
15891589 # `activesupport/lib/active_support/testing/isolation.rb` exceeds what Windows can handle.
15901590 coerce_tests! :test_has_one_with_reload if RbConfig ::CONFIG [ "host_os" ] =~ /mswin|mingw/
15911591end
1592+
1593+ require "models/post"
1594+ class AnnotateTest < ActiveRecord ::TestCase
1595+ # Same as original coerced test except our SQL starts with `EXEC sp_executesql`.
1596+ coerce_tests! :test_annotate_wraps_content_in_an_inline_comment
1597+ def test_annotate_wraps_content_in_an_inline_comment_coerced
1598+ quoted_posts_id , quoted_posts = regexp_escape_table_name ( "posts.id" ) , regexp_escape_table_name ( "posts" )
1599+
1600+ assert_sql ( %r{SELECT #{ quoted_posts_id } FROM #{ quoted_posts } /\* foo \* /}i ) do
1601+ posts = Post . select ( :id ) . annotate ( "foo" )
1602+ assert posts . first
1603+ end
1604+ end
1605+
1606+ # Same as original coerced test except our SQL starts with `EXEC sp_executesql`.
1607+ coerce_tests! :test_annotate_is_sanitized
1608+ def test_annotate_is_sanitized_coerced
1609+ quoted_posts_id , quoted_posts = regexp_escape_table_name ( "posts.id" ) , regexp_escape_table_name ( "posts" )
1610+
1611+ assert_sql ( %r{SELECT #{ quoted_posts_id } FROM #{ quoted_posts } /\* foo \* /}i ) do
1612+ posts = Post . select ( :id ) . annotate ( "*/foo/*" )
1613+ assert posts . first
1614+ end
1615+
1616+ assert_sql ( %r{SELECT #{ quoted_posts_id } FROM #{ quoted_posts } /\* foo \* /}i ) do
1617+ posts = Post . select ( :id ) . annotate ( "**//foo//**" )
1618+ assert posts . first
1619+ end
1620+
1621+ assert_sql ( %r{SELECT #{ quoted_posts_id } FROM #{ quoted_posts } /\* foo \* / /\* bar \* /}i ) do
1622+ posts = Post . select ( :id ) . annotate ( "*/foo/*" ) . annotate ( "*/bar" )
1623+ assert posts . first
1624+ end
1625+
1626+ assert_sql ( %r{SELECT #{ quoted_posts_id } FROM #{ quoted_posts } /\* \+ MAX_EXECUTION_TIME\( 1\) \* /}i ) do
1627+ posts = Post . select ( :id ) . annotate ( "+ MAX_EXECUTION_TIME(1)" )
1628+ assert posts . first
1629+ end
1630+ end
1631+ end
0 commit comments