Skip to content

Commit

Permalink
Update coerced_tests.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Sep 21, 2023
1 parent c3fab52 commit 702d212
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,23 @@ def test_count_with_include_coerced

# Use TOP (1) in scope vs limit 1.
coerce_tests! %r{including association based on sql condition and no database column}

# Table name not regex escaped in original test. Remove coerced test when https://github.com/rails/rails/pull/49345 merged.
coerce_tests! %r{preloading belongs_to association SQL}
test "preloading belongs_to association SQL coerced" do
blog_ids = [sharded_blogs(:sharded_blog_one).id, sharded_blogs(:sharded_blog_two).id]
posts = Sharded::BlogPost.where(blog_id: blog_ids).includes(:comments)

sql = capture_sql do
comments_collection = posts.map(&:comments)
assert_equal 3, comments_collection.size
end.last

c = Sharded::BlogPost.connection
quoted_blog_id = Regexp.escape(c.quote_table_name("sharded_comments.blog_id"))
quoted_blog_post_id = Regexp.escape(c.quote_table_name("sharded_comments.blog_post_id"))
assert_match(/WHERE #{quoted_blog_id} IN \(.+\) AND #{quoted_blog_post_id} IN \(.+\)/, sql)
end
end

require "models/topic"
Expand Down

0 comments on commit 702d212

Please sign in to comment.