diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/arel/unit/relations/alias_spec.rb | 4 | ||||
-rw-r--r-- | spec/arel/unit/relations/array_spec.rb | 75 | ||||
-rw-r--r-- | spec/arel/unit/relations/order_spec.rb | 12 |
3 files changed, 72 insertions, 19 deletions
diff --git a/spec/arel/unit/relations/alias_spec.rb b/spec/arel/unit/relations/alias_spec.rb index 570f315892..63c15cfeff 100644 --- a/spec/arel/unit/relations/alias_spec.rb +++ b/spec/arel/unit/relations/alias_spec.rb @@ -30,7 +30,7 @@ module Arel FROM `users` WHERE `users`.`id` = 1 GROUP BY `users`.`id` - ORDER BY `users`.`id` + ORDER BY `users`.`id` ASC }) end @@ -40,7 +40,7 @@ module Arel FROM "users" WHERE "users"."id" = 1 GROUP BY "users"."id" - ORDER BY "users"."id" + ORDER BY "users"."id" ASC }) end end diff --git a/spec/arel/unit/relations/array_spec.rb b/spec/arel/unit/relations/array_spec.rb index c90843cd7d..d1c65c60a9 100644 --- a/spec/arel/unit/relations/array_spec.rb +++ b/spec/arel/unit/relations/array_spec.rb @@ -3,13 +3,18 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') module Arel describe Array do before do - @relation = Array.new([[1], [2], [3]], [:id]) + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) end describe '#attributes' do it 'manufactures attributes corresponding to the names given on construction' do @relation.attributes.should == [ - Attribute.new(@relation, :id) + Attribute.new(@relation, :id), + Attribute.new(@relation, :name) ] end end @@ -17,17 +22,65 @@ module Arel describe '#call' do it "manufactures an array of hashes of attributes to values" do @relation.call.should == [ - { @relation[:id] => 1 }, - { @relation[:id] => 2 }, - { @relation[:id] => 3 } + { @relation[:id] => 1, @relation[:name] => 'duck' }, + { @relation[:id] => 2, @relation[:name] => 'duck' }, + { @relation[:id] => 3, @relation[:name] => 'goose' } ] end - - it '' do - @relation.where(@relation[:id].lt(3)).call.should == [ - { @relation[:id] => 1 }, - { @relation[:id] => 2 } - ] + + describe 'where' do + it 'filters the relation with the provided predicate' do + @relation.where(@relation[:id].lt(3)).call.should == [ + { @relation[:id] => 1, @relation[:name] => 'duck' }, + { @relation[:id] => 2, @relation[:name] => 'duck' } + ] + end + end + + describe 'group' do + it 'sorts the relation with the provided ordering' do + end + end + + describe 'order' do + it 'sorts the relation with the provided ordering' do + @relation.order(@relation[:id].desc).call.should == [ + { @relation[:id] => 3, @relation[:name] => 'goose' }, + { @relation[:id] => 2, @relation[:name] => 'duck' }, + { @relation[:id] => 1, @relation[:name] => 'duck' } + ] + end + end + + describe 'project' do + it 'projects' do + @relation.project(@relation[:id]).call.should == [ + { @relation[:id] => 1 }, + { @relation[:id] => 2 }, + { @relation[:id] => 3 } + ] + end + end + + describe 'skip' do + it 'slices' do + @relation.skip(1).call.should == [ + { @relation[:id] => 2, @relation[:name] => 'duck' }, + { @relation[:id] => 3, @relation[:name] => 'goose' } + ] + end + end + + describe 'take' do + it 'dices' do + @relation.take(2).call.should == [ + { @relation[:id] => 1, @relation[:name] => 'duck' }, + { @relation[:id] => 2, @relation[:name] => 'duck' } + ] + end + end + + describe 'join' do end end end diff --git a/spec/arel/unit/relations/order_spec.rb b/spec/arel/unit/relations/order_spec.rb index 31014ddd39..cb0f1de84c 100644 --- a/spec/arel/unit/relations/order_spec.rb +++ b/spec/arel/unit/relations/order_spec.rb @@ -16,7 +16,7 @@ module Arel sql.should be_like(%Q{ SELECT `users`.`id`, `users`.`name` FROM `users` - ORDER BY `users`.`id` + ORDER BY `users`.`id` ASC }) end @@ -24,7 +24,7 @@ module Arel sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" - ORDER BY "users"."id" + ORDER BY "users"."id" ASC }) end end @@ -42,7 +42,7 @@ module Arel sql.should be_like(%Q{ SELECT `users`.`id`, `users`.`name` FROM `users` - ORDER BY `users`.`id`, `users`.`name` + ORDER BY `users`.`id` ASC, `users`.`name` ASC }) end @@ -50,7 +50,7 @@ module Arel sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" - ORDER BY "users"."id", "users"."name" + ORDER BY "users"."id" ASC, "users"."name" ASC }) end end @@ -95,7 +95,7 @@ module Arel sql.should be_like(%Q{ SELECT `users`.`id`, `users`.`name` FROM `users` - ORDER BY `users`.`name`, `users`.`id` + ORDER BY `users`.`name` ASC, `users`.`id` ASC }) end @@ -103,7 +103,7 @@ module Arel sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" - ORDER BY "users"."name", "users"."id" + ORDER BY "users"."name" ASC, "users"."id" ASC }) end end |