Skip to content

Commit 716bbb4

Browse files
committed
Fix failing ActiveRecord::RelationTest tests
1 parent 8b97fef commit 716bbb4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,24 @@ def test_reverse_arel_assoc_order_with_function_coerced
742742
end
743743
end
744744

745+
class ActiveRecord::RelationTest < ActiveRecord::TestCase
746+
coerce_tests! :test_relation_merging_with_merged_symbol_joins_is_aliased
747+
def test_relation_merging_with_merged_symbol_joins_is_aliased__coerced
748+
categorizations_with_authors = Categorization.joins(:author)
749+
queries = capture_sql { Post.joins(:author, :categorizations).merge(Author.select(:id)).merge(categorizations_with_authors).to_a }
750+
751+
nb_inner_join = queries.sum { |sql| sql.scan(/INNER\s+JOIN/i).size }
752+
assert_equal 3, nb_inner_join, "Wrong amount of INNER JOIN in query"
753+
754+
# using `\W` as the column separator
755+
query_matches = queries.any? do |sql|
756+
%r[INNER\s+JOIN\s+#{Regexp.escape(Author.quoted_table_name)}\s+\Wauthors_categorizations\W]i.match?(sql)
757+
end
758+
759+
assert query_matches, "Should be aliasing the child INNER JOINs in query"
760+
end
761+
end
762+
745763

746764

747765

0 commit comments

Comments
 (0)