Skip to content

Commit

Permalink
Create failing test case for from with subquery
Browse files Browse the repository at this point in the history
After rails#35360 was merged we bumped Rails again and while the test script
we sent passed we still had the same failures. I debugged a bit and
found that the new code assumes that the `from` is passing only a table
name and that we can get that from `name` or from `value` but there are
cases (like this test case) where you may not pass a name along with the
`FromClause` and the value may not be just a table name.

This test demonstrates what happens when you add an index to the from
clause.
  • Loading branch information
eileencodes committed Feb 28, 2019
1 parent 81710da commit f5173b8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions activerecord/test/cases/relations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ def test_finding_with_order
assert_equal topics(:first).title, topics.first.title
end

if current_adapter?(:SQLite3Adapter)
def test_pluck_with_subquery_with_as_uses_original_table_name
relation = Company.joins(:contracts).order(:id)
subquery = Company.from("#{Company.quoted_table_name} INDEXED BY company_index").joins(:contracts).order(:id)
assert_equal relation.pluck(:id), subquery.pluck(:id)
end
end

if current_adapter?(:Mysql2Adapter)
def test_pluck_with_subquery_with_as_uses_original_table_name
relation = Company.joins(:contracts).order(:id)
subquery = Company.from("#{Company.quoted_table_name} USE INDEX (company_index)").joins(:contracts).order(:id)
assert_equal relation.pluck(:id), subquery.pluck(:id)
end
end

def test_finding_with_arel_order
topics = Topic.order(Topic.arel_table[:id].asc)
assert_equal 5, topics.to_a.size
Expand Down

0 comments on commit f5173b8

Please sign in to comment.