aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/unit/relations/range_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/active_relation/unit/relations/range_spec.rb')
-rw-r--r--spec/active_relation/unit/relations/range_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/active_relation/unit/relations/range_spec.rb b/spec/active_relation/unit/relations/range_spec.rb
new file mode 100644
index 0000000000..501a8d3641
--- /dev/null
+++ b/spec/active_relation/unit/relations/range_spec.rb
@@ -0,0 +1,35 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')
+
+module ActiveRelation
+ describe Range do
+ before do
+ @relation = Table.new(:users)
+ @range = 4..9
+ end
+
+ describe '#qualify' do
+ it "descends" do
+ Range.new(@relation, @range).qualify.should == Range.new(@relation, @range).descend(&:qualify)
+ end
+ end
+
+ describe '#descend' do
+ it "distributes over the relation" do
+ Range.new(@relation, @range).descend(&:qualify).should == Range.new(@relation.descend(&:qualify), @range)
+ 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("""
+ SELECT `users`.`id`, `users`.`name`
+ FROM `users`
+ LIMIT #{range_size}
+ OFFSET #{range_start}
+ """)
+ end
+ end
+ end
+end \ No newline at end of file