aboutsummaryrefslogtreecommitdiffstats
path: root/spec/shared
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-12 17:02:43 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-12 17:02:43 -0800
commit07e133e97ed422436810b7398dcbd780cabea2c3 (patch)
tree0942678b7745894827ae13c5f4b5e35e79001fb3 /spec/shared
parente9c71a864bd33b3109e802efc7d03255037a899f (diff)
downloadrails-07e133e97ed422436810b7398dcbd780cabea2c3.tar.gz
rails-07e133e97ed422436810b7398dcbd780cabea2c3.tar.bz2
rails-07e133e97ed422436810b7398dcbd780cabea2c3.zip
Add full stack tests for #take
Diffstat (limited to 'spec/shared')
-rw-r--r--spec/shared/relation_spec.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/shared/relation_spec.rb b/spec/shared/relation_spec.rb
index c492ca847e..aa03ab6c0a 100644
--- a/spec/shared/relation_spec.rb
+++ b/spec/shared/relation_spec.rb
@@ -14,6 +14,10 @@ share_examples_for 'A Relation' do
raise "@expected needs to have at least 6 items" unless @expected.length >= 6
end
+ before :each do
+ @expected = @expected.dup
+ end
+
describe "#each" do
it "iterates over the rows in any order" do
@relation.should have_rows(@expected)
@@ -89,4 +93,27 @@ share_examples_for 'A Relation' do
it "works"
end
end
+
+ describe "#take" do
+ it "returns a relation" do
+ @relation.take(3).should be_a(Arel::Relation)
+ end
+
+ it "returns X items from the collection" do
+ length = @expected.length
+
+ @relation.take(3).each do |resource|
+ @expected.delete_if { |r| r.tuple == resource.tuple }
+ end
+
+ @expected.length.should == length - 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).take(3).map { |r| r[@relation[:id]] }
+
+ actual.should == expected[0,3]
+ end
+ end
end \ No newline at end of file