Skip to content

Commit 702d212

Browse files
committed
Update coerced_tests.rb
1 parent c3fab52 commit 702d212

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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
853870
end
854871

855872
require "models/topic"

0 commit comments

Comments
 (0)