sunspot 2.2.7 → 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -8
  6. data/gemfiles/.gitkeep +0 -0
  7. data/lib/sunspot/dsl/scope.rb +6 -1
  8. data/lib/sunspot/field.rb +11 -0
  9. data/lib/sunspot/field_factory.rb +6 -2
  10. data/lib/sunspot/query/bbox.rb +5 -1
  11. data/lib/sunspot/query/restriction.rb +11 -0
  12. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  13. data/lib/sunspot/search/standard_search.rb +2 -3
  14. data/lib/sunspot/version.rb +1 -1
  15. data/spec/api/adapters_spec.rb +19 -19
  16. data/spec/api/batcher_spec.rb +15 -15
  17. data/spec/api/binding_spec.rb +3 -3
  18. data/spec/api/class_set_spec.rb +3 -3
  19. data/spec/api/hit_enumerable_spec.rb +32 -9
  20. data/spec/api/indexer/attributes_spec.rb +31 -31
  21. data/spec/api/indexer/batch_spec.rb +8 -7
  22. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  23. data/spec/api/indexer/fixed_fields_spec.rb +12 -12
  24. data/spec/api/indexer/fulltext_spec.rb +8 -8
  25. data/spec/api/indexer/removal_spec.rb +14 -14
  26. data/spec/api/indexer_spec.rb +2 -2
  27. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  28. data/spec/api/query/connectives_examples.rb +26 -14
  29. data/spec/api/query/dsl_spec.rb +17 -9
  30. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  31. data/spec/api/query/faceting_examples.rb +62 -62
  32. data/spec/api/query/fulltext_examples.rb +56 -55
  33. data/spec/api/query/function_spec.rb +26 -26
  34. data/spec/api/query/geo_examples.rb +6 -6
  35. data/spec/api/query/group_spec.rb +6 -6
  36. data/spec/api/query/highlighting_examples.rb +26 -26
  37. data/spec/api/query/join_spec.rb +2 -2
  38. data/spec/api/query/more_like_this_spec.rb +29 -29
  39. data/spec/api/query/ordering_pagination_examples.rb +25 -25
  40. data/spec/api/query/scope_examples.rb +39 -39
  41. data/spec/api/query/spatial_examples.rb +3 -3
  42. data/spec/api/query/spellcheck_examples.rb +3 -3
  43. data/spec/api/query/standard_spec.rb +1 -1
  44. data/spec/api/query/stats_examples.rb +8 -8
  45. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  46. data/spec/api/query/types_spec.rb +4 -4
  47. data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
  48. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  49. data/spec/api/search/faceting_spec.rb +55 -52
  50. data/spec/api/search/highlighting_spec.rb +7 -7
  51. data/spec/api/search/hits_spec.rb +29 -29
  52. data/spec/api/search/paginated_collection_spec.rb +18 -18
  53. data/spec/api/search/results_spec.rb +13 -13
  54. data/spec/api/search/search_spec.rb +3 -3
  55. data/spec/api/search/stats_spec.rb +10 -10
  56. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
  57. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
  58. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  59. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
  60. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
  61. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
  62. data/spec/api/session_proxy/spec_helper.rb +1 -1
  63. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
  64. data/spec/api/session_spec.rb +42 -42
  65. data/spec/api/sunspot_spec.rb +4 -4
  66. data/spec/integration/atomic_updates_spec.rb +25 -11
  67. data/spec/integration/dynamic_fields_spec.rb +10 -10
  68. data/spec/integration/faceting_spec.rb +39 -39
  69. data/spec/integration/field_grouping_spec.rb +16 -16
  70. data/spec/integration/field_lists_spec.rb +41 -0
  71. data/spec/integration/geospatial_spec.rb +19 -8
  72. data/spec/integration/highlighting_spec.rb +5 -5
  73. data/spec/integration/indexing_spec.rb +5 -5
  74. data/spec/integration/keyword_search_spec.rb +47 -45
  75. data/spec/integration/local_search_spec.rb +4 -4
  76. data/spec/integration/more_like_this_spec.rb +7 -7
  77. data/spec/integration/scoped_search_spec.rb +107 -107
  78. data/spec/integration/spellcheck_spec.rb +52 -7
  79. data/spec/integration/stats_spec.rb +10 -10
  80. data/spec/integration/stored_fields_spec.rb +1 -1
  81. data/spec/integration/test_pagination.rb +4 -4
  82. data/spec/integration/unicode_spec.rb +1 -1
  83. data/spec/mocks/post.rb +5 -1
  84. data/spec/spec_helper.rb +11 -6
  85. data/sunspot.gemspec +3 -1
  86. metadata +40 -7
