Permalink
Browse files

Add shared tests for skip

  • Loading branch information...
1 parent 07e133e commit c2f9f707fc56ca610fb1706886b3111dfe1d286f Carl Lerche committed Mar 13, 2010
Showing with 25 additions and 1 deletion.
  1. +2 −1 lib/arel/algebra/relations/operations/skip.rb
  2. +23 −0 spec/shared/relation_spec.rb
@@ -1,6 +1,7 @@
module Arel
class Skip < Compound
attributes :relation, :skipped
- deriving :initialize, :==
+ deriving :initialize, :==
+ requires :skipping
end
end
@@ -116,4 +116,27 @@
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

0 comments on commit c2f9f70

Please sign in to comment.