ripplr 0.0.9.beta → 1.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,16 @@ module Ripplr
16
16
  self
17
17
  end
18
18
 
19
+ def limit(number_of_records)
20
+ @limit = number_of_records
21
+ self
22
+ end
23
+
24
+ def skip(number_of_rows)
25
+ @skip = number_of_rows
26
+ self
27
+ end
28
+
19
29
  def ascending
20
30
  @order_by_direction = " asc"
21
31
  self
@@ -26,6 +36,10 @@ module Ripplr
26
36
  self
27
37
  end
28
38
 
39
+ def [](index)
40
+ results[index]
41
+ end
42
+
29
43
  def each(&block)
30
44
  results.each do |result|
31
45
  yield result
@@ -59,13 +73,16 @@ module Ripplr
59
73
  end
60
74
 
61
75
  def options
62
- Maybe(ordering) { Hash.new }
76
+ {
77
+ :start => @skip,
78
+ :rows => @limit,
79
+ :sort => ordering
80
+ }.select{|k,v| v.present? }
63
81
  end
64
82
 
65
83
  def ordering
66
- return NullObject.new if @order_by_field.nil?
67
- sort = { :sort => "#{@order_by_field.to_s}" }
68
- sort[:sort] += @order_by_direction unless @order_by_direction.nil?
84
+ sort = @order_by_field.to_s
85
+ sort += @order_by_direction unless @order_by_direction.nil?
69
86
  sort
70
87
  end
71
88
 
@@ -1,3 +1,3 @@
1
1
  module Ripplr
2
- VERSION = "0.0.9.beta"
2
+ VERSION = "1.0.0.rc"
3
3
  end
@@ -37,6 +37,10 @@ describe Ripplr::Criteria do
37
37
  Then { iterated.should == ["Dan"] }
38
38
  end
39
39
 
40
+ context "by calling []" do
41
+ Then { criteria[0].should == "Dan" }
42
+ end
43
+
40
44
  context "by calling #each twice only calls execute once" do
41
45
  Given (:iterated) { Array.new }
42
46
  Given { criteria.each {|p| p } }
@@ -61,6 +65,20 @@ describe Ripplr::Criteria do
61
65
  end
62
66
  end
63
67
 
68
+ describe "limiting the number of records" do
69
+ Given (:indexer) { mock }
70
+ Given { indexer.should_receive(:search).with(Person, "first_name_text: \"Patrick\"", :rows => 20).and_return [1,2] }
71
+ When (:criteria) { Ripplr::Criteria.new(Person, indexer).where(:first_name => 'Patrick').limit(20) }
72
+ Then { criteria.execute.should == [1,2] }
73
+ end
74
+
75
+ describe "skipping some records (for paging)" do
76
+ Given (:indexer) { mock }
77
+ Given { indexer.should_receive(:search).with(Person, "first_name_text: \"Patrick\"", :start => 50).and_return [3,2] }
78
+ When (:criteria) { Ripplr::Criteria.new(Person, indexer).where(:first_name => 'Patrick').skip(50) }
79
+ Then { criteria.execute.should == [3,2] }
80
+ end
81
+
64
82
  describe "adding a sort to a query" do
65
83
  Given (:indexer) { mock }
66
84
  Given (:criteria) { Ripplr::Criteria.new(Person, indexer).where(:first_name => 'Patrick') }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripplr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9.beta
4
+ version: 1.0.0.rc
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-given