aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-11-05 16:33:26 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-05 16:33:26 -0700
commitdbd0140974ed768705f3680d5d6e47a56305b965 (patch)
tree5b2e6973c84e582e483b9f69b25348ff20d2514b /test
parent22a38c6a86bc6323f7aa1fd3179a9f8ed7591267 (diff)
downloadrails-dbd0140974ed768705f3680d5d6e47a56305b965.tar.gz
rails-dbd0140974ed768705f3680d5d6e47a56305b965.tar.bz2
rails-dbd0140974ed768705f3680d5d6e47a56305b965.zip
arel more nicely supports EXISTS queries
Diffstat (limited to 'test')
-rw-r--r--test/test_select_manager.rb28
1 files changed, 22 insertions, 6 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index ebec92b1da..d63bec0093 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -56,9 +56,7 @@ module Arel
manager.project SqlLiteral.new '*'
manager.from table
manager.order :foo
- manager.to_sql.must_be_like %{
- SELECT * FROM "users" ORDER BY foo
- }
+ manager.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo }
end
end
@@ -68,9 +66,7 @@ module Arel
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.group :foo
- manager.to_sql.must_be_like %{
- SELECT FROM "users" GROUP BY foo
- }
+ manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo }
end
end
@@ -130,6 +126,26 @@ module Arel
end
end
+ describe 'exists' do
+ it 'should create an exists clause' do
+ table = Table.new(:users)
+ manager = Arel::SelectManager.new Table.engine, table
+ manager.project SqlLiteral.new '*'
+ m2 = Arel::SelectManager.new(manager.engine)
+ m2.project manager.exists
+ m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) }
+ end
+
+ it 'can be aliased' do
+ table = Table.new(:users)
+ manager = Arel::SelectManager.new Table.engine, table
+ manager.project SqlLiteral.new '*'
+ m2 = Arel::SelectManager.new(manager.engine)
+ m2.project manager.exists.as('foo')
+ m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) AS foo }
+ end
+ end
+
describe 'ast' do
it 'should return the ast' do
table = Table.new :users