From f413129f37bbbc4100317cb60179f43291e69f8e Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 4 May 2008 16:50:03 -0700 Subject: Table names seem to be disambiguated. - Code is a mess, about to undergo some refactoring --- spec/arel/unit/relations/grouping_spec.rb | 4 ++-- spec/arel/unit/relations/join_spec.rb | 22 +++------------------- spec/arel/unit/relations/projection_spec.rb | 11 ++++++++++- spec/arel/unit/relations/table_spec.rb | 7 ------- 4 files changed, 15 insertions(+), 29 deletions(-) (limited to 'spec') 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 == [ -- cgit v1.2.3