@@ -14,30 +14,30 @@ describe 'more_like_this' do
14
14
  end
15
15
 
16
16
  it 'should return results for all MLT fields' do
17
- Sunspot.more_like_this(@posts.first).results.to_set.should == @posts[1..3].to_set
17
+ expect(Sunspot.more_like_this(@posts.first).results.to_set).to eq(@posts[1..3].to_set)
18
18
  end
19
19
 
20
20
  it 'should return results for specified text field' do
21
- Sunspot.more_like_this(@posts.first) do
21
+ expect(Sunspot.more_like_this(@posts.first) do
22
22
  fields :body
23
- end.results.to_set.should == @posts[2..3].to_set
23
+ end.results.to_set).to eq(@posts[2..3].to_set)
24
24
  end
25
25
 
26
26
  it 'should return empty result set if no results' do
27
- Sunspot.more_like_this(@posts.last) do
27
+ expect(Sunspot.more_like_this(@posts.last) do
28
28
  with(:title, 'bogus')
29
- end.results.should == []
29
+ end.results).to eq([])
30
30
  end
31
31
 
32
32
  describe 'when non-indexed object searched' do
33
33
  before(:each) { @mlt = Sunspot.more_like_this(Post.new) }
34
34
 
35
35
  it 'should return empty result set' do
36
- @mlt.results.should == []
36
+ expect(@mlt.results).to eq([])
37
37
  end
38
38
 
39
39
  it 'shoult return a total of 0' do
40
- @mlt.total.should == 0
40
+ expect(@mlt.total).to eq(0)
41
41
  end
42
42
  end
43
43
  end
@@ -22,95 +22,95 @@ describe 'scoped_search' do
22
22
  end
23
23
 
24
24
  it 'should filter by exact match' do
25
- Sunspot.search(clazz) { with(field, values[2]) }.results.should == [@objects[2]]
25
+ expect(Sunspot.search(clazz) { with(field, values[2]) }.results).to eq([@objects[2]])
26
26
  end
27
27
 
28
28
  it 'should reject by inexact match' do
29
29
  results = Sunspot.search(clazz) { without(field, values[2]) }.results
30
- [0, 1, 3, 4].each { |i| results.should include(@objects[i]) }
31
- results.should_not include(@objects[2])
30
+ [0, 1, 3, 4].each { |i| expect(results).to include(@objects[i]) }
31
+ expect(results).not_to include(@objects[2])
32
32
  end
33
33
 
34
34
  it 'should filter by less than' do
35
35
  results = Sunspot.search(clazz) { with(field).less_than values[2] }.results
36
- (0..1).each { |i| results.should include(@objects[i]) }
37
- (2..4).each { |i| results.should_not include(@objects[i]) }
36
+ (0..1).each { |i| expect(results).to include(@objects[i]) }
37
+ (2..4).each { |i| expect(results).not_to include(@objects[i]) }
38
38
  end
39
39
 
40
40
  it 'should reject by less than' do
41
41
  results = Sunspot.search(clazz) { without(field).less_than values[2] }.results
42
- (0..1).each { |i| results.should_not include(@objects[i]) }
43
- (2..4).each { |i| results.should include(@objects[i]) }
42
+ (0..1).each { |i| expect(results).not_to include(@objects[i]) }
43
+ (2..4).each { |i| expect(results).to include(@objects[i]) }
44
44
  end
45
45
 
46
46
  it 'should filter by less than or equal to' do
47
47
  results = Sunspot.search(clazz) { with(field).less_than_or_equal_to values[2] }.results
48
- (0..2).each { |i| results.should include(@objects[i]) }
49
- (3..4).each { |i| results.should_not include(@objects[i]) }
48
+ (0..2).each { |i| expect(results).to include(@objects[i]) }
49
+ (3..4).each { |i| expect(results).not_to include(@objects[i]) }
50
50
  end
