diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-13 19:42:36 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-13 19:42:36 -0300 |
commit | 282bb10a6dcd7e488ea441dd40033bf0f9ecb6c3 (patch) | |
tree | d0bddaaecd9791e4476119241e278130e4d23526 /test | |
parent | 22136deb66c79e37e68ea0f061389a3317601c92 (diff) | |
parent | b4bec045a8bb89c2a2cfc06a8071b34a97723de7 (diff) | |
download | rails-282bb10a6dcd7e488ea441dd40033bf0f9ecb6c3.tar.gz rails-282bb10a6dcd7e488ea441dd40033bf0f9ecb6c3.tar.bz2 rails-282bb10a6dcd7e488ea441dd40033bf0f9ecb6c3.zip |
Merge pull request #289 from mekishizufu/fix_with_statements
Fix WITH statements
Diffstat (limited to 'test')
-rw-r--r-- | test/test_select_manager.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 09608ea71e..4678901bb4 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -330,6 +330,20 @@ module Arel end describe 'with' do + it 'should support basic WITH' do + users = Table.new(:users) + users_top = Table.new(:users_top) + comments = Table.new(:comments) + + top = users.project(users[:id]).where(users[:karma].gt(100)) + users_as = Arel::Nodes::As.new(users_top, top) + select_manager = comments.project(Arel.star).with(users_as) + .where(comments[:author_id].in(users_top.project(users_top[:id]))) + + select_manager.to_sql.must_be_like %{ + WITH "users_top" AS (SELECT "users"."id" FROM "users" WHERE "users"."karma" > 100) SELECT * FROM "comments" WHERE "comments"."author_id" IN (SELECT "users_top"."id" FROM "users_top") + } + end it "should support WITH RECURSIVE" do comments = Table.new(:comments) |