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 May 24, 2024
1 parent af545ec commit 2311cb0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2732,3 +2732,26 @@ def test_assert_queries_match_coerced
end
end
end

module ActiveRecord
class WithTest < ActiveRecord::TestCase
# SQL contains just 'WITH' instead of 'WITH RECURSIVE' as expected by the original test.
coerce_tests! :test_with_recursive
def test_with_recursive_coerced
top_companies = Company.where(firm_id: nil).to_a
child_companies = Company.where(firm_id: top_companies).to_a
top_companies_and_children = (top_companies.map(&:id) + child_companies.map(&:id)).sort

relation = Company.with_recursive(
top_companies_and_children: [
Company.where(firm_id: nil),
Company.joins("JOIN top_companies_and_children ON companies.firm_id = top_companies_and_children.id"),
]
).from("top_companies_and_children AS companies")

assert_equal top_companies_and_children, relation.order(:id).pluck(:id)
assert_match "WITH ", relation.to_sql
end
end
end

0 comments on commit 2311cb0

Please sign in to comment.