aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/select_manager_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/arel/select_manager_spec.rb')
-rw-r--r--spec/arel/select_manager_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/arel/select_manager_spec.rb b/spec/arel/select_manager_spec.rb
index 4262a7465b..3fe68a8db0 100644
--- a/spec/arel/select_manager_spec.rb
+++ b/spec/arel/select_manager_spec.rb
@@ -74,6 +74,17 @@ module Arel
end
end
+ describe 'clone' do
+ it 'creates new cores' do
+ table = Table.new :users, :engine => Table.engine, :as => 'foo'
+ mgr = table.from table
+ m2 = mgr.clone
+ m2.project "foo"
+
+ check mgr.to_sql.should_not == m2.to_sql
+ end
+ end
+
describe 'initialize' do
it 'uses alias in sql' do
table = Table.new :users, :engine => Table.engine, :as => 'foo'
@@ -354,6 +365,34 @@ module Arel
end
describe 'update' do
+ it 'copies limits' do
+ engine = EngineProxy.new Table.engine
+ table = Table.new :users
+ manager = Arel::SelectManager.new engine
+ manager.from table
+ manager.take 1
+ manager.update(SqlLiteral.new('foo = bar'))
+
+ engine.executed.last.should be_like %{
+ UPDATE "users" SET foo = bar
+ WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1)
+ }
+ end
+
+ it 'copies order' do
+ engine = EngineProxy.new Table.engine
+ table = Table.new :users
+ manager = Arel::SelectManager.new engine
+ manager.from table
+ manager.order :foo
+ manager.update(SqlLiteral.new('foo = bar'))
+
+ engine.executed.last.should be_like %{
+ UPDATE "users" SET foo = bar
+ WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo)
+ }
+ end
+
it 'takes a string' do
engine = EngineProxy.new Table.engine
table = Table.new :users