diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/arel/unit/relations/relation_spec.rb | 57 | ||||
-rw-r--r-- | spec/arel/unit/relations/update_spec.rb | 32 |
2 files changed, 35 insertions, 54 deletions
diff --git a/spec/arel/unit/relations/relation_spec.rb b/spec/arel/unit/relations/relation_spec.rb index 77a787b840..a3bfa67353 100644 --- a/spec/arel/unit/relations/relation_spec.rb +++ b/spec/arel/unit/relations/relation_spec.rb @@ -7,14 +7,14 @@ module Arel @attribute1 = @relation[:id] @attribute2 = @relation[:name] end - + describe '[]' do describe 'when given an', Attribute do it "return the attribute congruent to the provided attribute" do @relation[@attribute1].should == @attribute1 end end - + describe 'when given a', Symbol, String do it "returns the attribute with the same name, if it exists" do @relation[:id].should == @attribute1 @@ -23,13 +23,13 @@ module Arel end end end - + describe Relation::Operable do describe 'joins' do before do @predicate = @relation[:id].eq(@relation[:id]) end - + describe '#join' do describe 'when given a relation' do it "manufactures an inner join operation between those two relations" do @@ -37,13 +37,13 @@ module Arel should == Join.new("INNER JOIN", @relation, @relation, @predicate) end end - + describe "when given a string" do it "manufactures a join operation with the string passed through" do - @relation.join(arbitrary_string = "ASDF").should == Join.new(arbitrary_string, @relation) + @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 @@ -64,7 +64,7 @@ module Arel @relation.project(@attribute1, @attribute2). \ should == Project.new(@relation, @attribute1, @attribute2) end - + describe "when given blank attributes" do it "returns self" do @relation.project.should == @relation @@ -97,36 +97,36 @@ module Arel 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 - + describe 'when given a blank number of items' do it 'returns self' do @relation.skip.should == @relation @@ -138,24 +138,15 @@ module Arel it 'manufactures a group relation' do @relation.group(@attribute1, @attribute2).should == Group.new(@relation, @attribute1, @attribute2) end - + describe 'when given blank groupings' do it 'returns self' do @relation.group.should == @relation end end end - - describe Relation::Operable::Writable do - describe '#delete' do - it 'manufactures a deletion relation' do - Session.start do - mock(Session.new).delete(Deletion.new(@relation)) - @relation.delete.should == @relation - end - end - end + describe Relation::Operable::Writable do describe '#insert' do it 'manufactures an insertion relation' do Session.start do @@ -165,26 +156,16 @@ module Arel end end end - - describe '#update' do - it 'manufactures an update relation' do - Session.start do - assignments = {@relation[:name] => Value.new('bob', @relation)} - mock(Session.new).update(Update.new(@relation, assignments)) - @relation.update(assignments).should == @relation - end - end - end end end - + describe Relation::Enumerable do it "implements enumerable" do @relation.collect.should == @relation.session.read(@relation) @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).execute(@relation.to_sql) { [] } @@ -192,4 +173,4 @@ module Arel end end end -end
\ No newline at end of file +end diff --git a/spec/arel/unit/relations/update_spec.rb b/spec/arel/unit/relations/update_spec.rb index 08c6da7901..b67369251f 100644 --- a/spec/arel/unit/relations/update_spec.rb +++ b/spec/arel/unit/relations/update_spec.rb @@ -5,32 +5,32 @@ module Arel before do @relation = Table.new(:users) end - + describe '#to_sql' do it "manufactures sql updating attributes when given multiple attributes" do Update.new(@relation, @relation[:id] => 1, @relation[:name] => "nick").to_sql.should be_like(" UPDATE `users` - SET `users`.`id` = 1, `users`.`name` = 'nick' + SET `id` = 1, `name` = 'nick' ") end - + it "manufactures sql updating attributes when given a ranged relation" do Update.new(@relation.take(1), @relation[:name] => "nick").to_sql.should be_like(" UPDATE `users` - SET `users`.`name` = 'nick' + SET `name` = 'nick' LIMIT 1 ") end - + describe 'when given values whose types correspond to the types of the attributes' do before do @update = Update.new(@relation, @relation[:name] => "nick") end - + it 'manufactures sql updating attributes' do @update.to_sql.should be_like(" UPDATE `users` - SET `users`.`name` = 'nick' + SET `name` = 'nick' ") end end @@ -39,15 +39,15 @@ module Arel before do @update = Update.new(@relation, @relation[:id] => '1-asdf') end - + it 'manufactures sql updating attributes' do @update.to_sql.should be_like(" UPDATE `users` - SET `users`.`id` = 1 + SET `id` = 1 ") end end - + describe 'when the relation is a where' do before do @update = Update.new( @@ -55,27 +55,27 @@ module Arel @relation[:name] => "nick" ) end - + it 'manufactures sql updating a where relation' do @update.to_sql.should be_like(" UPDATE `users` - SET `users`.`name` = 'nick' + SET `name` = 'nick' WHERE `users`.`id` = 1 ") end end end - + describe '#call' do before do @update = Update.new(@relation, @relation[:name] => "nick") end - + it 'executes an update on the connection' do mock(connection = Object.new).update(@update.to_sql) @update.call(connection) end end - + end -end
\ No newline at end of file +end |