File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -850,6 +850,23 @@ def test_count_with_include_coerced
850850
851851 # Use TOP (1) in scope vs limit 1.
852852 coerce_tests! %r{including association based on sql condition and no database column}
853+
854+ # Table name not regex escaped in original test. Remove coerced test when https://github.com/rails/rails/pull/49345 merged.
855+ coerce_tests! %r{preloading belongs_to association SQL}
856+ test "preloading belongs_to association SQL coerced" do
857+ blog_ids = [ sharded_blogs ( :sharded_blog_one ) . id , sharded_blogs ( :sharded_blog_two ) . id ]
858+ posts = Sharded ::BlogPost . where ( blog_id : blog_ids ) . includes ( :comments )
859+
860+ sql = capture_sql do
861+ comments_collection = posts . map ( &:comments )
862+ assert_equal 3 , comments_collection . size
863+ end . last
864+
865+ c = Sharded ::BlogPost . connection
866+ quoted_blog_id = Regexp . escape ( c . quote_table_name ( "sharded_comments.blog_id" ) )
867+ quoted_blog_post_id = Regexp . escape ( c . quote_table_name ( "sharded_comments.blog_post_id" ) )
868+ assert_match ( /WHERE #{ quoted_blog_id } IN \( .+\) AND #{ quoted_blog_post_id } IN \( .+\) / , sql )
869+ end
853870end
854871
855872require "models/topic"
You can’t perform that action at this time.
0 commit comments