aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_select_manager.rb
diff options
context:
space:
mode:
authorJoel Bryan Juliano <joel.juliano@extensioncorporation.com>2011-10-31 00:42:22 -0500
committerJoel Bryan Juliano <joel.juliano@extensioncorporation.com>2011-10-31 00:42:22 -0500
commitd75a0ef0d5139348b7b4d046374502824254a076 (patch)
treed104f51664581a1f9b533728e6466a4afdd7a95e /test/test_select_manager.rb
parent45f87174d11dc549a059b7a041172db25bcc32ce (diff)
downloadrails-d75a0ef0d5139348b7b4d046374502824254a076.tar.gz
rails-d75a0ef0d5139348b7b4d046374502824254a076.tar.bz2
rails-d75a0ef0d5139348b7b4d046374502824254a076.zip
Added a failing test for a non-table alias as rhs relation name
Diffstat (limited to 'test/test_select_manager.rb')
-rw-r--r--test/test_select_manager.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index 7e9099d0d0..ca47b873a2 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -654,6 +654,24 @@ module Arel
}
end
+ it 'can have a non-table alias as relation name' do
+ users = Table.new :users
+ comments = Table.new :comments
+
+ counts = comments.from(comments).
+ group(comments[:user_id]).
+ project(
+ comments[:user_id].as("user_id"),
+ comments[:user_id].count.as("count")
+ ).as("counts")
+
+ joins = users.join(counts).on(counts[:user_id].eq(10))
+ joins.to_sql.must_be_like %{
+ SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10
+
+ }
+ end
+
it 'returns string join sql' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine