From 2f9b70b6179d0b66f80d6edd3eca1017aec70659 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sat, 12 Apr 2008 17:45:36 -0700 Subject: better test coverage of relational operations with blank data --- .../unit/relations/relation_spec.rb | 61 +++++++++++++++++----- spec/active_relation/unit/relations/rename_spec.rb | 50 ------------------ 2 files changed, 48 insertions(+), 63 deletions(-) delete mode 100644 spec/active_relation/unit/relations/rename_spec.rb (limited to 'spec') diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb index fa66352c91..2b62c8db5e 100644 --- a/spec/active_relation/unit/relations/relation_spec.rb +++ b/spec/active_relation/unit/relations/relation_spec.rb @@ -57,6 +57,12 @@ module ActiveRelation @relation.join(arbitrary_string = "ASDF").should == Join.new(arbitrary_string, @relation) end end + + describe "when given something blank" do + it "returns self" do + @relation.join.should == @relation + end + end end describe '#outer_join' do @@ -72,17 +78,23 @@ module ActiveRelation @relation.project(@attribute1, @attribute2). \ should == Projection.new(@relation, @attribute1, @attribute2) end + + describe "when given blank attributes" do + it "returns self" do + @relation.project.should == @relation + end + end end describe '#as' do it "manufactures an alias relation" do @relation.as(:paul).should == Alias.new(@relation, :paul) end - end - - describe '#rename' do - it "manufactures a rename relation" do - @relation.rename(@attribute1, :users).should == Rename.new(@relation, @attribute1 => :users) + + describe 'when given a blank alias' do + it 'returns self' do + @relation.as.should == @relation + end end end @@ -98,34 +110,50 @@ module ActiveRelation it "accepts arbitrary strings" do @relation.select("arbitrary").should == Selection.new(@relation, "arbitrary") end + + describe 'when given a blank predicate' do + it 'returns self' do + @relation.select.should == @relation + end + end end describe '#order' do it "manufactures an order relation" do @relation.order(@attribute1, @attribute2).should == Order.new(@relation, @attribute1, @attribute2) end + + describe 'when given a blank ordering' do + it 'returns self' do + @relation.order.should == @relation + end + end end describe '#take' do it "manufactures a take relation" do @relation.take(5).should == Take.new(@relation, 5) end + + describe 'when given a blank number of items' do + it 'returns self' do + @relation.take.should == @relation + end + end end describe '#skip' do it "manufactures a skip relation" do @relation.skip(4).should == Skip.new(@relation, 4) end - end - - describe '#call' do - it 'executes a select_all on the connection' do - mock(connection = Object.new).select_all(@relation.to_sql) - @relation.call(connection) + + describe 'when given a blank number of items' do + it 'returns self' do + @relation.skip.should == @relation + end end end - - + describe '#aggregate' do before do @expression1 = @attribute1.sum @@ -179,5 +207,12 @@ module ActiveRelation @relation.first.should == @relation.session.read(@relation).first end end + + describe '#call' do + it 'executes a select_all on the connection' do + mock(connection = Object.new).select_all(@relation.to_sql) + @relation.call(connection) + end + end end end \ No newline at end of file diff --git a/spec/active_relation/unit/relations/rename_spec.rb b/spec/active_relation/unit/relations/rename_spec.rb deleted file mode 100644 index 192c819848..0000000000 --- a/spec/active_relation/unit/relations/rename_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') - -module ActiveRelation - describe Rename do - before do - @relation = Table.new(:users) - end - - describe '#initialize' do - it "manufactures nested rename relations if multiple renames are provided" do - Rename.new(@relation, @relation[:id] => :humpty, @relation[:name] => :dumpty). \ - should == Rename.new(Rename.new(@relation, @relation[:name] => :dumpty), @relation[:id] => :humpty) - end - end - - describe '==' do - before do - @another_relation = Table.new(:photos) - end - - it "obtains if the relation, attribute, and rename are identical" do - Rename.new(@relation, @relation[:id] => :humpty).should == Rename.new(@relation, @relation[:id] => :humpty) - Rename.new(@relation, @relation[:id] => :humpty).should_not == Rename.new(@relation, @relation[:id] => :dumpty) - Rename.new(@relation, @relation[:id] => :humpty).should_not == Rename.new(@another_relation, @relation[:id] => :humpty) - end - end - - describe '#attributes' do - before do - @renamed_relation = Rename.new(@relation, @relation[:id] => :schmid) - end - - it "manufactures a list of attributes with the renamed attribute renameed" do - @renamed_relation.attributes.should include(@relation[:id].as(:schmid).bind(@renamed_relation)) - @renamed_relation.attributes.should_not include(@relation[:id].bind(@renamed_relation)) - @renamed_relation.attributes.should include(@relation[:name].bind(@renamed_relation)) - @renamed_relation.should have(@relation.attributes.size).attributes - end - end - - describe '#to_sql' do - it 'manufactures sql renaming the attribute' do - Rename.new(@relation, @relation[:id] => :schmid).to_sql.should be_like(" - SELECT `users`.`id` AS 'schmid', `users`.`name` - FROM `users` - ") - end - end - end -end \ No newline at end of file -- cgit v1.2.3