51
51
 
52
52
  it 'should reject by less than or equal to' do
53
53
  results = Sunspot.search(clazz) { without(field).less_than_or_equal_to values[2] }.results
54
- (0..2).each { |i| results.should_not include(@objects[i]) }
55
- (3..4).each { |i| results.should include(@objects[i]) }
54
+ (0..2).each { |i| expect(results).not_to include(@objects[i]) }
55
+ (3..4).each { |i| expect(results).to include(@objects[i]) }
56
56
  end
57
57
 
58
58
  it 'should filter by greater than' do
59
59
  results = Sunspot.search(clazz) { with(field).greater_than values[2] }.results
60
- (3..4).each { |i| results.should include(@objects[i]) }
61
- (0..2).each { |i| results.should_not include(@objects[i]) }
60
+ (3..4).each { |i| expect(results).to include(@objects[i]) }
61
+ (0..2).each { |i| expect(results).not_to include(@objects[i]) }
62
62
  end
63
63
 
64
64
  it 'should reject by greater than' do
65
65
  results = Sunspot.search(clazz) { without(field).greater_than values[2] }.results
66
- (3..4).each { |i| results.should_not include(@objects[i]) }
67
- (0..2).each { |i| results.should include(@objects[i]) }
66
+ (3..4).each { |i| expect(results).not_to include(@objects[i]) }
67
+ (0..2).each { |i| expect(results).to include(@objects[i]) }
68
68
  end
69
69
 
70
70
  it 'should filter by greater than or equal to' do
71
71
  results = Sunspot.search(clazz) { with(field).greater_than_or_equal_to values[2] }.results
72
- (2..4).each { |i| results.should include(@objects[i]) }
73
- (0..1).each { |i| results.should_not include(@objects[i]) }
72
+ (2..4).each { |i| expect(results).to include(@objects[i]) }
73
+ (0..1).each { |i| expect(results).not_to include(@objects[i]) }
74
74
  end
75
75
 
76
76
  it 'should reject by greater than' do
77
77
  results = Sunspot.search(clazz) { without(field).greater_than_or_equal_to values[2] }.results
78
- (2..4).each { |i| results.should_not include(@objects[i]) }
79
- (0..1).each { |i| results.should include(@objects[i]) }
78
+ (2..4).each { |i| expect(results).not_to include(@objects[i]) }
79
+ (0..1).each { |i| expect(results).to include(@objects[i]) }
80
80
  end
81
81
 
82
82
  it 'should filter by between' do
83
83
  results = Sunspot.search(clazz) { with(field).between(values[1]..values[3]) }.results
84
- (1..3).each { |i| results.should include(@objects[i]) }
85
- [0, 4].each { |i| results.should_not include(@objects[i]) }
84
+ (1..3).each { |i| expect(results).to include(@objects[i]) }
85
+ [0, 4].each { |i| expect(results).not_to include(@objects[i]) }
86
86
  end
87
87
 
88
88
  it 'should reject by between' do
89
89
  results = Sunspot.search(clazz) { without(field).between(values[1]..values[3]) }.results
90
- (1..3).each { |i| results.should_not include(@objects[i]) }
91
- [0, 4].each { |i| results.should include(@objects[i]) }
90
+ (1..3).each { |i| expect(results).not_to include(@objects[i]) }
91
+ [0, 4].each { |i| expect(results).to include(@objects[i]) }
92
92
  end
93
93
 
94
94
  it 'should filter by any of' do
95
95
  results = Sunspot.search(clazz) { with(field).any_of(values.values_at(1, 3)) }.results
96
- [1, 3].each { |i| results.should include(@objects[i]) }
97
- [0, 2, 4].each { |i| results.should_not include(@objects[i]) }
96
+ [1, 3].each { |i| expect(results).to include(@objects[i]) }
97
+ [0, 2, 4].each { |i| expect(results).not_to include(@objects[i]) }
98
98
  end
99
99
 
100
100
  it 'should reject by any of' do
101
101
  results = Sunspot.search(clazz) { without(field).any_of(values.values_at(1, 3)) }.results
