File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2732,3 +2732,26 @@ def test_assert_queries_match_coerced
2732
2732
end
2733
2733
end
2734
2734
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
+
You can’t perform that action at this time.
0 commit comments