diff options
Diffstat (limited to 'test/test_select_manager.rb')
-rw-r--r-- | test/test_select_manager.rb | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index f457c55f40..2fe43aa982 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -30,6 +30,10 @@ module Arel @engine.connection.columns table, message end + def columns_hash + @engine.connection.columns_hash + end + def table_exists? name @engine.connection.table_exists? name end @@ -122,6 +126,24 @@ module Arel mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar } end end + + describe 'on' do + it 'converts to sqlliterals' do + table = Table.new :users + right = table.alias + mgr = table.from table + mgr.join(right).on("omg") + mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg } + end + + it 'converts to sqlliterals' do + table = Table.new :users + right = table.alias + mgr = table.from table + mgr.join(right).on("omg", "123") + mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg AND 123 } + end + end end describe 'clone' do @@ -158,6 +180,32 @@ module Arel end end + describe 'offset' do + it 'should add an offset' do + table = Table.new :users + mgr = table.from table + mgr.offset = 10 + mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } + end + + it 'should remove an offset' do + table = Table.new :users + mgr = table.from table + mgr.offset = 10 + mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } + + mgr.offset = nil + mgr.to_sql.must_be_like %{ SELECT FROM "users" } + end + + it 'should return the offset' do + table = Table.new :users + mgr = table.from table + mgr.offset = 10 + assert_equal 10, mgr.offset + end + end + describe 'exists' do it 'should create an exists clause' do table = Table.new(:users) @@ -288,9 +336,7 @@ module Arel as_statement = Arel::Nodes::As.new replies, union manager = Arel::SelectManager.new Table.engine - manager.from replies - manager.with :recursive, as_statement - manager.project Arel.star + manager.with(:recursive, as_statement).from(replies).project(Arel.star) sql = manager.to_sql sql.must_be_like %{ @@ -302,7 +348,6 @@ module Arel SELECT * FROM "replies" } end - end describe 'ast' do @@ -724,6 +769,15 @@ module Arel manager = Arel::SelectManager.new Table.engine manager.take(1).must_equal manager end + + it 'removes LIMIT when nil is passed' do + manager = Arel::SelectManager.new Table.engine + manager.limit = 10 + assert_match('LIMIT', manager.to_sql) + + manager.limit = nil + refute_match('LIMIT', manager.to_sql) + end end describe 'where' do |