102
- [1, 3].each { |i| results.should_not include(@objects[i]) }
103
- [0, 2, 4].each { |i| results.should include(@objects[i]) }
102
+ [1, 3].each { |i| expect(results).not_to include(@objects[i]) }
103
+ [0, 2, 4].each { |i| expect(results).to include(@objects[i]) }
104
104
  end
105
105
 
106
106
  it 'should order by field ascending' do
107
107
  results = Sunspot.search(clazz) { order_by field, :asc }.results
108
- results.should == @objects
108
+ expect(results).to eq(@objects)
109
109
  end
110
110
 
111
111
  it 'should order by field descending' do
112
112
  results = Sunspot.search(clazz) { order_by field, :desc }.results
113
- results.should == @objects.reverse
113
+ expect(results).to eq(@objects.reverse)
114
114
  end
115
115
  end
116
116
  end
@@ -126,10 +126,7 @@ describe 'scoped_search' do
126
126
  test_field_type 'Trie Float', :average_rating, :average_rating, Photo, -2.5, 0.0, 3.2, 3.5, 16.0
127
127
  test_field_type 'Trie Time', :created_at, :created_at, Photo, *(['1970-01-01 00:00:00 UTC', '1983-07-08 04:00:00 UTC', '1983-07-08 02:00:00 -0500',
128
128
  '2005-11-05 10:00:00 UTC', Time.now.to_s].map { |t| Time.parse(t) })
129
-
130
129
  describe 'Date range field type' do
131
- let(:january) { Date.new(2015,1,1)..Date.new(2015,1,31) }
132
- let(:february) { Date.new(2015,2,1)..Date.new(2015,2,28) }
133
130
  let(:date_ranges) do
