waistband 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,17 @@ module Waistband
97
97
  }
98
98
  end
99
99
 
100
+ def add_random_sort
101
+ @random_sort = {
102
+ _script: {
103
+ script: "Math.random()",
104
+ type: :number,
105
+ params: {},
106
+ order: :asc
107
+ }
108
+ }
109
+ end
110
+
100
111
  private
101
112
 
102
113
  def url
@@ -127,6 +138,8 @@ module Waistband
127
138
  end
128
139
 
129
140
  def sort_to_hash
141
+ return @random_sort if @random_sort
142
+
130
143
  sort = []
131
144
 
132
145
  @sorts.each do |s|
@@ -1,3 +1,3 @@
1
1
  module Waistband
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -84,6 +84,43 @@ describe Waistband::Query do
84
84
 
85
85
  end
86
86
 
87
+ describe '#add_random_sort' do
88
+
89
+ it "sets the correct instance variables" do
90
+ query.add_random_sort
91
+
92
+ query.instance_variable_get('@random_sort').should eql({
93
+ _script: {
94
+ script: "Math.random()",
95
+ type: :number,
96
+ params: {},
97
+ order: :asc
98
+ }
99
+ })
100
+
101
+ query.send(:sort_to_hash).should eql({
102
+ _script: {
103
+ script: "Math.random()",
104
+ type: :number,
105
+ params: {},
106
+ order: :asc
107
+ }
108
+ })
109
+ end
110
+
111
+ it "sorts restuls randomly" do
112
+ add_result!
113
+
114
+ query = index.query('shopping ikea')
115
+
116
+ query.add_field('name')
117
+ query.add_random_sort
118
+
119
+ query.results.size.should eql 2
120
+ end
121
+
122
+ end
123
+
87
124
  describe '#add_range' do
88
125
 
89
126
  it "adds a range" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waistband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
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: 2013-09-06 00:00:00.000000000 Z
12
+ date: 2013-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport