diff options
Diffstat (limited to 'spec')
6 files changed, 145 insertions, 86 deletions
diff --git a/spec/arel/engines/memory/unit/relations/array_spec.rb b/spec/arel/engines/memory/unit/relations/array_spec.rb index 22cddf7156..4fe24c77fa 100644 --- a/spec/arel/engines/memory/unit/relations/array_spec.rb +++ b/spec/arel/engines/memory/unit/relations/array_spec.rb @@ -27,92 +27,6 @@ module Arel Row.new(@relation, [3, 'goose']) ] end - - describe 'where' do - xit 'filters the relation with the provided predicate' do - @relation \ - .where(@relation[:id].lt(3)) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [1, 'duck']), - Row.new(relation, [2, 'duck']), - ] - end - end - - it 'filters the relation with the provided predicate' do - @relation \ - .where(@relation[:id].gt(1)) \ - .where(@relation[:id].lt(3)) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [2, 'duck']) - ] - end - end - end - - describe 'group' do - xit '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) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [3, 'goose']), - Row.new(relation, [2, 'duck']), - Row.new(relation, [1, 'duck']) - ] - end - end - end - - describe 'project' do - it 'projects' do - @relation \ - .project(@relation[:id]) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [1]), - Row.new(relation, [2]), - Row.new(relation, [3]) - ] - end - end - end - - describe 'skip' do - it 'slices' do - @relation \ - .skip(1) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [2, 'duck']), - Row.new(relation, [3, 'goose']), - ] - end - end - end - - describe 'take' do - it 'dices' do - @relation \ - .take(2) \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [1, 'duck']), - Row.new(relation, [2, 'duck']), - ] - end - end - end - - describe 'join' do - end end end end
\ No newline at end of file diff --git a/spec/arel/engines/memory/unit/relations/order_spec.rb b/spec/arel/engines/memory/unit/relations/order_spec.rb new file mode 100644 index 0000000000..3ecb31068b --- /dev/null +++ b/spec/arel/engines/memory/unit/relations/order_spec.rb @@ -0,0 +1,27 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Order do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) + end + + describe '#call' do + it 'sorts the relation with the provided ordering' do + @relation \ + .order(@relation[:id].desc) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [3, 'goose']), + Row.new(relation, [2, 'duck' ]), + Row.new(relation, [1, 'duck' ]) + ] + end + end + end + end +end
\ No newline at end of file diff --git a/spec/arel/engines/memory/unit/relations/project_spec.rb b/spec/arel/engines/memory/unit/relations/project_spec.rb new file mode 100644 index 0000000000..1d1224cfdc --- /dev/null +++ b/spec/arel/engines/memory/unit/relations/project_spec.rb @@ -0,0 +1,27 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Project do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) + end + + describe '#call' do + it 'retains only the attributes that are provided' do + @relation \ + .project(@relation[:id]) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1]), + Row.new(relation, [2]), + Row.new(relation, [3]) + ] + end + end + end + end +end
\ No newline at end of file diff --git a/spec/arel/engines/memory/unit/relations/skip_spec.rb b/spec/arel/engines/memory/unit/relations/skip_spec.rb new file mode 100644 index 0000000000..86db45ef61 --- /dev/null +++ b/spec/arel/engines/memory/unit/relations/skip_spec.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Skip do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) + end + + describe '#call' do + it 'removes the first n rows' do + @relation \ + .skip(1) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [2, 'duck']), + Row.new(relation, [3, 'goose']), + ] + end + end + end + end +end
\ No newline at end of file diff --git a/spec/arel/engines/memory/unit/relations/take_spec.rb b/spec/arel/engines/memory/unit/relations/take_spec.rb new file mode 100644 index 0000000000..8b774987e0 --- /dev/null +++ b/spec/arel/engines/memory/unit/relations/take_spec.rb @@ -0,0 +1,26 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Take do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) + end + + describe '#call' do + it 'removes the rows after the first n' do + @relation \ + .take(2) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1, 'duck']), + Row.new(relation, [2, 'duck']), + ] + end + end + end + end +end
\ No newline at end of file diff --git a/spec/arel/engines/memory/unit/relations/where_spec.rb b/spec/arel/engines/memory/unit/relations/where_spec.rb new file mode 100644 index 0000000000..d75ee5dcbe --- /dev/null +++ b/spec/arel/engines/memory/unit/relations/where_spec.rb @@ -0,0 +1,39 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') + +module Arel + describe Where do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [:id, :name]) + end + + describe '#call' do + it 'filters the relation with the provided predicate' do + @relation \ + .where(@relation[:id].lt(3)) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1, 'duck']), + Row.new(relation, [2, 'duck']), + ] + end + end + + describe 'when filtering a where relation' do + it 'further filters the already-filtered relation with the provided predicate' do + @relation \ + .where(@relation[:id].gt(1)) \ + .where(@relation[:id].lt(3)) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [2, 'duck']) + ] + end + end + end + end + end +end
\ No newline at end of file |