Skip to content

Commit 2311cb0

Browse files
committed
Update coerced_tests.rb
1 parent af545ec commit 2311cb0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/cases/coerced_tests.rb

+23
Original file line numberDiff line numberDiff line change
@@ -2732,3 +2732,26 @@ def test_assert_queries_match_coerced
27322732
end
27332733
end
27342734
end
2735+
2736+
module ActiveRecord
2737+
class WithTest < ActiveRecord::TestCase
2738+
# SQL contains just 'WITH' instead of 'WITH RECURSIVE' as expected by the original test.
2739+
coerce_tests! :test_with_recursive
2740+
def test_with_recursive_coerced
2741+
top_companies = Company.where(firm_id: nil).to_a
2742+
child_companies = Company.where(firm_id: top_companies).to_a
2743+
top_companies_and_children = (top_companies.map(&:id) + child_companies.map(&:id)).sort
2744+
2745+
relation = Company.with_recursive(
2746+
top_companies_and_children: [
2747+
Company.where(firm_id: nil),
2748+
Company.joins("JOIN top_companies_and_children ON companies.firm_id = top_companies_and_children.id"),
2749+
]
2750+
).from("top_companies_and_children AS companies")
2751+
2752+
assert_equal top_companies_and_children, relation.order(:id).pluck(:id)
2753+
assert_match "WITH ", relation.to_sql
2754+
end
2755+
end
2756+
end
2757+

0 commit comments

Comments
 (0)