From c2f9f707fc56ca610fb1706886b3111dfe1d286f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 12 Mar 2010 17:19:59 -0800 Subject: Add shared tests for skip --- spec/shared/relation_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'spec/shared') 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 -- cgit v1.2.3