From a5d62729799ed58ce344dba0621e951dbc92ab3f Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Thu, 3 Jan 2008 23:41:43 -0800 Subject: new usage of builder ` --- spec/relations/attribute_spec.rb | 1 + spec/relations/join_relation_spec.rb | 22 ++++++++++++++-------- spec/relations/order_relation_spec.rb | 15 +++++++++------ spec/relations/projection_relation_spec.rb | 10 +++++----- spec/relations/range_relation_spec.rb | 5 ++++- spec/relations/relation_spec.rb | 8 -------- spec/relations/selection_relation_spec.rb | 9 ++++++--- spec/relations/table_relation_spec.rb | 5 ++++- 8 files changed, 43 insertions(+), 32 deletions(-) (limited to 'spec/relations') diff --git a/spec/relations/attribute_spec.rb b/spec/relations/attribute_spec.rb index 5ddbaa96b5..d8a007f918 100644 --- a/spec/relations/attribute_spec.rb +++ b/spec/relations/attribute_spec.rb @@ -57,6 +57,7 @@ describe Attribute do end end + describe '#to_sql' do it "manufactures a column" do Attribute.new(@relation1, :attribute_name, :alias).to_sql.should == SelectsBuilder.new do diff --git a/spec/relations/join_relation_spec.rb b/spec/relations/join_relation_spec.rb index a7c15fd76a..bae294440e 100644 --- a/spec/relations/join_relation_spec.rb +++ b/spec/relations/join_relation_spec.rb @@ -4,7 +4,7 @@ describe 'between two relations' do before do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) - @predicate = EqualityPredicate.new(@relation1[:a], @relation2[:b]) + @predicate = EqualityPredicate.new(@relation1[:id], @relation2[:id]) end describe '==' do @@ -20,9 +20,9 @@ describe 'between two relations' do describe '#to_sql' do before do - @relation1 = @relation1.select(@relation1[:c] == @relation2[:d]) + @relation1 = @relation1.select(@relation1[:id] == @relation2[:foo_id]) class ConcreteJoinRelation < JoinRelation - def join_name + def join_type :inner_join end end @@ -30,19 +30,25 @@ describe 'between two relations' do it 'manufactures sql joining the two tables on the predicate, merging the selects' do ConcreteJoinRelation.new(@relation1, @relation2, @predicate).to_sql.to_s.should == SelectBuilder.new do - select { all } + select do + column :foo, :name + column :foo, :id + column :bar, :name + column :bar, :foo_id + column :bar, :id + end from :foo do inner_join :bar do equals do - column :foo, :a - column :bar, :b + column :foo, :id + column :bar, :id end end end where do equals do - column :foo, :c - column :bar, :d + column :foo, :id + column :bar, :foo_id end end end.to_s diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb index 8050aa981c..d0654bd8da 100644 --- a/spec/relations/order_relation_spec.rb +++ b/spec/relations/order_relation_spec.rb @@ -4,8 +4,8 @@ describe OrderRelation do before do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) - @attribute1 = @relation1[:foo] - @attribute2 = @relation2[:bar] + @attribute1 = @relation1[:id] + @attribute2 = @relation2[:id] end describe '==' do @@ -18,13 +18,16 @@ describe OrderRelation do describe '#to_sql' do it "manufactures sql with an order clause" do - OrderRelation.new(@relation1, @attribute1).to_sql.should == SelectBuilder.new do - select { all } + OrderRelation.new(@relation1, @attribute1).to_sql.to_s.should == SelectBuilder.new do + select do + column :foo, :name + column :foo, :id + end from :foo order_by do - column :foo, :foo + column :foo, :id end - end + end.to_s end end diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb index f17f57df7b..47386f966d 100644 --- a/spec/relations/projection_relation_spec.rb +++ b/spec/relations/projection_relation_spec.rb @@ -4,8 +4,8 @@ describe ProjectionRelation do before do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) - @attribute1 = @relation1[:foo] - @attribute2 = @relation2[:bar] + @attribute1 = @relation1[:id] + @attribute2 = @relation2[:id] end describe '==' do @@ -18,12 +18,12 @@ describe ProjectionRelation do describe '#to_sql' do it "manufactures sql with a limited select clause" do - ProjectionRelation.new(@relation1, @attribute1).to_sql.should == SelectBuilder.new do + ProjectionRelation.new(@relation1, @attribute1).to_sql.to_s.should == SelectBuilder.new do select do - column :foo, :foo + column :foo, :id end from :foo - end + end.to_s end end end \ No newline at end of file diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb index e6caa32e80..ea3901e3fd 100644 --- a/spec/relations/range_relation_spec.rb +++ b/spec/relations/range_relation_spec.rb @@ -21,7 +21,10 @@ describe RangeRelation do range_size = @range2.last - @range2.first + 1 range_start = @range2.first RangeRelation.new(@relation1, @range2).to_sql.to_s.should == SelectBuilder.new do - select { all } + select do + column :foo, :name + column :foo, :id + end from :foo limit range_size offset range_start diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb index 6c2c2b8611..db4b6b8775 100644 --- a/spec/relations/relation_spec.rb +++ b/spec/relations/relation_spec.rb @@ -30,10 +30,6 @@ describe Relation do it "manufactures a range relation when given a range" do @relation1[1..2].should == RangeRelation.new(@relation1, 1..2) end - - it "raises an error if the named attribute is not part of the relation" do - pending - end end describe Relation, '#include?' do @@ -43,10 +39,6 @@ describe Relation do end describe Relation, '#project' do - it "only allows projecting attributes in the relation" do - pending - end - it "collapses identical projections" do pending end diff --git a/spec/relations/selection_relation_spec.rb b/spec/relations/selection_relation_spec.rb index ceb771b46d..1a7f9e6659 100644 --- a/spec/relations/selection_relation_spec.rb +++ b/spec/relations/selection_relation_spec.rb @@ -28,8 +28,11 @@ describe SelectionRelation do describe '#to_sql' do it "manufactures sql with where clause conditions" do - SelectionRelation.new(@relation1, @predicate1).to_sql.should == SelectBuilder.new do - select { all } + SelectionRelation.new(@relation1, @predicate1).to_sql.to_s.should == SelectBuilder.new do + select do + column :foo, :name + column :foo, :id + end from :foo where do equals do @@ -37,7 +40,7 @@ describe SelectionRelation do column :bar, :foo_id end end - end + end.to_s end end end \ No newline at end of file diff --git a/spec/relations/table_relation_spec.rb b/spec/relations/table_relation_spec.rb index 7a820782df..8cd31a9ac8 100644 --- a/spec/relations/table_relation_spec.rb +++ b/spec/relations/table_relation_spec.rb @@ -3,7 +3,10 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper') describe TableRelation, '#to_sql' do it "returns a simple SELECT query" do TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s| - select { all } + select do + column :users, :name + column :users, :id + end from :users end end -- cgit v1.2.3