aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-24 16:55:24 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-24 16:56:01 -0300
commitc479480638508c20601af69ca46b5b606c2d5b4d (patch)
treeff42658b68c7cea5dacf94b1160c181e0470080f /activerecord/test/cases
parent2bc72ae29c660a2d9bf6b1b42db4fe18f0d1492f (diff)
downloadrails-c479480638508c20601af69ca46b5b606c2d5b4d.tar.gz
rails-c479480638508c20601af69ca46b5b606c2d5b4d.tar.bz2
rails-c479480638508c20601af69ca46b5b606c2d5b4d.zip
Merge pull request #18744 from mfazekas/no-table-name-with-from
Fix appending table_name to select and group when used with subquery (fr...
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/relations_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index dec3a37f42..0cf44388fa 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -157,6 +157,17 @@ class RelationTest < ActiveRecord::TestCase
end
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')
+ assert_equal(relation.map(&:post_count).sort,subquery.map(&:post_count).sort)
+ end
+
+ def test_group_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).group('type').average("post_count")
+ assert_equal(relation.map(&:post_count).sort,subquery.values.sort)
+ end
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)