aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-11 18:24:18 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-04-11 18:24:18 -0700
commitae0fe8f6c8c41b5abf8ced6a99b19dacdf8f57eb (patch)
tree3f3e9a0bc779b489033a4def6dcf31603953fec6 /spec
parent3967bd524da7b3c0b985c57670ceb7f5d48a0f1b (diff)
downloadrails-ae0fe8f6c8c41b5abf8ced6a99b19dacdf8f57eb.tar.gz
rails-ae0fe8f6c8c41b5abf8ced6a99b19dacdf8f57eb.tar.bz2
rails-ae0fe8f6c8c41b5abf8ced6a99b19dacdf8f57eb.zip
redesigned the way limit and offset work
- was range now have special 'take' and 'skip' operations. (the terminology comes from linq)
Diffstat (limited to 'spec')
-rw-r--r--spec/active_relation/unit/relations/relation_spec.rb6
-rw-r--r--spec/active_relation/unit/relations/skip_spec.rb (renamed from spec/active_relation/unit/relations/range_spec.rb)15
-rw-r--r--spec/active_relation/unit/relations/take_spec.rb32
3 files changed, 38 insertions, 15 deletions
diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb
index 70bf87271a..d10ae490de 100644
--- a/spec/active_relation/unit/relations/relation_spec.rb
+++ b/spec/active_relation/unit/relations/relation_spec.rb
@@ -9,12 +9,6 @@ module ActiveRelation
end
describe '[]' do
- describe 'when given a', Range do
- it "manufactures a range relation when given a range" do
- @relation[1..2].should == Range.new(@relation, 1..2)
- end
- end
-
describe 'when given an', Attribute do
it "return the attribute congruent to the provided attribute" do
@relation[@attribute1].should == @attribute1
diff --git a/spec/active_relation/unit/relations/range_spec.rb b/spec/active_relation/unit/relations/skip_spec.rb
index a0207c7342..77f2b8db27 100644
--- a/spec/active_relation/unit/relations/range_spec.rb
+++ b/spec/active_relation/unit/relations/skip_spec.rb
@@ -1,33 +1,30 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
module ActiveRelation
- describe Range do
+ describe Skip do
before do
@relation = Table.new(:users)
- @range = 4..9
+ @skip = 4
end
describe '#qualify' do
it "descends" do
- Range.new(@relation, @range).qualify.should == Range.new(@relation, @range).descend(&:qualify)
+ Skip.new(@relation, @skip).qualify.should == Skip.new(@relation, @skip).descend(&:qualify)
end
end
describe '#descend' do
it "distributes a block over the relation" do
- Range.new(@relation, @range).descend(&:qualify).should == Range.new(@relation.descend(&:qualify), @range)
+ Skip.new(@relation, @skip).descend(&:qualify).should == Skip.new(@relation.descend(&:qualify), @skip)
end
end
describe '#to_sql' do
it "manufactures sql with limit and offset" do
- range_size = @range.last - @range.first + 1
- range_start = @range.first
- Range.new(@relation, @range).to_s.should be_like("
+ Skip.new(@relation, @skip).to_s.should be_like("
SELECT `users`.`id`, `users`.`name`
FROM `users`
- LIMIT #{range_size}
- OFFSET #{range_start}
+ OFFSET #{@skip}
")
end
end
diff --git a/spec/active_relation/unit/relations/take_spec.rb b/spec/active_relation/unit/relations/take_spec.rb
new file mode 100644
index 0000000000..6523ff85f9
--- /dev/null
+++ b/spec/active_relation/unit/relations/take_spec.rb
@@ -0,0 +1,32 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
+
+module ActiveRelation
+ describe Take do
+ before do
+ @relation = Table.new(:users)
+ @take = 4
+ end
+
+ describe '#qualify' do
+ it "descends" do
+ Take.new(@relation, @take).qualify.should == Take.new(@relation, @take).descend(&:qualify)
+ end
+ end
+
+ describe '#descend' do
+ it "distributes a block over the relation" do
+ Take.new(@relation, @take).descend(&:qualify).should == Take.new(@relation.descend(&:qualify), @take)
+ end
+ end
+
+ describe '#to_sql' do
+ it "manufactures sql with limit and offset" do
+ Take.new(@relation, @take).to_s.should be_like("
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ LIMIT #{@take}
+ ")
+ end
+ end
+ end
+end \ No newline at end of file