134
131
  {
135
132
  'December and January' => Date.new(2014,12,25)..Date.new(2015,1,10),
@@ -143,38 +140,40 @@ describe 'scoped_search' do
143
140
  end
144
141
 
145
142
  before :all do
143
+ january = Date.new(2015,1,1)..Date.new(2015,1,31)
144
+ february = Date.new(2015,2,1)..Date.new(2015,2,28)
146
145
  Sunspot.remove_all
147
146
  @posts = [Post.new(featured_for: january), Post.new(featured_for: february), Post.new]
148
147
  Sunspot.index!(@posts)
149
148
  end
150
149
 
151
150
  it 'should filter by Contains' do
152
- featured_for_posts(:containing, Date.new(2015,1,15) ).should == [@posts[0]]
153
- featured_for_posts(:containing, 'December and January').should be_empty
154
- featured_for_posts(:containing, 'January only').should == [@posts[0]]
155
- featured_for_posts(:containing, 'January only', negated = true).should == @posts[1..-1]
151
+ expect(featured_for_posts(:containing, Date.new(2015,1,15) )).to eq([@posts[0]])
152
+ expect(featured_for_posts(:containing, 'December and January')).to be_empty
153
+ expect(featured_for_posts(:containing, 'January only')).to eq([@posts[0]])
154
+ expect(featured_for_posts(:containing, 'January only', negated = true)).to eq(@posts[1..-1])
156
155
  end
157
156
 
158
157
  it 'should filter by Intersects' do
159
- featured_for_posts(:intersecting, Date.new(2015,1,15) ).should == [@posts[0]]
160
- featured_for_posts(:intersecting, 'January only').should == [@posts[0]]
161
- featured_for_posts(:intersecting, 'January and February').should == @posts[0..1]
162
- featured_for_posts(:intersecting, 'January and February', negated = true).should == [@posts[2]]
163
- featured_for_posts(:intersecting, 'February only').should == [@posts[1]]
164
- featured_for_posts(:intersecting, 'February only', negated = true).should == [@posts[0], @posts[2]]
158
+ expect(featured_for_posts(:intersecting, Date.new(2015,1,15) )).to eq([@posts[0]])
159
+ expect(featured_for_posts(:intersecting, 'January only')).to eq([@posts[0]])
160
+ expect(featured_for_posts(:intersecting, 'January and February')).to eq(@posts[0..1])
161
+ expect(featured_for_posts(:intersecting, 'January and February', negated = true)).to eq([@posts[2]])
162
+ expect(featured_for_posts(:intersecting, 'February only')).to eq([@posts[1]])
163
+ expect(featured_for_posts(:intersecting, 'February only', negated = true)).to eq([@posts[0], @posts[2]])
165
164
  end
166
165
 
167
166
  it 'should filter by Within' do
168
- featured_for_posts(:within, Date.new(2015,1,15) ).should be_empty
167
+ expect(featured_for_posts(:within, Date.new(2015,1,15) )).to be_empty
169
168
  (date_ranges.keys - date_ranges.keys.grep(/ to /)).each do |key|
170
- featured_for_posts(:within, key).should be_empty
169
+ expect(featured_for_posts(:within, key)).to be_empty
171
170
  end
172
- featured_for_posts(:within, 'December to February').should == [@posts[0]]
173
- featured_for_posts(:within, 'December to February', negated = true).should == @posts[1..-1]
174
- featured_for_posts(:within, 'January to March').should == [@posts[1]]
175
- featured_for_posts(:within, 'January to March', negated = true).should == [@posts[0], @posts[2]]
176
- featured_for_posts(:within, 'December to March').should == @posts[0..1]
177
- featured_for_posts(:within, 'December to March', negated = true).should == [@posts[2]]
171
+ expect(featured_for_posts(:within, 'December to February')).to eq([@posts[0]])
172
+ expect(featured_for_posts(:within, 'December to February', negated = true)).to eq(@posts[1..-1])
173
+ expect(featured_for_posts(:within, 'January to March')).to eq([@posts[1]])
174
+ expect(featured_for_posts(:within, 'January to March', negated = true)).to eq([@posts[0], @posts[2]])
175
+ expect(featured_for_posts(:within, 'December to March')).to eq(@posts[0..1])
176
+ expect(featured_for_posts(:within, 'December to March', negated = true)).to eq([@posts[2]])
178
177
  end
179
178
  end
180
179
 
@@ -186,11 +185,11 @@ describe 'scoped_search' do
186
185
  end
187
186
 
188
187
  it 'should filter by exact match for true' do
189
- Sunspot.search(Post) { with(:featured, true) }.results.should == [@posts[0]]
188
+ expect(Sunspot.search(Post) { with(:featured, true) }.results).to eq([@posts[0]])
190
189
  end
191
190
 
192
191
  it 'should filter for exact match for false' do
193
- Sunspot.search(Post) { with(:featured, false) }.results.should == [@posts[1]]
192
+ expect(Sunspot.search(Post) { with(:featured, false) }.results).to eq([@posts[1]])
194
193
  end
195
194
  end
196
195
 
@@ -198,7 +197,7 @@ describe 'scoped_search' do
198
197
  it "allows for using symbols in defining static field names" do
199
198
  Sunspot.remove_all
200
199
  Sunspot.index!(legacy = Post.new(:title => "foo"))
201
- Sunspot.search(Post) { with(:legacy, "legacy foo") }.results.should == [legacy]
200
+ expect(Sunspot.search(Post) { with(:legacy, "legacy foo") }.results).to eq([legacy])
202
201
  end
203
202
  end
204
203
 
@@ -206,7 +205,7 @@ describe 'scoped_search' do
206
205
  %w(AND OR NOT TO).each do |word|
207
206
  it "should successfully search for #{word.inspect}" do
208
207
  Sunspot.index!(post = Post.new(:title => word))
209
- Sunspot.search(Post) { with(:title, word) }.results.should == [post]
208
+ expect(Sunspot.search(Post) { with(:title, word) }.results).to eq([post])
210
209
  end
211
210
  end
212
211
  end
@@ -219,11 +218,11 @@ describe 'scoped_search' do
219
218
  end
220
219
 
221
220
  it 'should filter results without value for field' do
222
- Sunspot.search(Post) { with(:title, nil) }.results.should == [@posts[1]]
221
+ expect(Sunspot.search(Post) { with(:title, nil) }.results).to eq([@posts[1]])
223
222
  end
224
223
 
225
224
  it 'should exclude results without value for field' do
226
- Sunspot.search(Post) { without(:title, nil) }.results.should == [@posts[0]]
225
+ expect(Sunspot.search(Post) { without(:title, nil) }.results).to eq([@posts[0]])
227
226
  end
228
227
  end
229
228
 
@@ -237,12 +236,13 @@ describe 'scoped_search' do
237
236
  end
238
237
 
239
238
  it 'should return results whose prefix matches' do
240
- Sunspot.search(Post) { with(:title).starting_with('test') }.results.should == @posts[0..1]
239
+ expect(Sunspot.search(Post) { with(:title).starting_with('test') }.results).to eq(@posts[0..1])
241
240
  end
242
241
  end
243
242
 
244
243
  describe 'inclusion by identity' do
245
244
  before do
245
+ Sunspot.remove_all
246
246
  @posts = (1..5).map do |i|
247
247
  post = Post.new
248
248
  Sunspot.index(post)
@@ -253,26 +253,27 @@ describe 'scoped_search' do
253
253
 
254
254
  it 'should only return included object' do
255
255
  included_post = @posts.shift
256
- Sunspot.search(Post) { with(included_post) }.results.should include(included_post)
256
+ expect(Sunspot.search(Post) { with(included_post) }.results).to include(included_post)
257
257
  end
258
258
 
259
259
  it 'should not return objects not included' do
260
260
  included_post = @posts.shift
261
261
  for excluded_post in @posts
262
- Sunspot.search(Post) { with(included_post) }.results.should_not include(excluded_post)
262
+ expect(Sunspot.search(Post) { with(included_post) }.results).not_to include(excluded_post)
263
263
  end
264
264
  end
265
265
 
266
266
  it 'should return included objects' do
267
267
  included_posts = [@posts.shift, @posts.shift]
268
268
  for included_post in included_posts
269
- Sunspot.search(Post) { with(included_posts) }.results.should include(included_post)
269
+ expect(Sunspot.search(Post) { with(included_posts) }.results).to include(included_post)
270
270
  end
271
271
  end
272
272
  end
273
273
 
274
274
  describe 'exclusion by identity' do
275
275
  before do
276
+ Sunspot.remove_all
276
277
  @posts = (1..5).map do |i|
277
278
  post = Post.new
278
279
  Sunspot.index(post)
@@ -283,20 +284,20 @@ describe 'scoped_search' do
283
284
 
284
285
  it 'should not return excluded object' do
285
286
  excluded_post = @posts.shift
286
- Sunspot.search(Post) { without(excluded_post) }.results.should_not include(excluded_post)
287
+ expect(Sunspot.search(Post) { without(excluded_post) }.results).not_to include(excluded_post)
287
288
  end
288
289
 
289
290
  it 'should return objects not excluded' do
290
291
  excluded_post = @posts.shift
291
292
  for included_post in @posts
292
- Sunspot.search(Post) { without(excluded_post) }.results.should include(included_post)
293
+ expect(Sunspot.search(Post) { without(excluded_post) }.results).to include(included_post)
293
294
  end
294
295
  end
295
296
 
296
297
  it 'should not return excluded objects' do
297
298
  excluded_posts = [@posts.shift, @posts.shift]
298
299
  for excluded_post in excluded_posts
299
- Sunspot.search(Post) { without(excluded_posts) }.results.should_not include(excluded_post)
300
+ expect(Sunspot.search(Post) { without(excluded_posts) }.results).not_to include(excluded_post)
300
301
  end
301
302
  end
302
303
  end
@@ -309,50 +310,50 @@ describe 'scoped_search' do
309
310
  it 'should return results that match any restriction in a disjunction' do
310
311
  posts = (1..3).map { |i| Post.new(:blog_id => i)}
311
312
  Sunspot.index!(posts)
312
- Sunspot.search(Post) do
313
+ expect(Sunspot.search(Post) do
313
314
  any_of do
314
315
  with(:blog_id, 1)
315
316
  with(:blog_id, 2)
316
317
  end
317
- end.results.should == posts[0..1]
318
+ end.results).to eq(posts[0..1])
318
319
  end
319
320
 
320
321
  it 'should return results, ignoring any restriction in a disjunction that has been passed an empty array' do
321
322
  posts = (1..3).map { |i| Post.new(:blog_id => i)}
322
323
  Sunspot.index!(posts)
323
- Sunspot.search(Post) do
324
+ expect(Sunspot.search(Post) do
324
325
  with(:blog_id, [])
325
- end.results.should == posts
326
+ end.results).to eq(posts)
326
327
  end
327
328
 
328
329
  it 'should return results, ignoring any restriction in a negative disjunction that has been passed an empty array' do
329
330
  posts = (1..3).map { |i| Post.new(:blog_id => i)}
330
331
  Sunspot.index!(posts)
331
- Sunspot.search(Post) do
332
+ expect(Sunspot.search(Post) do
332
333
  without(:blog_id, [])
333
- end.results.should == posts
334
+ end.results).to eq(posts)
334
335
  end
335
336
 
336
337
  it 'should return results, ignoring any restriction in a conjunction that has been passed an empty array' do
337
338
  posts = (1..3).map { |i| Post.new(:blog_id => i)}
338
339
  Sunspot.index!(posts)
339
- Sunspot.search(Post) do
340
+ expect(Sunspot.search(Post) do
340
341
  all_of do
341
342
  with(:blog_id, 1)
342
343
  with(:blog_id, [])
343
344
  end
344
- end.results.should == posts[0..0]
345
+ end.results).to eq(posts[0..0])
345
346
  end
346
347
 
347
348
  it 'should return results, ignoring any restriction in a negative conjunction that has been passed an empty array' do
348
349
  posts = (1..3).map { |i| Post.new(:blog_id => i)}
349
350
  Sunspot.index!(posts)
350
- Sunspot.search(Post) do
351
+ expect(Sunspot.search(Post) do
351
352
  all_of do
352
353
  with(:blog_id, 1)
353
354
  without(:blog_id, [])
354
355
  end
355
- end.results.should == posts[0..0]
356
+ end.results).to eq(posts[0..0])
356
357
  end
357
358
 
358
359
  it 'should return results that match a nested conjunction in a disjunction' do
@@ -363,7 +364,7 @@ describe 'scoped_search' do
363
364
  Post.new(:title => 'No', :blog_id => 2)
364
365
  ]
