diff options
-rw-r--r-- | lib/arel/algebra/relations/operations/skip.rb | 3 | ||||
-rw-r--r-- | spec/shared/relation_spec.rb | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/arel/algebra/relations/operations/skip.rb b/lib/arel/algebra/relations/operations/skip.rb index 689e06e1c3..43db134ea0 100644 --- a/lib/arel/algebra/relations/operations/skip.rb +++ b/lib/arel/algebra/relations/operations/skip.rb @@ -1,6 +1,7 @@ module Arel class Skip < Compound attributes :relation, :skipped - deriving :initialize, :== + deriving :initialize, :== + requires :skipping end end diff --git a/spec/shared/relation_spec.rb b/spec/shared/relation_spec.rb index aa03ab6c0a..5f0ae4b46e 100644 --- a/spec/shared/relation_spec.rb +++ b/spec/shared/relation_spec.rb @@ -116,4 +116,27 @@ share_examples_for 'A Relation' do actual.should == expected[0,3] end end + + describe "#skip" do + it "returns a relation" do + @relation.skip(3).should be_a(Arel::Relation) + end + + it "skips X items from the collection" do + length = @expected.length + + @relation.skip(3).each do |resource| + @expected.delete_if { |r| r.tuple == resource.tuple } + end + + @expected.length.should == 3 + end + + it "works with ordering" do + expected = @expected.sort_by { |r| [r[@relation[:age]], r[@relation[:id]]] }.map { |r| r[@relation[:id]] } + actual = @relation.order(@relation[:age].asc, @relation[:id].asc).skip(3).map { |r| r[@relation[:id]] } + + actual.should == expected[3..-1] + end + end end
\ No newline at end of file |