aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 16:50:03 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 16:50:03 -0700
commitf413129f37bbbc4100317cb60179f43291e69f8e (patch)
treef640bfb9223d60f7ed46add9f157f30048b245bb /spec
parent85bc3b417dc4e1ecad76fa89b5d195e2db8f5ff5 (diff)
downloadrails-f413129f37bbbc4100317cb60179f43291e69f8e.tar.gz
rails-f413129f37bbbc4100317cb60179f43291e69f8e.tar.bz2
rails-f413129f37bbbc4100317cb60179f43291e69f8e.zip
Table names seem to be disambiguated.
- Code is a mess, about to undergo some refactoring
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/unit/relations/grouping_spec.rb4
-rw-r--r--spec/arel/unit/relations/join_spec.rb22
-rw-r--r--spec/arel/unit/relations/projection_spec.rb11
-rw-r--r--spec/arel/unit/relations/table_spec.rb7
4 files changed, 15 insertions, 29 deletions
diff --git a/spec/arel/unit/relations/grouping_spec.rb b/spec/arel/unit/relations/grouping_spec.rb
index bef3566896..66205b8f95 100644
--- a/spec/arel/unit/relations/grouping_spec.rb
+++ b/spec/arel/unit/relations/grouping_spec.rb
@@ -6,7 +6,7 @@ module Arel
@relation = Table.new(:users)
@attribute = @relation[:id]
end
-
+
describe '#to_sql' do
describe 'when given a predicate' do
it "manufactures sql with where clause conditions" do
@@ -20,7 +20,7 @@ module Arel
describe 'when given a string' do
it "passes the string through to the where clause" do
- pending 'it should not quote asdf'
+ pending 'it should not quote the group clause'
Grouping.new(@relation, 'asdf').to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`
FROM `users`
diff --git a/spec/arel/unit/relations/join_spec.rb b/spec/arel/unit/relations/join_spec.rb
index 0c2d1d771d..52e1a93b8e 100644
--- a/spec/arel/unit/relations/join_spec.rb
+++ b/spec/arel/unit/relations/join_spec.rb
@@ -47,15 +47,6 @@ module Arel
end
end
- describe '#prefix_for' do
- it "returns the name of the relation containing the attribute" do
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).prefix_for(@relation1[:id]) \
- .should == @relation1.prefix_for(@relation1[:id])
- Join.new("INNER JOIN", @relation1, @relation2, @predicate).prefix_for(@relation2[:id]) \
- .should == @relation2.prefix_for(@relation2[:id])
- end
- end
-
describe '#to_sql' do
it 'manufactures sql joining the two tables on the predicate' do
Join.new("INNER JOIN", @relation1, @relation2, @predicate).to_sql.should be_like("
@@ -116,6 +107,7 @@ module Arel
end
end
+ # TESTME try other direction too!
it "keeps selects on the aggregation within the derived table" do
Join.new("INNER JOIN", @relation1, @aggregation.select(@aggregation[:user_id].eq(1)), @predicate).to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`, `photos_aggregation`.`user_id`, `photos_aggregation`.`cnt`
@@ -133,16 +125,6 @@ module Arel
@predicate = @relation1[:id].eq(@aliased_relation[:id])
end
- describe '#prefix_for' do
- it "returns the alias of the relation containing the attribute" do
- relation = Join.new("INNER JOIN", @relation1, @aliased_relation, @predicate)
- relation.prefix_for(@aliased_relation[:id]) \
- .should == @relation1.name
- relation.prefix_for(@relation1[:id]) \
- .should == @relation1.name + '_2'
- end
- end
-
describe 'when joining the same relation to itself' do
describe '#to_sql' do
it '' do
@@ -151,6 +133,7 @@ module Arel
@relation1 \
.join(relation2.join(relation3).on(relation2[:id].eq(relation3[:id]))) \
.on(@relation1[:id].eq(relation2[:id])) \
+ .select(@relation1[:id].eq(1)) \
.to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
FROM `users`
@@ -158,6 +141,7 @@ module Arel
ON `users`.`id` = `users_2`.`id`
INNER JOIN `users` AS `users_3`
ON `users_2`.`id` = `users_3`.`id`
+ WHERE `users`.`id` = 1
")
end
diff --git a/spec/arel/unit/relations/projection_spec.rb b/spec/arel/unit/relations/projection_spec.rb
index cd59d6c383..eedcf77952 100644
--- a/spec/arel/unit/relations/projection_spec.rb
+++ b/spec/arel/unit/relations/projection_spec.rb
@@ -47,7 +47,7 @@ module Arel
it "manufactures sql with scalar selects" do
Projection.new(@relation, @scalar_relation).to_sql.should be_like("
- SELECT (SELECT `users`.`name` FROM `users`) FROM `users`
+ SELECT (SELECT `users`.`name` FROM `users`) AS `users` FROM `users`
")
end
end
@@ -59,6 +59,15 @@ module Arel
")
end
end
+
+ describe 'when given an expression' do
+ it 'manufactures sql with expressions' do
+ @relation.project(@attribute.count).to_sql.should be_like("
+ SELECT COUNT(`users`.`id`)
+ FROM `users`
+ ")
+ end
+ end
end
describe Projection::Externalizable do
diff --git a/spec/arel/unit/relations/table_spec.rb b/spec/arel/unit/relations/table_spec.rb
index eb765ce777..54520bf3b6 100644
--- a/spec/arel/unit/relations/table_spec.rb
+++ b/spec/arel/unit/relations/table_spec.rb
@@ -51,13 +51,6 @@ module Arel
end
end
- describe '#prefix_for' do
- it "returns the table name if the relation contains the attribute" do
- @relation.prefix_for(@relation[:id]).should == 'users'
- @relation.prefix_for(:does_not_exist).should be_nil
- end
- end
-
describe '#attributes' do
it 'manufactures attributes corresponding to columns in the table' do
@relation.attributes.should == [