365
366
  Sunspot.index!(posts)
366
- Sunspot.search(Post) do
367
+ expect(Sunspot.search(Post) do
367
368
  any_of do
368
369
  with(:blog_id, 1)
369
370
  all_of do
@@ -371,7 +372,7 @@ describe 'scoped_search' do
371
372
  with(:title, 'Yes')
372
373
  end
373
374
  end
374
- end.results.should == posts[0..1]
375
+ end.results).to eq(posts[0..1])
375
376
  end
376
377
 
377
378
  it 'should return results that match a conjunction with a negated restriction' do
@@ -387,7 +388,7 @@ describe 'scoped_search' do
387
388
  without(:title, 'No')
388
389
  end
389
390
  end
390
- search.results.should == posts[0..1]
391
+ expect(search.results).to eq(posts[0..1])
391
392
  end
392
393
 
393
394
  it 'should return results that match a conjunction with a disjunction with a conjunction with a negated restriction' do
@@ -411,7 +412,7 @@ describe 'scoped_search' do
411
412
  end
412
413
  end
413
414
  end
414
- search.results.should == posts[0..2]
415
+ expect(search.results).to eq(posts[0..2])
415
416
  end
416
417
 
417
418
  it 'should return results that match a disjunction with a negated restriction and a nested disjunction in a conjunction with a negated restriction' do
