sunspot_matchers 2.1.0.1 → 2.1.1.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/lib/sunspot_matchers/matchers.rb +6 -6
- data/lib/sunspot_matchers/version.rb +1 -1
- data/spec/have_searchable_field_matcher_spec.rb +8 -3
- data/spec/sunspot_matchers_spec.rb +164 -166
- data/sunspot_matchers.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b8548cd1bcdfe461b406e3ed49c4444a90420d9
|
4
|
+
data.tar.gz: d7cf21aabe2c90fdb63d6a24a6529d0784c4d145
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48696bd6207d61fa04f233fb226d3cc7895a6fda5376ad9e48a27697af36f95a15a331cb79e653bce4b979982240b5859a8edb3690205dc99ab4686e41d60c82
|
7
|
+
data.tar.gz: 7d8bda1169a4fb790990fefe74f47fb261b28d5622d195aad5de0f6e25935ddb7b320d783338741bd41be324abbe88509bfc559afb351e2820baf94d552ec56e
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sunspot_matchers (2.1.
|
4
|
+
sunspot_matchers (2.1.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
builder (3.2.2)
|
10
|
-
diff-lcs (1.
|
10
|
+
diff-lcs (1.2.5)
|
11
11
|
pr_geohash (1.0.0)
|
12
|
-
rake (
|
13
|
-
rsolr (1.0.
|
12
|
+
rake (10.3.1)
|
13
|
+
rsolr (1.0.10)
|
14
14
|
builder (>= 2.1.2)
|
15
|
-
rspec (2.
|
16
|
-
rspec-core (~> 2.
|
17
|
-
rspec-expectations (~> 2.
|
18
|
-
rspec-mocks (~> 2.
|
19
|
-
rspec-core (2.
|
20
|
-
rspec-expectations (2.
|
21
|
-
diff-lcs (
|
22
|
-
rspec-mocks (2.
|
23
|
-
sunspot (2.1.
|
15
|
+
rspec (2.14.1)
|
16
|
+
rspec-core (~> 2.14.0)
|
17
|
+
rspec-expectations (~> 2.14.0)
|
18
|
+
rspec-mocks (~> 2.14.0)
|
19
|
+
rspec-core (2.14.8)
|
20
|
+
rspec-expectations (2.14.5)
|
21
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
22
|
+
rspec-mocks (2.14.6)
|
23
|
+
sunspot (2.1.1)
|
24
24
|
pr_geohash (~> 1.0)
|
25
25
|
rsolr (~> 1.0.7)
|
26
26
|
|
@@ -30,6 +30,6 @@ PLATFORMS
|
|
30
30
|
DEPENDENCIES
|
31
31
|
bundler (>= 1.0.0)
|
32
32
|
rake
|
33
|
-
rspec (~> 2.
|
34
|
-
sunspot (~> 2.1.
|
33
|
+
rspec (~> 2.0)
|
34
|
+
sunspot (~> 2.1.1)
|
35
35
|
sunspot_matchers!
|
@@ -135,11 +135,11 @@ module SunspotMatchers
|
|
135
135
|
@matcher.match?
|
136
136
|
end
|
137
137
|
|
138
|
-
def
|
138
|
+
def failure_message
|
139
139
|
@matcher.missing_param_error_message
|
140
140
|
end
|
141
141
|
|
142
|
-
def
|
142
|
+
def failure_message_when_negated
|
143
143
|
@matcher.unexpected_match_error_message
|
144
144
|
end
|
145
145
|
|
@@ -306,11 +306,11 @@ module SunspotMatchers
|
|
306
306
|
search_tuple.first
|
307
307
|
end
|
308
308
|
|
309
|
-
def
|
309
|
+
def failure_message
|
310
310
|
"expected search class: #{search_types.join(' and ')} to match expected class: #{@expected_class}"
|
311
311
|
end
|
312
312
|
|
313
|
-
def
|
313
|
+
def failure_message_when_negated
|
314
314
|
"expected search class: #{search_types.join(' and ')} NOT to match expected class: #{@expected_class}"
|
315
315
|
end
|
316
316
|
end
|
@@ -335,12 +335,12 @@ module SunspotMatchers
|
|
335
335
|
"should have searchable field #{@field}"
|
336
336
|
end
|
337
337
|
|
338
|
-
def
|
338
|
+
def failure_message
|
339
339
|
message = "expected class: #{@klass} to have searchable field: #{@field}"
|
340
340
|
message << ", but Sunspot was not configured on #{@klass}" unless @sunspot
|
341
341
|
end
|
342
342
|
|
343
|
-
def
|
343
|
+
def failure_message_when_negated
|
344
344
|
"expected class: #{@klass} NOT to have searchable field: #{@field}"
|
345
345
|
end
|
346
346
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'sunspot'
|
2
2
|
require 'sunspot_matchers'
|
3
|
+
require 'rspec'
|
3
4
|
|
4
5
|
describe SunspotMatchers::HaveSearchableField do
|
5
|
-
|
6
|
+
let(:matcher) do
|
6
7
|
described_class.new(:field).tap do |matcher|
|
7
8
|
matcher.matches? klass
|
8
9
|
end
|
@@ -11,7 +12,9 @@ describe SunspotMatchers::HaveSearchableField do
|
|
11
12
|
context "when a class has no searchable fields" do
|
12
13
|
let(:klass) { NotALotGoingOn = Class.new }
|
13
14
|
|
14
|
-
|
15
|
+
it "gives Sunspot configuration error" do
|
16
|
+
expect(matcher.failure_message).to match(/Sunspot was not configured/)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
context "when a class has an unexpected searchable field" do
|
@@ -20,6 +23,8 @@ describe SunspotMatchers::HaveSearchableField do
|
|
20
23
|
Sunspot.setup(klass) { text :parachute }
|
21
24
|
end
|
22
25
|
|
23
|
-
|
26
|
+
it "does not have an error" do
|
27
|
+
expect(matcher.failure_message).to be_nil
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
@@ -33,142 +33,142 @@ describe "Sunspot Matchers" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "have_search_params" do
|
36
|
-
it "
|
36
|
+
it "allows you to specify your search on multiple models" do
|
37
37
|
Sunspot.search([Post, Blog]) do
|
38
38
|
keywords 'great pizza'
|
39
39
|
end
|
40
|
-
Sunspot.session.
|
40
|
+
expect(Sunspot.session).to have_search_params(:keywords, 'great pizza')
|
41
41
|
end
|
42
42
|
|
43
|
-
it "
|
43
|
+
it "allows you to specify your search" do
|
44
44
|
Sunspot.search(Post) do
|
45
45
|
keywords 'great pizza'
|
46
46
|
end
|
47
47
|
Sunspot.search(Blog) do
|
48
48
|
keywords 'bad pizza'
|
49
49
|
end
|
50
|
-
Sunspot.session.searches.first.
|
51
|
-
Sunspot.session.searches.last.
|
50
|
+
expect(Sunspot.session.searches.first).to have_search_params(:keywords, 'great pizza')
|
51
|
+
expect(Sunspot.session.searches.last).to have_search_params(:keywords, 'bad pizza')
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "keyword/fulltext matcher" do
|
55
|
-
it "
|
55
|
+
it "matches if search matches" do
|
56
56
|
Sunspot.search(Post) do
|
57
57
|
keywords 'great pizza'
|
58
58
|
end
|
59
|
-
Sunspot.session.
|
59
|
+
expect(Sunspot.session).to have_search_params(:keywords, 'great pizza')
|
60
60
|
end
|
61
61
|
|
62
|
-
it "
|
62
|
+
it "works with fulltext also" do
|
63
63
|
Sunspot.search(Post) do
|
64
64
|
fulltext 'great pizza'
|
65
65
|
end
|
66
|
-
Sunspot.session.
|
66
|
+
expect(Sunspot.session).to have_search_params(:fulltext, 'great pizza')
|
67
67
|
end
|
68
68
|
|
69
|
-
it "
|
69
|
+
it "does not match if search does not match" do
|
70
70
|
Sunspot.search(Post) do
|
71
71
|
keywords 'terrible pizza'
|
72
72
|
end
|
73
|
-
Sunspot.session.
|
73
|
+
expect(Sunspot.session).to_not have_search_params(:keywords, 'great pizza')
|
74
74
|
end
|
75
75
|
|
76
|
-
it "
|
76
|
+
it "matches for multiple keywords" do
|
77
77
|
Sunspot.search(Post) do
|
78
78
|
keywords 'great pizza'
|
79
79
|
keywords 'terrible pizza'
|
80
80
|
end
|
81
|
-
Sunspot.session.
|
81
|
+
expect(Sunspot.session).to have_search_params(:keywords) {
|
82
82
|
keywords 'great pizza'
|
83
83
|
keywords 'terrible pizza'
|
84
84
|
}
|
85
85
|
end
|
86
86
|
|
87
|
-
it "
|
87
|
+
it "works with any_param match" do
|
88
88
|
Sunspot.search(Post) do
|
89
89
|
keywords 'great pizza'
|
90
90
|
end
|
91
|
-
Sunspot.session.
|
91
|
+
expect(Sunspot.session).to have_search_params(:keywords, any_param)
|
92
92
|
end
|
93
93
|
|
94
|
-
it "
|
94
|
+
it "works with any_param negative match" do
|
95
95
|
Sunspot.search(Post) do
|
96
96
|
with :blog_id, 4
|
97
97
|
end
|
98
|
-
Sunspot.session.
|
98
|
+
expect(Sunspot.session).to_not have_search_params(:keywords, any_param)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
describe "with matcher" do
|
103
|
-
it "
|
103
|
+
it "matches if search matches" do
|
104
104
|
Sunspot.search(Post) do
|
105
105
|
with :author_name, 'Mark Twain'
|
106
106
|
end
|
107
|
-
Sunspot.session.
|
107
|
+
expect(Sunspot.session).to have_search_params(:with, :author_name, 'Mark Twain')
|
108
108
|
end
|
109
109
|
|
110
|
-
it "
|
110
|
+
it "does not match if search does not match" do
|
111
111
|
Sunspot.search(Post) do
|
112
112
|
with :author_name, 'Mark Twain'
|
113
113
|
end
|
114
|
-
Sunspot.session.
|
114
|
+
expect(Sunspot.session).to_not have_search_params(:with, :author_name, 'John Twain')
|
115
115
|
end
|
116
116
|
|
117
|
-
it "
|
117
|
+
it "matches for multiple with" do
|
118
118
|
Sunspot.search(Post) do
|
119
119
|
with :author_name, 'Mark Twain'
|
120
120
|
with :author_name, 'John Twain'
|
121
121
|
end
|
122
|
-
Sunspot.session.
|
122
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
123
123
|
with :author_name, 'Mark Twain'
|
124
124
|
with :author_name, 'John Twain'
|
125
125
|
}
|
126
126
|
end
|
127
127
|
|
128
|
-
it "
|
128
|
+
it "matches for greater_than" do
|
129
129
|
Sunspot.search(Post) do
|
130
130
|
with(:category_ids).greater_than(1)
|
131
131
|
end
|
132
|
-
Sunspot.session.
|
132
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
133
133
|
with(:category_ids).greater_than(1)
|
134
134
|
}
|
135
135
|
end
|
136
136
|
|
137
|
-
it "
|
137
|
+
it "matches for less_than" do
|
138
138
|
Sunspot.search(Post) do
|
139
139
|
with(:category_ids).less_than(1)
|
140
140
|
end
|
141
|
-
Sunspot.session.
|
141
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
142
142
|
with(:category_ids).less_than(1)
|
143
143
|
}
|
144
144
|
end
|
145
145
|
|
146
|
-
it "
|
146
|
+
it "matches for range" do
|
147
147
|
Sunspot.search(Post) do
|
148
148
|
with :category_ids, 1..3
|
149
149
|
end
|
150
|
-
Sunspot.session.
|
150
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
151
151
|
with :category_ids, 1..3
|
152
152
|
}
|
153
153
|
end
|
154
154
|
|
155
|
-
it "
|
155
|
+
it "matches any_of" do
|
156
156
|
Sunspot.search(Post) do
|
157
157
|
with(:category_ids).any_of [1, 2]
|
158
158
|
end
|
159
|
-
Sunspot.session.
|
159
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
160
160
|
with(:category_ids).any_of [1, 2]
|
161
161
|
}
|
162
162
|
end
|
163
163
|
|
164
|
-
it "
|
164
|
+
it "matches any_of multiline" do
|
165
165
|
Sunspot.search(Post) do
|
166
166
|
any_of do
|
167
167
|
with :category_ids, 1
|
168
168
|
with :category_ids, 2
|
169
169
|
end
|
170
170
|
end
|
171
|
-
Sunspot.session.
|
171
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
172
172
|
any_of do
|
173
173
|
with :category_ids, 1
|
174
174
|
with :category_ids, 2
|
@@ -176,7 +176,7 @@ describe "Sunspot Matchers" do
|
|
176
176
|
}
|
177
177
|
end
|
178
178
|
|
179
|
-
it "
|
179
|
+
it "matches any_of and all_of" do
|
180
180
|
Sunspot.search(Post) do
|
181
181
|
any_of do
|
182
182
|
with :category_ids, 1
|
@@ -186,7 +186,7 @@ describe "Sunspot Matchers" do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
189
|
-
Sunspot.session.
|
189
|
+
expect(Sunspot.session).to have_search_params(:with) {
|
190
190
|
any_of do
|
191
191
|
with :category_ids, 1
|
192
192
|
all_of do
|
@@ -197,120 +197,120 @@ describe "Sunspot Matchers" do
|
|
197
197
|
}
|
198
198
|
end
|
199
199
|
|
200
|
-
it "
|
200
|
+
it "works with any_param match" do
|
201
201
|
Sunspot.search(Post) do
|
202
202
|
with :blog_id, 4
|
203
203
|
end
|
204
|
-
Sunspot.session.
|
204
|
+
expect(Sunspot.session).to have_search_params(:with, :blog_id, any_param)
|
205
205
|
end
|
206
206
|
|
207
|
-
it "
|
207
|
+
it "works with a time attribute and any_param match" do
|
208
208
|
Sunspot.search(Post) do
|
209
209
|
with :published_at, 'July 1st, 2009'
|
210
210
|
end
|
211
|
-
Sunspot.session.
|
211
|
+
expect(Sunspot.session).to have_search_params(:with, :published_at, any_param)
|
212
212
|
end
|
213
213
|
|
214
|
-
it "
|
214
|
+
it "works with any_param negative match no with at all" do
|
215
215
|
Sunspot.search(Post) do
|
216
216
|
keywords 'great pizza'
|
217
217
|
end
|
218
|
-
Sunspot.session.
|
218
|
+
expect(Sunspot.session).to_not have_search_params(:with, :blog_id, any_param)
|
219
219
|
end
|
220
220
|
|
221
|
-
it "
|
221
|
+
it "works with any_param negative match when without exists" do
|
222
222
|
Sunspot.search(Post) do
|
223
223
|
without :blog_id, 4
|
224
224
|
without :blog_id, 5
|
225
225
|
end
|
226
|
-
Sunspot.session.
|
226
|
+
expect(Sunspot.session).to_not have_search_params(:with, :blog_id, any_param)
|
227
227
|
end
|
228
228
|
|
229
|
-
it "
|
229
|
+
it "works with any_param negative match different field with query" do
|
230
230
|
Sunspot.search(Post) do
|
231
231
|
with :category_ids, 7
|
232
232
|
end
|
233
|
-
Sunspot.session.
|
233
|
+
expect(Sunspot.session).to_not have_search_params(:with, :blog_id, any_param)
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
237
237
|
describe "without matcher" do
|
238
|
-
it "
|
238
|
+
it "matches if search matches" do
|
239
239
|
Sunspot.search(Post) do
|
240
240
|
without :author_name, 'Mark Twain'
|
241
241
|
end
|
242
|
-
Sunspot.session.
|
242
|
+
expect(Sunspot.session).to have_search_params(:without, :author_name, 'Mark Twain')
|
243
243
|
end
|
244
244
|
|
245
|
-
it "
|
245
|
+
it "does not match if search does not match" do
|
246
246
|
Sunspot.search(Post) do
|
247
247
|
without :author_name, 'Mark Twain'
|
248
248
|
end
|
249
|
-
Sunspot.session.
|
249
|
+
expect(Sunspot.session).to_not have_search_params(:without, :author_name, 'John Twain')
|
250
250
|
end
|
251
251
|
|
252
|
-
it "
|
252
|
+
it "does not match a with search" do
|
253
253
|
Sunspot.search(Post) do
|
254
254
|
with :author_name, 'Mark Twain'
|
255
255
|
end
|
256
|
-
Sunspot.session.
|
256
|
+
expect(Sunspot.session).to_not have_search_params(:without, :author_name, 'Mark Twain')
|
257
257
|
end
|
258
258
|
|
259
|
-
it "
|
259
|
+
it "matches for multiple without" do
|
260
260
|
Sunspot.search(Post) do
|
261
261
|
without :author_name, 'Mark Twain'
|
262
262
|
without :author_name, 'John Twain'
|
263
263
|
end
|
264
|
-
Sunspot.session.
|
264
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
265
265
|
without :author_name, 'Mark Twain'
|
266
266
|
without :author_name, 'John Twain'
|
267
267
|
}
|
268
268
|
end
|
269
269
|
|
270
|
-
it "
|
270
|
+
it "matches for greater_than" do
|
271
271
|
Sunspot.search(Post) do
|
272
272
|
without(:category_ids).greater_than(1)
|
273
273
|
end
|
274
|
-
Sunspot.session.
|
274
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
275
275
|
without(:category_ids).greater_than(1)
|
276
276
|
}
|
277
277
|
end
|
278
278
|
|
279
|
-
it "
|
279
|
+
it "matches for less_than" do
|
280
280
|
Sunspot.search(Post) do
|
281
281
|
without(:category_ids).less_than(1)
|
282
282
|
end
|
283
|
-
Sunspot.session.
|
283
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
284
284
|
without(:category_ids).less_than(1)
|
285
285
|
}
|
286
286
|
end
|
287
287
|
|
288
|
-
it "
|
288
|
+
it "matches for range" do
|
289
289
|
Sunspot.search(Post) do
|
290
290
|
without :category_ids, 1..3
|
291
291
|
end
|
292
|
-
Sunspot.session.
|
292
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
293
293
|
without :category_ids, 1..3
|
294
294
|
}
|
295
295
|
end
|
296
296
|
|
297
|
-
it "
|
297
|
+
it "matches any_of" do
|
298
298
|
Sunspot.search(Post) do
|
299
299
|
without(:category_ids).any_of [1, 2]
|
300
300
|
end
|
301
|
-
Sunspot.session.
|
301
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
302
302
|
without(:category_ids).any_of [1, 2]
|
303
303
|
}
|
304
304
|
end
|
305
305
|
|
306
|
-
it "
|
306
|
+
it "matches any_of multiline" do
|
307
307
|
Sunspot.search(Post) do
|
308
308
|
any_of do
|
309
309
|
without :category_ids, 1
|
310
310
|
without :category_ids, 2
|
311
311
|
end
|
312
312
|
end
|
313
|
-
Sunspot.session.
|
313
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
314
314
|
any_of do
|
315
315
|
without :category_ids, 1
|
316
316
|
without :category_ids, 2
|
@@ -318,7 +318,7 @@ describe "Sunspot Matchers" do
|
|
318
318
|
}
|
319
319
|
end
|
320
320
|
|
321
|
-
it "
|
321
|
+
it "matches any_of and all_of" do
|
322
322
|
Sunspot.search(Post) do
|
323
323
|
any_of do
|
324
324
|
without :category_ids, 1
|
@@ -328,7 +328,7 @@ describe "Sunspot Matchers" do
|
|
328
328
|
end
|
329
329
|
end
|
330
330
|
end
|
331
|
-
Sunspot.session.
|
331
|
+
expect(Sunspot.session).to have_search_params(:without) {
|
332
332
|
any_of do
|
333
333
|
without :category_ids, 1
|
334
334
|
all_of do
|
@@ -339,224 +339,224 @@ describe "Sunspot Matchers" do
|
|
339
339
|
}
|
340
340
|
end
|
341
341
|
|
342
|
-
it "
|
342
|
+
it "works with any_param match" do
|
343
343
|
Sunspot.search(Post) do
|
344
344
|
without :blog_id, 4
|
345
345
|
end
|
346
|
-
Sunspot.session.
|
346
|
+
expect(Sunspot.session).to have_search_params(:without, :blog_id, any_param)
|
347
347
|
end
|
348
348
|
|
349
|
-
it "
|
349
|
+
it "works with any_param negative match no without at all" do
|
350
350
|
Sunspot.search(Post) do
|
351
351
|
keywords 'great pizza'
|
352
352
|
end
|
353
|
-
Sunspot.session.
|
353
|
+
expect(Sunspot.session).to_not have_search_params(:without, :blog_id, any_param)
|
354
354
|
end
|
355
355
|
|
356
|
-
it "
|
356
|
+
it "works with any_param negative match when with exists" do
|
357
357
|
Sunspot.search(Post) do
|
358
358
|
with :blog_id, 4
|
359
359
|
end
|
360
|
-
Sunspot.session.
|
360
|
+
expect(Sunspot.session).to_not have_search_params(:without, :blog_id, any_param)
|
361
361
|
end
|
362
362
|
|
363
|
-
it "
|
363
|
+
it "works with any_param negative match different field without query" do
|
364
364
|
Sunspot.search(Post) do
|
365
365
|
without :category_ids, 4
|
366
366
|
end
|
367
|
-
Sunspot.session.
|
367
|
+
expect(Sunspot.session).to_not have_search_params(:without, :blog_id, any_param)
|
368
368
|
end
|
369
369
|
end
|
370
370
|
|
371
371
|
describe "paginate matcher" do
|
372
|
-
it "
|
372
|
+
it "matches if search matches" do
|
373
373
|
Sunspot.search(Post) do
|
374
374
|
paginate :page => 3, :per_page => 15
|
375
375
|
end
|
376
|
-
Sunspot.session.
|
376
|
+
expect(Sunspot.session).to have_search_params(:paginate, :page => 3, :per_page => 15)
|
377
377
|
end
|
378
378
|
|
379
|
-
it "
|
379
|
+
it "matches if search matches, page only" do
|
380
380
|
Sunspot.search(Post) do
|
381
381
|
paginate :page => 3
|
382
382
|
end
|
383
|
-
Sunspot.session.
|
383
|
+
expect(Sunspot.session).to have_search_params(:paginate, :page => 3)
|
384
384
|
end
|
385
385
|
|
386
|
-
it "
|
386
|
+
it "matches if search matches, per_page only" do
|
387
387
|
Sunspot.search(Post) do
|
388
388
|
paginate :per_page => 15
|
389
389
|
end
|
390
|
-
Sunspot.session.
|
390
|
+
expect(Sunspot.session).to have_search_params(:paginate, :per_page => 15)
|
391
391
|
end
|
392
392
|
|
393
|
-
it "
|
393
|
+
it "does not match if per_page does not match" do
|
394
394
|
Sunspot.search(Post) do
|
395
395
|
paginate :page => 3, :per_page => 30
|
396
396
|
end
|
397
|
-
Sunspot.session.
|
397
|
+
expect(Sunspot.session).to_not have_search_params(:paginate, :page => 3, :per_page => 15)
|
398
398
|
end
|
399
399
|
|
400
|
-
it "
|
400
|
+
it "does not match if page does not match" do
|
401
401
|
Sunspot.search(Post) do
|
402
402
|
paginate :page => 5, :per_page => 15
|
403
403
|
end
|
404
|
-
Sunspot.session.
|
404
|
+
expect(Sunspot.session).to_not have_search_params(:paginate, :page => 3, :per_page => 15)
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
408
408
|
describe "order_by matcher" do
|
409
|
-
it "
|
409
|
+
it "matches if search matches" do
|
410
410
|
Sunspot.search(Post) do
|
411
411
|
order_by :published_at, :desc
|
412
412
|
end
|
413
|
-
Sunspot.session.
|
413
|
+
expect(Sunspot.session).to have_search_params(:order_by, :published_at, :desc)
|
414
414
|
end
|
415
415
|
|
416
|
-
it "
|
416
|
+
it "does not match if search does not match" do
|
417
417
|
Sunspot.search(Post) do
|
418
418
|
order_by :published_at, :asc
|
419
419
|
end
|
420
|
-
Sunspot.session.
|
420
|
+
expect(Sunspot.session).to_not have_search_params(:order_by, :published_at, :desc)
|
421
421
|
end
|
422
422
|
|
423
|
-
it "
|
423
|
+
it "matches for multiple orderings" do
|
424
424
|
Sunspot.search(Post) do
|
425
425
|
order_by :published_at, :asc
|
426
426
|
order_by :average_rating, :asc
|
427
427
|
end
|
428
|
-
Sunspot.session.
|
428
|
+
expect(Sunspot.session).to have_search_params(:order_by) {
|
429
429
|
order_by :published_at, :asc
|
430
430
|
order_by :average_rating, :asc
|
431
431
|
}
|
432
432
|
end
|
433
433
|
|
434
|
-
it "
|
434
|
+
it "does not match if multiple orderings are reversed" do
|
435
435
|
Sunspot.search(Post) do
|
436
436
|
order_by :average_rating, :asc
|
437
437
|
order_by :published_at, :asc
|
438
438
|
end
|
439
|
-
Sunspot.session.
|
439
|
+
expect(Sunspot.session).to_not have_search_params(:order_by) {
|
440
440
|
order_by :published_at, :asc
|
441
441
|
order_by :average_rating, :asc
|
442
442
|
}
|
443
443
|
end
|
444
444
|
|
445
|
-
it "
|
445
|
+
it "matches when using random" do
|
446
446
|
Sunspot.search(Post) do
|
447
447
|
order_by :average_rating, :asc
|
448
448
|
order_by :random
|
449
449
|
end
|
450
|
-
Sunspot.session.
|
450
|
+
expect(Sunspot.session).to have_search_params(:order_by) {
|
451
451
|
order_by :average_rating, :asc
|
452
452
|
order_by :random
|
453
453
|
}
|
454
454
|
end
|
455
455
|
|
456
|
-
it "
|
456
|
+
it "does not match when random is missing" do
|
457
457
|
Sunspot.search(Post) do
|
458
458
|
order_by :average_rating, :asc
|
459
459
|
order_by :random
|
460
460
|
end
|
461
|
-
Sunspot.session.
|
461
|
+
expect(Sunspot.session).to_not have_search_params(:order_by) {
|
462
462
|
order_by :average_rating, :asc
|
463
463
|
}
|
464
464
|
end
|
465
465
|
|
466
|
-
it "
|
466
|
+
it "matches when using score" do
|
467
467
|
Sunspot.search(Post) do
|
468
468
|
order_by :average_rating, :asc
|
469
469
|
order_by :score
|
470
470
|
end
|
471
|
-
Sunspot.session.
|
471
|
+
expect(Sunspot.session).to have_search_params(:order_by) {
|
472
472
|
order_by :average_rating, :asc
|
473
473
|
order_by :score
|
474
474
|
}
|
475
475
|
end
|
476
476
|
|
477
|
-
it "
|
477
|
+
it "does not match when score is missing" do
|
478
478
|
Sunspot.search(Post) do
|
479
479
|
order_by :average_rating, :asc
|
480
480
|
order_by :score
|
481
481
|
end
|
482
|
-
Sunspot.session.
|
482
|
+
expect(Sunspot.session).to_not have_search_params(:order_by) {
|
483
483
|
order_by :average_rating, :asc
|
484
484
|
}
|
485
485
|
end
|
486
486
|
|
487
|
-
it "
|
487
|
+
it "works with any_param match on direction" do
|
488
488
|
Sunspot.search(Post) do
|
489
489
|
order_by :average_rating, :asc
|
490
490
|
end
|
491
|
-
Sunspot.session.
|
491
|
+
expect(Sunspot.session).to have_search_params(:order_by, :average_rating, any_param)
|
492
492
|
end
|
493
493
|
|
494
|
-
it "
|
494
|
+
it "works with any_param match on field" do
|
495
495
|
Sunspot.search(Post) do
|
496
496
|
order_by :average_rating, :asc
|
497
497
|
end
|
498
|
-
Sunspot.session.
|
498
|
+
expect(Sunspot.session).to have_search_params(:order_by, any_param)
|
499
499
|
end
|
500
500
|
|
501
|
-
it "
|
501
|
+
it "works with any_param negative match on direction" do
|
502
502
|
Sunspot.search(Post) do
|
503
503
|
order_by :score
|
504
504
|
end
|
505
|
-
Sunspot.session.
|
505
|
+
expect(Sunspot.session).to_not have_search_params(:order_by, :average_rating, any_param)
|
506
506
|
end
|
507
507
|
|
508
|
-
it "
|
508
|
+
it "works with any_param negative match on field" do
|
509
509
|
Sunspot.search(Post) do
|
510
510
|
keywords 'great pizza'
|
511
511
|
end
|
512
|
-
Sunspot.session.
|
512
|
+
expect(Sunspot.session).to_not have_search_params(:order_by, any_param)
|
513
513
|
end
|
514
514
|
|
515
|
-
it "
|
515
|
+
it "works with any_param match on field and direction" do
|
516
516
|
Sunspot.search(Post) do
|
517
517
|
order_by :score, :desc
|
518
518
|
end
|
519
|
-
Sunspot.session.
|
519
|
+
expect(Sunspot.session).to have_search_params(:order_by, any_param, any_param)
|
520
520
|
end
|
521
521
|
|
522
|
-
it "
|
522
|
+
it "works with any_param negative match on field and direction" do
|
523
523
|
Sunspot.search(Post) do
|
524
524
|
keywords 'great pizza'
|
525
525
|
end
|
526
|
-
Sunspot.session.
|
526
|
+
expect(Sunspot.session).to_not have_search_params(:order_by, any_param, any_param)
|
527
527
|
end
|
528
528
|
end
|
529
529
|
|
530
530
|
describe "facet matcher" do
|
531
531
|
describe "field facets" do
|
532
|
-
it "
|
532
|
+
it "matches if facet exists" do
|
533
533
|
Sunspot.search(Post) do
|
534
534
|
facet :category_ids
|
535
535
|
end
|
536
|
-
Sunspot.session.
|
536
|
+
expect(Sunspot.session).to have_search_params(:facet, :category_ids)
|
537
537
|
end
|
538
538
|
|
539
|
-
it "
|
539
|
+
it "matches if multiple facet exists" do
|
540
540
|
Sunspot.search(Post) do
|
541
541
|
facet :category_ids
|
542
542
|
facet :blog_id
|
543
543
|
end
|
544
|
-
Sunspot.session.
|
544
|
+
expect(Sunspot.session).to have_search_params(:facet, :category_ids)
|
545
545
|
end
|
546
546
|
|
547
|
-
it "
|
547
|
+
it "does not match if facet does not exist" do
|
548
548
|
Sunspot.search(Post) do
|
549
549
|
paginate :page => 5, :per_page => 15
|
550
550
|
end
|
551
|
-
Sunspot.session.
|
551
|
+
expect(Sunspot.session).to_not have_search_params(:facet, :category_ids)
|
552
552
|
end
|
553
553
|
|
554
|
-
it "
|
554
|
+
it "matches when excluding filters" do
|
555
555
|
Sunspot.search(Post) do
|
556
556
|
category_filter = with(:category_ids, 2)
|
557
557
|
facet(:category_ids, :exclude => category_filter)
|
558
558
|
end
|
559
|
-
Sunspot.session.
|
559
|
+
expect(Sunspot.session).to have_search_params(:facet) {
|
560
560
|
category_filter = with(:category_ids, 2)
|
561
561
|
facet(:category_ids, :exclude => category_filter)
|
562
562
|
}
|
@@ -564,7 +564,7 @@ describe "Sunspot Matchers" do
|
|
564
564
|
end
|
565
565
|
|
566
566
|
describe "query facets" do
|
567
|
-
it "
|
567
|
+
it "matches if facet exists" do
|
568
568
|
Sunspot.search(Post) do
|
569
569
|
facet(:average_rating) do
|
570
570
|
row(1.0..2.0) do
|
@@ -575,7 +575,7 @@ describe "Sunspot Matchers" do
|
|
575
575
|
end
|
576
576
|
end
|
577
577
|
end
|
578
|
-
Sunspot.session.
|
578
|
+
expect(Sunspot.session).to have_search_params(:facet) {
|
579
579
|
facet(:average_rating) do
|
580
580
|
row(1.0..2.0) do
|
581
581
|
with(:average_rating, 1.0..2.0)
|
@@ -587,7 +587,7 @@ describe "Sunspot Matchers" do
|
|
587
587
|
}
|
588
588
|
end
|
589
589
|
|
590
|
-
it "
|
590
|
+
it "matches if multiple facet exists, but the facet you are matching on only has a single row" do
|
591
591
|
Sunspot.search(Post) do
|
592
592
|
facet(:average_rating) do
|
593
593
|
row(1.0..2.0) do
|
@@ -604,7 +604,7 @@ describe "Sunspot Matchers" do
|
|
604
604
|
end
|
605
605
|
end
|
606
606
|
end
|
607
|
-
Sunspot.session.
|
607
|
+
expect(Sunspot.session).to have_search_params(:facet) {
|
608
608
|
facet(:average_rating) do
|
609
609
|
row(1.0..2.0) do
|
610
610
|
with(:average_rating, 1.0..2.0)
|
@@ -613,7 +613,7 @@ describe "Sunspot Matchers" do
|
|
613
613
|
}
|
614
614
|
end
|
615
615
|
|
616
|
-
it "
|
616
|
+
it "does not match if actual search is missing a facet" do
|
617
617
|
Sunspot.search(Post) do
|
618
618
|
facet(:average_rating) do
|
619
619
|
row(1.0..2.0) do
|
@@ -621,7 +621,7 @@ describe "Sunspot Matchers" do
|
|
621
621
|
end
|
622
622
|
end
|
623
623
|
end
|
624
|
-
Sunspot.session.
|
624
|
+
expect(Sunspot.session).to_not have_search_params(:facet) {
|
625
625
|
facet(:average_rating) do
|
626
626
|
row(1.0..2.0) do
|
627
627
|
with(:average_rating, 1.0..2.0)
|
@@ -633,7 +633,7 @@ describe "Sunspot Matchers" do
|
|
633
633
|
}
|
634
634
|
end
|
635
635
|
|
636
|
-
it "
|
636
|
+
it "does not match if facet query is different" do
|
637
637
|
Sunspot.search(Post) do
|
638
638
|
facet(:average_rating) do
|
639
639
|
row(1.0..2.0) do
|
@@ -644,7 +644,7 @@ describe "Sunspot Matchers" do
|
|
644
644
|
end
|
645
645
|
end
|
646
646
|
end
|
647
|
-
Sunspot.session.
|
647
|
+
expect(Sunspot.session).to_not have_search_params(:facet) {
|
648
648
|
facet(:average_rating) do
|
649
649
|
row(1.0..2.0) do
|
650
650
|
with(:average_rating, 1.0..2.0)
|
@@ -659,33 +659,33 @@ describe "Sunspot Matchers" do
|
|
659
659
|
end
|
660
660
|
|
661
661
|
describe "boost matcher" do
|
662
|
-
it "
|
662
|
+
it "matches if field boost matches" do
|
663
663
|
Sunspot.search(Post) do
|
664
664
|
keywords 'great pizza' do
|
665
665
|
boost_fields :body => 2.0
|
666
666
|
end
|
667
667
|
end
|
668
|
-
Sunspot.session.
|
668
|
+
expect(Sunspot.session).to have_search_params(:boost) {
|
669
669
|
keywords 'great pizza' do
|
670
670
|
boost_fields :body => 2.0
|
671
671
|
end
|
672
672
|
}
|
673
673
|
end
|
674
674
|
|
675
|
-
it "
|
675
|
+
it "does not match if field boost does not match" do
|
676
676
|
Sunspot.search(Post) do
|
677
677
|
keywords 'great pizza' do
|
678
678
|
boost_fields :body => 2.0
|
679
679
|
end
|
680
680
|
end
|
681
|
-
Sunspot.session.
|
681
|
+
expect(Sunspot.session).to_not have_search_params(:boost) {
|
682
682
|
keywords 'great pizza' do
|
683
683
|
boost_fields :body => 3.0
|
684
684
|
end
|
685
685
|
}
|
686
686
|
end
|
687
687
|
|
688
|
-
it "
|
688
|
+
it "matches if boost query matches" do
|
689
689
|
Sunspot.search(Post) do
|
690
690
|
keywords 'great pizza' do
|
691
691
|
boost(2.0) do
|
@@ -693,7 +693,7 @@ describe "Sunspot Matchers" do
|
|
693
693
|
end
|
694
694
|
end
|
695
695
|
end
|
696
|
-
Sunspot.session.
|
696
|
+
expect(Sunspot.session).to have_search_params(:boost) {
|
697
697
|
keywords 'great pizza' do
|
698
698
|
boost(2.0) do
|
699
699
|
with :blog_id, 4
|
@@ -702,7 +702,7 @@ describe "Sunspot Matchers" do
|
|
702
702
|
}
|
703
703
|
end
|
704
704
|
|
705
|
-
it "
|
705
|
+
it "does not match if boost query does not match" do
|
706
706
|
Sunspot.search(Post) do
|
707
707
|
keywords 'great pizza' do
|
708
708
|
boost(2.0) do
|
@@ -710,7 +710,7 @@ describe "Sunspot Matchers" do
|
|
710
710
|
end
|
711
711
|
end
|
712
712
|
end
|
713
|
-
Sunspot.session.
|
713
|
+
expect(Sunspot.session).to_not have_search_params(:boost) {
|
714
714
|
keywords 'great pizza' do
|
715
715
|
boost(2.0) do
|
716
716
|
with :blog_id, 5
|
@@ -719,26 +719,26 @@ describe "Sunspot Matchers" do
|
|
719
719
|
}
|
720
720
|
end
|
721
721
|
|
722
|
-
it "
|
722
|
+
it "matches if boost function matches" do
|
723
723
|
Sunspot.search(Post) do
|
724
724
|
keywords 'great pizza' do
|
725
725
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
726
726
|
end
|
727
727
|
end
|
728
|
-
Sunspot.session.
|
728
|
+
expect(Sunspot.session).to have_search_params(:boost) {
|
729
729
|
keywords 'great pizza' do
|
730
730
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
731
731
|
end
|
732
732
|
}
|
733
733
|
end
|
734
734
|
|
735
|
-
it "
|
735
|
+
it "does not match if boost function does not match" do
|
736
736
|
Sunspot.search(Post) do
|
737
737
|
keywords 'great pizza' do
|
738
738
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
739
739
|
end
|
740
740
|
end
|
741
|
-
Sunspot.session.
|
741
|
+
expect(Sunspot.session).to_not have_search_params(:boost) {
|
742
742
|
keywords 'great pizza' do
|
743
743
|
boost(function { sum(:average_rating, product(:popularity, 42)) })
|
744
744
|
end
|
@@ -747,19 +747,19 @@ describe "Sunspot Matchers" do
|
|
747
747
|
end
|
748
748
|
|
749
749
|
describe "group matcher" do
|
750
|
-
it "
|
750
|
+
it "matches if grouping a field" do
|
751
751
|
Sunspot.search(Post) do
|
752
752
|
keywords 'great pizza'
|
753
753
|
group :author_name
|
754
754
|
end
|
755
|
-
Sunspot.session.
|
755
|
+
expect(Sunspot.session).to have_search_params(:group, :author_name)
|
756
756
|
end
|
757
757
|
|
758
|
-
it "
|
758
|
+
it "matches if grouping a field" do
|
759
759
|
Sunspot.search(Post) do
|
760
760
|
keywords 'great pizza'
|
761
761
|
end
|
762
|
-
Sunspot.session.
|
762
|
+
expect(Sunspot.session).to_not have_search_params(:group, :author_name)
|
763
763
|
end
|
764
764
|
end
|
765
765
|
|
@@ -772,56 +772,54 @@ describe "Sunspot Matchers" do
|
|
772
772
|
end
|
773
773
|
end
|
774
774
|
|
775
|
-
it "
|
776
|
-
Sunspot.session.
|
775
|
+
it "succeeds if the model is correct" do
|
776
|
+
expect(Sunspot.session).to be_a_search_for(Post)
|
777
777
|
end
|
778
778
|
|
779
|
-
it "
|
780
|
-
Sunspot.session.
|
779
|
+
it "fails if the model is incorrect" do
|
780
|
+
expect(Sunspot.session).to_not be_a_search_for(Blog)
|
781
781
|
end
|
782
782
|
|
783
783
|
describe "when searching for multiple models" do
|
784
|
-
it "
|
784
|
+
it "is true for both" do
|
785
785
|
Sunspot.search([Post, Blog]) do
|
786
786
|
keywords 'great pizza'
|
787
787
|
end
|
788
788
|
|
789
|
-
Sunspot.session.
|
790
|
-
Sunspot.session.
|
791
|
-
Sunspot.session.
|
789
|
+
expect(Sunspot.session).to be_a_search_for(Post)
|
790
|
+
expect(Sunspot.session).to be_a_search_for(Blog)
|
791
|
+
expect(Sunspot.session).to_not be_a_search_for(Person)
|
792
792
|
end
|
793
793
|
end
|
794
794
|
|
795
795
|
describe "with multiple searches" do
|
796
|
-
it "
|
796
|
+
it "allows you to choose the search" do
|
797
797
|
Sunspot.search(Blog) do
|
798
798
|
keywords 'bad pizza'
|
799
799
|
end
|
800
|
-
Sunspot.session.searches.first.
|
801
|
-
Sunspot.session.searches.last.
|
800
|
+
expect(Sunspot.session.searches.first).to be_a_search_for(Post)
|
801
|
+
expect(Sunspot.session.searches.last).to be_a_search_for(Blog)
|
802
802
|
end
|
803
803
|
end
|
804
804
|
end
|
805
805
|
|
806
806
|
describe "have_searchable_field" do
|
807
|
-
|
808
|
-
|
809
|
-
it { should have_searchable_field(:body) }
|
810
|
-
end
|
807
|
+
it "works with instances as well as classes" do
|
808
|
+
expect(Post).to have_searchable_field(:body)
|
811
809
|
end
|
812
810
|
|
813
|
-
it "
|
814
|
-
Post.
|
815
|
-
Post.
|
816
|
-
Post.
|
811
|
+
it "succeeds if the model has the given field" do
|
812
|
+
expect(Post).to have_searchable_field(:body)
|
813
|
+
expect(Post).to have_searchable_field(:author_name)
|
814
|
+
expect(Post).to have_searchable_field(:blog_id)
|
817
815
|
end
|
818
816
|
|
819
|
-
it "
|
820
|
-
Post.
|
817
|
+
it "fails if the model does not have the given field" do
|
818
|
+
expect(Post).to_not have_searchable_field(:potato)
|
821
819
|
end
|
822
820
|
|
823
|
-
it "
|
824
|
-
Person.
|
821
|
+
it "fails if the model does not have any searchable fields" do
|
822
|
+
expect(Person).to_not have_searchable_field(:name)
|
825
823
|
end
|
826
824
|
end
|
827
825
|
end
|
data/sunspot_matchers.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_rubygems_version = ">= 1.3.6"
|
16
16
|
|
17
17
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
-
s.add_development_dependency "rspec", "~> 2.
|
19
|
-
s.add_development_dependency "sunspot", "~> 2.1.
|
18
|
+
s.add_development_dependency "rspec", "~> 2.0"
|
19
|
+
s.add_development_dependency "sunspot", "~> 2.1.1"
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.0
|
4
|
+
version: 2.1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Palermo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sunspot
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.1.
|
47
|
+
version: 2.1.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.1.
|
54
|
+
version: 2.1.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|