aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/nodes/select_statement_spec.rb4
-rw-r--r--spec/arel/select_manager_spec.rb39
-rw-r--r--spec/arel/table_spec.rb6
3 files changed, 47 insertions, 2 deletions
diff --git a/spec/arel/nodes/select_statement_spec.rb b/spec/arel/nodes/select_statement_spec.rb
index 75463f1d95..68bde3c4f7 100644
--- a/spec/arel/nodes/select_statement_spec.rb
+++ b/spec/arel/nodes/select_statement_spec.rb
@@ -5,10 +5,10 @@ describe Arel::Nodes::SelectStatement do
it "clones cores" do
statement = Arel::Nodes::SelectStatement.new %w[a b c]
- statement.cores.should_receive(:clone).and_return([:cores])
+ statement.cores.map { |x| x.should_receive(:clone).and_return(:f) }
dolly = statement.clone
- dolly.cores.should == [:cores]
+ dolly.cores.should == [:f, :f, :f]
end
end
end
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
diff --git a/spec/arel/table_spec.rb b/spec/arel/table_spec.rb
index 7cc0b20a25..5b68040aac 100644
--- a/spec/arel/table_spec.rb
+++ b/spec/arel/table_spec.rb
@@ -6,6 +6,12 @@ module Arel
@relation = Table.new(:users)
end
+ describe 'primary_key' do
+ it 'should return an attribute' do
+ check @relation.primary_key.name.should == :id
+ end
+ end
+
describe 'having' do
it 'adds a having clause' do
mgr = @relation.having @relation[:id].eq(10)