@@ -436,7 +437,7 @@ describe 'scoped_search' do
436
437
  end
437
438
  end
438
439
  end
439
- search.results.should == posts[0..2]
440
+ expect(search.results).to eq(posts[0..2])
440
441
  end
441
442
  end
442
443
 
@@ -456,7 +457,7 @@ describe 'scoped_search' do
456
457
  order_by :average_rating, :desc
457
458
  order_by :sort_title, :asc
458
459
  end
459
- search.results.should == @posts
460
+ expect(search.results).to eq(@posts)
460
461
  end
461
462
  end
462
463
 
@@ -466,45 +467,40 @@ describe 'scoped_search' do
466
467
  Sunspot.index!(Array.new(100) { Post.new })
467
468
  end
468
469
 
469
- it 'should order randomly (run this test again if it fails)' do
470
- result_sets = Array.new(2) do
471
- Sunspot.search(Post) { order_by(:random) }.results.map do |result|
472
- result.id
473
- end
470
+ def search_ordered_by_random(direction = nil)
471
+ Sunspot.search(Post) do
472
+ order_by(:random, direction)
473
+ paginate(:page => 1, :per_page => 100)
474
474
  end
475
- result_sets[0].should_not == result_sets[1]
476
475
  end
477
476
 
478
- # This could fail if the random set returned just happens to be the same as the last random set (the nature of randomness)
477
+ it 'should order randomly' do
478
+ result_sets = Array.new(5) do
479
+ search_ordered_by_random.results.map { |result| result.id }
480
+ end
481
+ expect(result_sets.uniq.size).to be > 1
482
+ end
483
+
479
484
  it 'should order randomly using the order_by function and passing a direction' do
