aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index adc50a694e..1781a015bc 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -182,6 +182,45 @@ class RelationTest < ActiveRecord::TestCase
end
end
+ def test_select_with_original_table_name_in_from
+ relation = Comment.joins(:post).select(:id).order(:id)
+ subquery = Comment.from(Comment.table_name).joins(:post).select(:id).order(:id)
+ assert_equal relation.map(&:id), subquery.map(&:id)
+ end
+
+ def test_pluck_with_original_table_name_in_from
+ relation = Comment.joins(:post).order(:id)
+ subquery = Comment.from(Comment.table_name).joins(:post).order(:id)
+ assert_equal relation.pluck(:id), subquery.pluck(:id)
+ end
+
+ def test_select_with_quoted_original_table_name_in_from
+ relation = Comment.joins(:post).select(:id).order(:id)
+ subquery = Comment.from(Comment.quoted_table_name).joins(:post).select(:id).order(:id)
+ assert_equal relation.map(&:id), subquery.map(&:id)
+ end
+
+ def test_pluck_with_quoted_original_table_name_in_from
+ relation = Comment.joins(:post).order(:id)
+ subquery = Comment.from(Comment.quoted_table_name).joins(:post).order(:id)
+ assert_equal relation.pluck(:id), subquery.pluck(:id)
+ end
+
+ def test_select_with_subquery_in_from_uses_original_table_name
+ if current_adapter?(:SQLite3Adapter) && ENV["TRAVIS"]
+ skip "https://travis-ci.org/rails/rails/jobs/496726410#L1198-L1208"
+ end
+ relation = Comment.joins(:post).select(:id).order(:id)
+ subquery = Comment.from(Comment.all, Comment.quoted_table_name).joins(:post).select(:id).order(:id)
+ assert_equal relation.map(&:id), subquery.map(&:id)
+ end
+
+ def test_pluck_with_subquery_in_from_uses_original_table_name
+ relation = Comment.joins(:post).order(:id)
+ subquery = Comment.from(Comment.all, Comment.quoted_table_name).joins(:post).order(:id)
+ assert_equal relation.pluck(:id), subquery.pluck(:id)
+ end
+
def test_select_with_subquery_in_from_does_not_use_original_table_name
relation = Comment.group(:type).select("COUNT(post_id) AS post_count, type")
subquery = Comment.from(relation).select("type", "post_count")