480
- result_sets = Array.new(2) do
481
- Sunspot.search(Post) { order_by(:random, :desc) }.results.map do |result|
482
- result.id
483
- end
485
+ result_sets = Array.new(5) do
486
+ search_ordered_by_random(:desc).results.map { |result| result.id }
484
487
  end
485
- result_sets[0].should_not == result_sets[1]
488
+ expect(result_sets.uniq.size).to be > 1
486
489
  end
487
490
 
488
491
  context 'when providing a custom seed value' do
489
492
  before do
490
- @first_results = Sunspot.search(Post) do
491
- order_by(:random, :seed => 12345)
492
- end.results.map { |result| result.id }
493
+ @first_results = search_ordered_by_random(:seed => 12345).results.map { |result| result.id }
493
494
  end
494
495
 
495
- # This could fail if the random set returned just happens to be the same as the last random set (the nature of randomness)
496
496
  it 'should return different results when passing a different seed value' do
497
- next_results = Sunspot.search(Post) do
498
- order_by(:random, :seed => 54321)
499
- end.results.map { |result| result.id }
500
- next_results.should_not == @first_results
497
+ next_results = search_ordered_by_random(:seed => 54321).results.map { |result| result.id }
498
+ expect(next_results).not_to eq(@first_results)
501
499
  end
502
500
 
503
501
  it 'should return the same results when passing the same seed value' do
504
- next_results = Sunspot.search(Post) do
505
- order_by(:random, :seed => 12345)
506
- end.results.map { |result| result.id }
507
- next_results.should == @first_results
502
+ next_results = search_ordered_by_random(:seed => 12345).results.map { |result| result.id }
503
+ expect(next_results).to eq(@first_results)
508
504
  end
509
505
  end
510
506
  end
@@ -517,25 +513,29 @@ describe 'scoped_search' do
517
513
  Sunspot.index([@p1,@p2])
518
514
  Sunspot.commit
519
515
  end
516
+
520
517
  it 'should order by sum' do
521
518
  # 1+3 > 2+1
522
519
  search = Sunspot.search(Post) {order_by_function :sum, :blog_id, :primary_category_id, :desc}
523
- search.results.first.should == @p1
520
+ expect(search.results.first).to eq(@p1)
524
521
  end
522
+
525
523
  it 'should order by product and sum' do
526
524
  # 1 * (1+3) < 2 * (2+1)
527
525
  search = Sunspot.search(Post) { order_by_function :product, :blog_id, [:sum,:blog_id,:primary_category_id], :desc}
528
- search.results.first.should == @p2
526
+ expect(search.results.first).to eq(@p2)
529
527
  end
528
+
530
529
  it 'should accept string literals' do
531
530
  # (1 * -2) > (2 * -2)
532
531
  search = Sunspot.search(Post) {order_by_function :product, :blog_id, '-2', :desc}
533
- search.results.first.should == @p1
532
+ expect(search.results.first).to eq(@p1)
534
533
  end
534
+
535
535
  it 'should accept non-string literals' do
536
536
  # (1 * -2) > (2 * -2)
537
537
  search = Sunspot.search(Post) {order_by_function :product, :blog_id, -2, :desc}
538
- search.results.first.should == @p1
538
+ expect(search.results.first).to eq(@p1)
539
539
  end
540
540
  end
541
541
  end