sunspot_matchers_testunit 1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +22 -22
- data/lib/sunspot_matchers_testunit/version.rb +1 -1
- data/test/sunspot_matchers_testunit_test.rb +95 -95
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -72,10 +72,10 @@ keywords, with, without, and order_by support wildcard expectations using the `a
|
|
72
72
|
order_by :blog_id, :desc
|
73
73
|
end
|
74
74
|
|
75
|
-
assert_has_search_params Sunspot.session,
|
76
|
-
assert_has_search_params Sunspot.session,
|
77
|
-
assert_has_search_params Sunspot.session,
|
78
|
-
assert_has_no_search_params Sunspot.session,
|
75
|
+
assert_has_search_params Sunspot.session, :with, :blog_id, any_param
|
76
|
+
assert_has_search_params Sunspot.session, :order_by, :blog_id, any_param
|
77
|
+
assert_has_search_params Sunspot.session, :order_by, any_param
|
78
|
+
assert_has_no_search_params Sunspot.session, :order_by, :category_ids, any_param
|
79
79
|
|
80
80
|
### :keywords
|
81
81
|
|
@@ -85,7 +85,7 @@ You can match against a keyword search:
|
|
85
85
|
keywords 'great pizza'
|
86
86
|
end
|
87
87
|
|
88
|
-
assert_has_search_params Sunspot.session,
|
88
|
+
assert_has_search_params Sunspot.session, :keywords, 'great pizza'
|
89
89
|
|
90
90
|
### :with
|
91
91
|
|
@@ -95,7 +95,7 @@ You can match against a with restriction:
|
|
95
95
|
with :author_name, 'Mark Twain'
|
96
96
|
end
|
97
97
|
|
98
|
-
assert_has_search_params Sunspot.session,
|
98
|
+
assert_has_search_params Sunspot.session, :with, :author_name, 'Mark Twain'
|
99
99
|
|
100
100
|
Complex conditions can be matched by using a Proc instead of a value. Be aware that order does matter, not for
|
101
101
|
the actual results that would come out of Solr, but the matcher will fail of the order of `with` restrictions is
|
@@ -108,12 +108,12 @@ different.
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
assert_has_search_params Sunspot.session,
|
111
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
112
112
|
any_of do
|
113
113
|
with :category_ids, 1
|
114
114
|
with :category_ids, 2
|
115
115
|
end
|
116
|
-
}
|
116
|
+
}
|
117
117
|
|
118
118
|
### :without
|
119
119
|
|
@@ -123,7 +123,7 @@ Without is nearly identical to with:
|
|
123
123
|
without :author_name, 'Mark Twain'
|
124
124
|
end
|
125
125
|
|
126
|
-
assert_has_search_params Sunspot.session,
|
126
|
+
assert_has_search_params Sunspot.session, :without, :author_name, 'Mark Twain'
|
127
127
|
|
128
128
|
### :paginate
|
129
129
|
|
@@ -133,7 +133,7 @@ You can also specify only page or per_page, both are not required.
|
|
133
133
|
paginate :page => 3, :per_page => 15
|
134
134
|
end
|
135
135
|
|
136
|
-
assert_has_search_params Sunspot.session,
|
136
|
+
assert_has_search_params Sunspot.session, :paginate, :page => 3, :per_page => 15
|
137
137
|
|
138
138
|
### :order_by
|
139
139
|
|
@@ -143,7 +143,7 @@ Expectations on multiple orderings are supported using using the Proc format men
|
|
143
143
|
order_by :published_at, :desc
|
144
144
|
end
|
145
145
|
|
146
|
-
assert_has_search_params Sunspot.session,
|
146
|
+
assert_has_search_params Sunspot.session, :order_by, :published_at, :desc
|
147
147
|
|
148
148
|
### :facet
|
149
149
|
|
@@ -153,7 +153,7 @@ Standard faceting expectation:
|
|
153
153
|
facet :category_ids
|
154
154
|
end
|
155
155
|
|
156
|
-
assert_has_search_params Sunspot.session,
|
156
|
+
assert_has_search_params Sunspot.session, :facet, :category_ids
|
157
157
|
|
158
158
|
Faceting where a query is excluded:
|
159
159
|
|
@@ -162,10 +162,10 @@ Faceting where a query is excluded:
|
|
162
162
|
facet(:category_ids, :exclude => category_filter)
|
163
163
|
end
|
164
164
|
|
165
|
-
assert_has_search_params Sunspot.session,
|
165
|
+
assert_has_search_params Sunspot.session, :facet, Proc.new {
|
166
166
|
category_filter = with(:category_ids, 2)
|
167
167
|
facet(:category_ids, :exclude => category_filter)
|
168
|
-
}
|
168
|
+
}
|
169
169
|
|
170
170
|
Query faceting:
|
171
171
|
|
@@ -180,7 +180,7 @@ Query faceting:
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
assert_has_search_params Sunspot.session,
|
183
|
+
assert_has_search_params Sunspot.session, :facet, Proc.new {
|
184
184
|
facet(:average_rating) do
|
185
185
|
row(1.0..2.0) do
|
186
186
|
with(:average_rating, 1.0..2.0)
|
@@ -189,7 +189,7 @@ Query faceting:
|
|
189
189
|
with(:average_rating, 2.0..3.0)
|
190
190
|
end
|
191
191
|
end
|
192
|
-
}
|
192
|
+
}
|
193
193
|
|
194
194
|
### :boost
|
195
195
|
|
@@ -201,11 +201,11 @@ Field boost matching:
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
assert_has_search_params Sunspot.session,
|
204
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
205
205
|
keywords 'great pizza' do
|
206
206
|
boost_fields :body => 2.0
|
207
207
|
end
|
208
|
-
}
|
208
|
+
}
|
209
209
|
|
210
210
|
Boost query matching:
|
211
211
|
|
@@ -217,13 +217,13 @@ Boost query matching:
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
220
|
-
assert_has_search_params Sunspot.session,
|
220
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
221
221
|
keywords 'great pizza' do
|
222
222
|
boost(2.0) do
|
223
223
|
with :blog_id, 4
|
224
224
|
end
|
225
225
|
end
|
226
|
-
}
|
226
|
+
}
|
227
227
|
|
228
228
|
Boost function matching:
|
229
229
|
|
@@ -233,8 +233,8 @@ Boost function matching:
|
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
236
|
-
assert_has_search_params Sunspot.session,
|
236
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
237
237
|
keywords 'great pizza' do
|
238
238
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
239
239
|
end
|
240
|
-
}
|
240
|
+
}
|
@@ -36,8 +36,8 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
36
36
|
Sunspot.search(Blog) do
|
37
37
|
keywords 'bad pizza'
|
38
38
|
end
|
39
|
-
assert_has_search_params Sunspot.session.searches.first,
|
40
|
-
assert_has_search_params Sunspot.session.searches.last,
|
39
|
+
assert_has_search_params Sunspot.session.searches.first, :keywords, 'great pizza'
|
40
|
+
assert_has_search_params Sunspot.session.searches.last, :keywords, 'bad pizza'
|
41
41
|
end
|
42
42
|
|
43
43
|
# should allow you to specify your search on multiple models
|
@@ -45,21 +45,21 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
45
45
|
Sunspot.search([ Post, Blog ]) do
|
46
46
|
keywords 'great pizza'
|
47
47
|
end
|
48
|
-
assert_has_search_params Sunspot.session,
|
48
|
+
assert_has_search_params Sunspot.session, :keywords, 'great pizza'
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_match_keywords
|
52
52
|
Sunspot.search(Post) do
|
53
53
|
keywords 'great pizza'
|
54
54
|
end
|
55
|
-
assert_has_search_params Sunspot.session,
|
55
|
+
assert_has_search_params Sunspot.session, :keywords, 'great pizza'
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_match_keywords_nomatch
|
59
59
|
Sunspot.search(Post) do
|
60
60
|
keywords 'terrible pizza'
|
61
61
|
end
|
62
|
-
assert_has_no_search_params Sunspot.session,
|
62
|
+
assert_has_no_search_params Sunspot.session, :keywords, 'great pizza'
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_match_multiple_keywords
|
@@ -68,38 +68,38 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
68
68
|
keywords 'terrible pizza'
|
69
69
|
end
|
70
70
|
|
71
|
-
assert_has_search_params Sunspot.session,
|
71
|
+
assert_has_search_params Sunspot.session, :keywords, Proc.new {
|
72
72
|
keywords 'great pizza'
|
73
73
|
keywords 'terrible pizza'
|
74
|
-
}
|
74
|
+
}
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_allow_any_match_keyword
|
78
78
|
Sunspot.search(Post) do
|
79
79
|
keywords 'great pizza'
|
80
80
|
end
|
81
|
-
assert_has_search_params Sunspot.session,
|
81
|
+
assert_has_search_params Sunspot.session, :keywords, any_param
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_allow_any_match_keyword_negative
|
85
85
|
Sunspot.search(Post) do
|
86
86
|
with :blog_id, 4
|
87
87
|
end
|
88
|
-
assert_has_no_search_params Sunspot.session,
|
88
|
+
assert_has_no_search_params Sunspot.session, :keywords, any_param
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_with_matcher_matches
|
92
92
|
Sunspot.search(Post) do
|
93
93
|
with :author_name, 'Mark Twain'
|
94
94
|
end
|
95
|
-
assert_has_search_params Sunspot.session,
|
95
|
+
assert_has_search_params Sunspot.session, :with, :author_name, 'Mark Twain'
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_with_matcher_doesnt_match_search
|
99
99
|
Sunspot.search(Post) do
|
100
100
|
with :author_name, 'Mark Twain'
|
101
101
|
end
|
102
|
-
assert_has_no_search_params Sunspot.session,
|
102
|
+
assert_has_no_search_params Sunspot.session, :with, :author_name, 'John Twain'
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_with_matcher_matches_multiple_with
|
@@ -107,46 +107,46 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
107
107
|
with :author_name, 'Mark Twain'
|
108
108
|
with :author_name, 'John Twain'
|
109
109
|
end
|
110
|
-
assert_has_search_params Sunspot.session,
|
110
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
111
111
|
with :author_name, 'Mark Twain'
|
112
112
|
with :author_name, 'John Twain'
|
113
|
-
}
|
113
|
+
}
|
114
114
|
end
|
115
115
|
|
116
116
|
def test_with_matcher_matches_greater_than
|
117
117
|
Sunspot.search(Post) do
|
118
118
|
with(:category_ids).greater_than(1)
|
119
119
|
end
|
120
|
-
assert_has_search_params Sunspot.session,
|
120
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
121
121
|
with(:category_ids).greater_than(1)
|
122
|
-
}
|
122
|
+
}
|
123
123
|
end
|
124
124
|
|
125
125
|
def test_with_matcher_matches_less_than
|
126
126
|
Sunspot.search(Post) do
|
127
127
|
with(:category_ids).less_than(1)
|
128
128
|
end
|
129
|
-
assert_has_search_params Sunspot.session,
|
129
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
130
130
|
with(:category_ids).less_than(1)
|
131
|
-
}
|
131
|
+
}
|
132
132
|
end
|
133
133
|
|
134
134
|
def test_with_matcher_matches_range
|
135
135
|
Sunspot.search(Post) do
|
136
136
|
with :category_ids, 1..3
|
137
137
|
end
|
138
|
-
assert_has_search_params Sunspot.session,
|
138
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
139
139
|
with :category_ids, 1..3
|
140
|
-
}
|
140
|
+
}
|
141
141
|
end
|
142
142
|
|
143
143
|
def test_with_matcher_matches_any_of
|
144
144
|
Sunspot.search(Post) do
|
145
145
|
with(:category_ids).any_of [ 1, 2 ]
|
146
146
|
end
|
147
|
-
assert_has_search_params Sunspot.session,
|
147
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
148
148
|
with(:category_ids).any_of [ 1, 2 ]
|
149
|
-
}
|
149
|
+
}
|
150
150
|
end
|
151
151
|
|
152
152
|
def test_with_matcher_matches_any_of_multiline
|
@@ -156,12 +156,12 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
156
156
|
with :category_ids, 2
|
157
157
|
end
|
158
158
|
end
|
159
|
-
assert_has_search_params Sunspot.session,
|
159
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
160
160
|
any_of do
|
161
161
|
with :category_ids, 1
|
162
162
|
with :category_ids, 2
|
163
163
|
end
|
164
|
-
}
|
164
|
+
}
|
165
165
|
end
|
166
166
|
|
167
167
|
def test_with_matcher_matches_any_of_and_all_of
|
@@ -174,7 +174,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
177
|
-
assert_has_search_params Sunspot.session,
|
177
|
+
assert_has_search_params Sunspot.session, :with, Proc.new {
|
178
178
|
any_of do
|
179
179
|
with :category_ids, 1
|
180
180
|
all_of do
|
@@ -182,28 +182,28 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
182
182
|
with :category_ids, 3
|
183
183
|
end
|
184
184
|
end
|
185
|
-
}
|
185
|
+
}
|
186
186
|
end
|
187
187
|
|
188
188
|
def test_with_matcher_matches_any_param_match
|
189
189
|
Sunspot.search(Post) do
|
190
190
|
with :blog_id, 4
|
191
191
|
end
|
192
|
-
assert_has_search_params Sunspot.session,
|
192
|
+
assert_has_search_params Sunspot.session, :with, :blog_id, any_param
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_with_matcher_matches_any_param_negative_no_with
|
196
196
|
Sunspot.search(Post) do
|
197
197
|
keywords 'great pizza'
|
198
198
|
end
|
199
|
-
assert_has_no_search_params Sunspot.session,
|
199
|
+
assert_has_no_search_params Sunspot.session, :with, :blog_id, any_param
|
200
200
|
end
|
201
201
|
|
202
202
|
def test_with_matcher_matches_any_param_negative_diff_field
|
203
203
|
Sunspot.search(Post) do
|
204
204
|
with :category_ids, 7
|
205
205
|
end
|
206
|
-
assert_has_no_search_params Sunspot.session,
|
206
|
+
assert_has_no_search_params Sunspot.session, :with, :blog_id, any_param
|
207
207
|
end
|
208
208
|
|
209
209
|
# 'without' matcher
|
@@ -212,21 +212,21 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
212
212
|
Sunspot.search(Post) do
|
213
213
|
without :author_name, 'Mark Twain'
|
214
214
|
end
|
215
|
-
assert_has_search_params Sunspot.session,
|
215
|
+
assert_has_search_params Sunspot.session, :without, :author_name, 'Mark Twain'
|
216
216
|
end
|
217
217
|
|
218
218
|
def test_without_matcher_doesnt_match_search
|
219
219
|
Sunspot.search(Post) do
|
220
220
|
without :author_name, 'Mark Twain'
|
221
221
|
end
|
222
|
-
assert_has_no_search_params Sunspot.session,
|
222
|
+
assert_has_no_search_params Sunspot.session, :without, :author_name, 'John Twain'
|
223
223
|
end
|
224
224
|
|
225
225
|
def test_without_matcher_doesnt_match_with_search
|
226
226
|
Sunspot.search(Post) do
|
227
227
|
with :author_name, 'Mark Twain'
|
228
228
|
end
|
229
|
-
assert_has_no_search_params Sunspot.session,
|
229
|
+
assert_has_no_search_params Sunspot.session, :without, :author_name, 'Mark Twain'
|
230
230
|
end
|
231
231
|
|
232
232
|
def test_without_matcher_matches_multiple_with
|
@@ -234,46 +234,46 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
234
234
|
without :author_name, 'Mark Twain'
|
235
235
|
without :author_name, 'John Twain'
|
236
236
|
end
|
237
|
-
assert_has_search_params Sunspot.session,
|
237
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
238
238
|
without :author_name, 'Mark Twain'
|
239
239
|
without :author_name, 'John Twain'
|
240
|
-
}
|
240
|
+
}
|
241
241
|
end
|
242
242
|
|
243
243
|
def test_without_matcher_matches_greater_than
|
244
244
|
Sunspot.search(Post) do
|
245
245
|
without(:category_ids).greater_than(1)
|
246
246
|
end
|
247
|
-
assert_has_search_params Sunspot.session,
|
247
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
248
248
|
without(:category_ids).greater_than(1)
|
249
|
-
}
|
249
|
+
}
|
250
250
|
end
|
251
251
|
|
252
252
|
def test_without_matcher_matches_less_than
|
253
253
|
Sunspot.search(Post) do
|
254
254
|
without(:category_ids).less_than(1)
|
255
255
|
end
|
256
|
-
assert_has_search_params Sunspot.session,
|
256
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
257
257
|
without(:category_ids).less_than(1)
|
258
|
-
}
|
258
|
+
}
|
259
259
|
end
|
260
260
|
|
261
261
|
def test_without_matcher_matches_range
|
262
262
|
Sunspot.search(Post) do
|
263
263
|
without :category_ids, 1..3
|
264
264
|
end
|
265
|
-
assert_has_search_params Sunspot.session,
|
265
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
266
266
|
without :category_ids, 1..3
|
267
|
-
}
|
267
|
+
}
|
268
268
|
end
|
269
269
|
|
270
270
|
def test_without_matcher_matches_any_of
|
271
271
|
Sunspot.search(Post) do
|
272
272
|
without(:category_ids).any_of [ 1, 2 ]
|
273
273
|
end
|
274
|
-
assert_has_search_params Sunspot.session,
|
274
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
275
275
|
without(:category_ids).any_of [ 1, 2 ]
|
276
|
-
}
|
276
|
+
}
|
277
277
|
end
|
278
278
|
|
279
279
|
def test_without_matcher_matches_any_of_multiline
|
@@ -283,12 +283,12 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
283
283
|
without :category_ids, 2
|
284
284
|
end
|
285
285
|
end
|
286
|
-
assert_has_search_params Sunspot.session,
|
286
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
287
287
|
any_of do
|
288
288
|
without :category_ids, 1
|
289
289
|
without :category_ids, 2
|
290
290
|
end
|
291
|
-
}
|
291
|
+
}
|
292
292
|
end
|
293
293
|
|
294
294
|
def test_without_matcher_matches_any_of_and_all_of
|
@@ -301,7 +301,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
301
301
|
end
|
302
302
|
end
|
303
303
|
end
|
304
|
-
assert_has_search_params Sunspot.session,
|
304
|
+
assert_has_search_params Sunspot.session, :without, Proc.new {
|
305
305
|
any_of do
|
306
306
|
without :category_ids, 1
|
307
307
|
all_of do
|
@@ -309,28 +309,28 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
309
309
|
without :category_ids, 3
|
310
310
|
end
|
311
311
|
end
|
312
|
-
}
|
312
|
+
}
|
313
313
|
end
|
314
314
|
|
315
315
|
def test_without_matcher_matches_any_param_match
|
316
316
|
Sunspot.search(Post) do
|
317
317
|
without :blog_id, 4
|
318
318
|
end
|
319
|
-
assert_has_search_params Sunspot.session,
|
319
|
+
assert_has_search_params Sunspot.session, :without, :blog_id, any_param
|
320
320
|
end
|
321
321
|
|
322
322
|
def test_without_matcher_matches_any_param_negative_no_without
|
323
323
|
Sunspot.search(Post) do
|
324
324
|
keywords 'great pizza'
|
325
325
|
end
|
326
|
-
assert_has_no_search_params Sunspot.session,
|
326
|
+
assert_has_no_search_params Sunspot.session, :without, :blog_id, any_param
|
327
327
|
end
|
328
328
|
|
329
329
|
def test_without_matcher_matches_any_param_negative_diff_field
|
330
330
|
Sunspot.search(Post) do
|
331
331
|
without :category_ids, 7
|
332
332
|
end
|
333
|
-
assert_has_no_search_params Sunspot.session,
|
333
|
+
assert_has_no_search_params Sunspot.session, :without, :blog_id, any_param
|
334
334
|
end
|
335
335
|
|
336
336
|
# 'paginate' matcher
|
@@ -339,49 +339,49 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
339
339
|
Sunspot.search(Post) do
|
340
340
|
paginate :page => 3, :per_page => 15
|
341
341
|
end
|
342
|
-
assert_has_search_params Sunspot.session,
|
342
|
+
assert_has_search_params Sunspot.session, :paginate, { :page => 3, :per_page => 15 }
|
343
343
|
end
|
344
344
|
|
345
345
|
def test_paginate_matcher_matches_page_only
|
346
346
|
Sunspot.search(Post) do
|
347
347
|
paginate :page => 3
|
348
348
|
end
|
349
|
-
assert_has_search_params Sunspot.session,
|
349
|
+
assert_has_search_params Sunspot.session, :paginate, { :page => 3 }
|
350
350
|
end
|
351
351
|
|
352
352
|
def test_paginate_matcher_matches_per_page_only
|
353
353
|
Sunspot.search(Post) do
|
354
354
|
paginate :per_page => 15
|
355
355
|
end
|
356
|
-
assert_has_search_params Sunspot.session,
|
356
|
+
assert_has_search_params Sunspot.session, :paginate, { :per_page => 15 }
|
357
357
|
end
|
358
358
|
|
359
359
|
def test_paginate_matcher_doesnt_match_without_per_page
|
360
360
|
Sunspot.search(Post) do
|
361
361
|
paginate :page => 3, :per_page => 30
|
362
362
|
end
|
363
|
-
assert_has_no_search_params Sunspot.session,
|
363
|
+
assert_has_no_search_params Sunspot.session, :paginate, { :page => 3, :per_page => 15 }
|
364
364
|
end
|
365
365
|
|
366
366
|
def test_paginate_matcher_doesnt_match_without_page
|
367
367
|
Sunspot.search(Post) do
|
368
368
|
paginate :page => 5, :per_page => 15
|
369
369
|
end
|
370
|
-
assert_has_no_search_params Sunspot.session,
|
370
|
+
assert_has_no_search_params Sunspot.session, :paginate, { :page => 3, :per_page => 15 }
|
371
371
|
end
|
372
372
|
|
373
373
|
def test_order_by_matcher_matches
|
374
374
|
Sunspot.search(Post) do
|
375
375
|
order_by :published_at, :desc
|
376
376
|
end
|
377
|
-
assert_has_search_params Sunspot.session,
|
377
|
+
assert_has_search_params Sunspot.session, :order_by, :published_at, :desc
|
378
378
|
end
|
379
379
|
|
380
380
|
def test_order_by_matcher_doesnt_match
|
381
381
|
Sunspot.search(Post) do
|
382
382
|
order_by :published_at, :asc
|
383
383
|
end
|
384
|
-
assert_has_no_search_params Sunspot.session,
|
384
|
+
assert_has_no_search_params Sunspot.session, :order_by, :published_at, :desc
|
385
385
|
end
|
386
386
|
|
387
387
|
def test_order_by_matcher_matches_multiple
|
@@ -389,10 +389,10 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
389
389
|
order_by :published_at, :asc
|
390
390
|
order_by :average_rating, :asc
|
391
391
|
end
|
392
|
-
assert_has_search_params Sunspot.session,
|
392
|
+
assert_has_search_params Sunspot.session, :order_by, Proc.new {
|
393
393
|
order_by :published_at, :asc
|
394
394
|
order_by :average_rating, :asc
|
395
|
-
}
|
395
|
+
}
|
396
396
|
end
|
397
397
|
|
398
398
|
def test_order_by_matcher_doesnt_match_multiple_reversed
|
@@ -400,10 +400,10 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
400
400
|
order_by :average_rating, :asc
|
401
401
|
order_by :published_at, :asc
|
402
402
|
end
|
403
|
-
assert_has_no_search_params Sunspot.session,
|
403
|
+
assert_has_no_search_params Sunspot.session, :order_by, Proc.new {
|
404
404
|
order_by :published_at, :asc
|
405
405
|
order_by :average_rating, :asc
|
406
|
-
}
|
406
|
+
}
|
407
407
|
end
|
408
408
|
|
409
409
|
def test_order_by_matcher_matches_on_random
|
@@ -411,10 +411,10 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
411
411
|
order_by :average_rating, :asc
|
412
412
|
order_by :random
|
413
413
|
end
|
414
|
-
assert_has_search_params Sunspot.session,
|
414
|
+
assert_has_search_params Sunspot.session, :order_by, Proc.new {
|
415
415
|
order_by :average_rating, :asc
|
416
416
|
order_by :random
|
417
|
-
}
|
417
|
+
}
|
418
418
|
end
|
419
419
|
|
420
420
|
def test_order_by_matcher_doesnt_match_without_random
|
@@ -422,9 +422,9 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
422
422
|
order_by :average_rating, :asc
|
423
423
|
order_by :random
|
424
424
|
end
|
425
|
-
assert_has_no_search_params Sunspot.session,
|
425
|
+
assert_has_no_search_params Sunspot.session, :order_by, Proc.new {
|
426
426
|
order_by :average_rating, :asc
|
427
|
-
}
|
427
|
+
}
|
428
428
|
end
|
429
429
|
|
430
430
|
def test_order_by_matcher_with_score
|
@@ -432,10 +432,10 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
432
432
|
order_by :average_rating, :asc
|
433
433
|
order_by :score
|
434
434
|
end
|
435
|
-
assert_has_search_params Sunspot.session,
|
435
|
+
assert_has_search_params Sunspot.session, :order_by, Proc.new {
|
436
436
|
order_by :average_rating, :asc
|
437
437
|
order_by :score
|
438
|
-
}
|
438
|
+
}
|
439
439
|
end
|
440
440
|
|
441
441
|
def test_order_by_matcher_doesnt_match_without_score
|
@@ -443,51 +443,51 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
443
443
|
order_by :average_rating, :asc
|
444
444
|
order_by :score
|
445
445
|
end
|
446
|
-
assert_has_no_search_params Sunspot.session,
|
446
|
+
assert_has_no_search_params Sunspot.session, :order_by, Proc.new {
|
447
447
|
order_by :average_rating, :asc
|
448
|
-
}
|
448
|
+
}
|
449
449
|
end
|
450
450
|
|
451
451
|
def test_order_by_matcher_respects_any_param_on_direction
|
452
452
|
Sunspot.search(Post) do
|
453
453
|
order_by :average_rating, :asc
|
454
454
|
end
|
455
|
-
assert_has_search_params Sunspot.session,
|
455
|
+
assert_has_search_params Sunspot.session, :order_by, :average_rating, any_param
|
456
456
|
end
|
457
457
|
|
458
458
|
def test_order_by_matcher_respects_any_param_on_field
|
459
459
|
Sunspot.search(Post) do
|
460
460
|
order_by :average_rating, :asc
|
461
461
|
end
|
462
|
-
assert_has_search_params Sunspot.session,
|
462
|
+
assert_has_search_params Sunspot.session, :order_by, any_param
|
463
463
|
end
|
464
464
|
|
465
465
|
def test_order_by_matcher_doesnt_respect_any_param_on_direction
|
466
466
|
Sunspot.search(Post) do
|
467
467
|
order_by :score
|
468
468
|
end
|
469
|
-
assert_has_no_search_params Sunspot.session,
|
469
|
+
assert_has_no_search_params Sunspot.session, :order_by, :average_rating, any_param
|
470
470
|
end
|
471
471
|
|
472
472
|
def test_order_by_matcher_doesnt_respect_any_param_on_field
|
473
473
|
Sunspot.search(Post) do
|
474
474
|
keywords 'great pizza'
|
475
475
|
end
|
476
|
-
assert_has_no_search_params Sunspot.session,
|
476
|
+
assert_has_no_search_params Sunspot.session, :order_by, any_param
|
477
477
|
end
|
478
478
|
|
479
479
|
def test_order_by_matcher_respects_any_param_on_field_and_dir
|
480
480
|
Sunspot.search(Post) do
|
481
481
|
order_by :score, :desc
|
482
482
|
end
|
483
|
-
assert_has_search_params Sunspot.session,
|
483
|
+
assert_has_search_params Sunspot.session, :order_by, any_param, any_param
|
484
484
|
end
|
485
485
|
|
486
486
|
def test_order_by_matcher_respects_any_param_on_field_and_dir
|
487
487
|
Sunspot.search(Post) do
|
488
488
|
keywords 'great pizza'
|
489
489
|
end
|
490
|
-
assert_has_no_search_params Sunspot.session,
|
490
|
+
assert_has_no_search_params Sunspot.session, :order_by, any_param, any_param
|
491
491
|
end
|
492
492
|
|
493
493
|
# 'facet' matcher
|
@@ -496,14 +496,14 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
496
496
|
Sunspot.search(Post) do
|
497
497
|
facet :category_ids
|
498
498
|
end
|
499
|
-
assert_has_search_params Sunspot.session,
|
499
|
+
assert_has_search_params Sunspot.session, :facet, :category_ids
|
500
500
|
end
|
501
501
|
|
502
502
|
def test_facet_matcher_doesnt_match_nonexistent_facet
|
503
503
|
Sunspot.search(Post) do
|
504
504
|
paginate :page => 5, :per_page => 15
|
505
505
|
end
|
506
|
-
assert_has_no_search_params Sunspot.session,
|
506
|
+
assert_has_no_search_params Sunspot.session, :facet, :category_ids
|
507
507
|
end
|
508
508
|
|
509
509
|
def test_facet_matcher_matches_excluding_filters
|
@@ -511,10 +511,10 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
511
511
|
category_filter = with(:category_ids, 2)
|
512
512
|
facet(:category_ids, :exclude => category_filter)
|
513
513
|
end
|
514
|
-
assert_has_search_params Sunspot.session,
|
514
|
+
assert_has_search_params Sunspot.session, :facet, Proc.new {
|
515
515
|
category_filter = with(:category_ids, 2)
|
516
516
|
facet(:category_ids, :exclude => category_filter)
|
517
|
-
}
|
517
|
+
}
|
518
518
|
end
|
519
519
|
|
520
520
|
def test_query_facet_matcher_matches
|
@@ -528,7 +528,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
528
528
|
end
|
529
529
|
end
|
530
530
|
end
|
531
|
-
assert_has_search_params Sunspot.session,
|
531
|
+
assert_has_search_params Sunspot.session, :facet, Proc.new {
|
532
532
|
facet(:average_rating) do
|
533
533
|
row(1.0..2.0) do
|
534
534
|
with(:average_rating, 1.0..2.0)
|
@@ -537,7 +537,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
537
537
|
with(:average_rating, 2.0..3.0)
|
538
538
|
end
|
539
539
|
end
|
540
|
-
}
|
540
|
+
}
|
541
541
|
end
|
542
542
|
|
543
543
|
def test_query_facet_matcher_doesnt_match_missing_facet
|
@@ -548,7 +548,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
548
548
|
end
|
549
549
|
end
|
550
550
|
end
|
551
|
-
assert_has_no_search_params Sunspot.session,
|
551
|
+
assert_has_no_search_params Sunspot.session, :facet, Proc.new {
|
552
552
|
facet(:average_rating) do
|
553
553
|
row(1.0..2.0) do
|
554
554
|
with(:average_rating, 1.0..2.0)
|
@@ -557,7 +557,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
557
557
|
with(:average_rating, 2.0..3.0)
|
558
558
|
end
|
559
559
|
end
|
560
|
-
}
|
560
|
+
}
|
561
561
|
end
|
562
562
|
|
563
563
|
def test_query_facet_matcher_doesnt_match_different_query
|
@@ -571,7 +571,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
571
571
|
end
|
572
572
|
end
|
573
573
|
end
|
574
|
-
assert_has_no_search_params Sunspot.session,
|
574
|
+
assert_has_no_search_params Sunspot.session, :facet, Proc.new {
|
575
575
|
facet(:average_rating) do
|
576
576
|
row(1.0..2.0) do
|
577
577
|
with(:average_rating, 1.0..2.0)
|
@@ -580,7 +580,7 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
580
580
|
with(:average_rating, 2.0..4.0)
|
581
581
|
end
|
582
582
|
end
|
583
|
-
}
|
583
|
+
}
|
584
584
|
end
|
585
585
|
|
586
586
|
# 'boost' matcher
|
@@ -591,11 +591,11 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
591
591
|
boost_fields :body => 2.0
|
592
592
|
end
|
593
593
|
end
|
594
|
-
assert_has_search_params Sunspot.session,
|
594
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
595
595
|
keywords 'great pizza' do
|
596
596
|
boost_fields :body => 2.0
|
597
597
|
end
|
598
|
-
}
|
598
|
+
}
|
599
599
|
end
|
600
600
|
|
601
601
|
def test_boost_matcher_doesnt_match_on_boost_mismatch
|
@@ -604,11 +604,11 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
604
604
|
boost_fields :body => 2.0
|
605
605
|
end
|
606
606
|
end
|
607
|
-
assert_has_no_search_params Sunspot.session,
|
607
|
+
assert_has_no_search_params Sunspot.session, :boost, Proc.new {
|
608
608
|
keywords 'great pizza' do
|
609
609
|
boost_fields :body => 3.0
|
610
610
|
end
|
611
|
-
}
|
611
|
+
}
|
612
612
|
end
|
613
613
|
|
614
614
|
def test_boost_matcher_matches_boost_query
|
@@ -619,13 +619,13 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
619
619
|
end
|
620
620
|
end
|
621
621
|
end
|
622
|
-
assert_has_search_params Sunspot.session,
|
622
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
623
623
|
keywords 'great pizza' do
|
624
624
|
boost(2.0) do
|
625
625
|
with :blog_id, 4
|
626
626
|
end
|
627
627
|
end
|
628
|
-
}
|
628
|
+
}
|
629
629
|
end
|
630
630
|
|
631
631
|
def test_boost_matcher_doesnt_match_on_boost_query_mismatch
|
@@ -636,13 +636,13 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
636
636
|
end
|
637
637
|
end
|
638
638
|
end
|
639
|
-
assert_has_no_search_params Sunspot.session,
|
639
|
+
assert_has_no_search_params Sunspot.session, :boost, Proc.new {
|
640
640
|
keywords 'great pizza' do
|
641
641
|
boost(2.0) do
|
642
642
|
with :blog_id, 5
|
643
643
|
end
|
644
644
|
end
|
645
|
-
}
|
645
|
+
}
|
646
646
|
end
|
647
647
|
|
648
648
|
def test_boost_matcher_matches_boost_function
|
@@ -651,11 +651,11 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
651
651
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
652
652
|
end
|
653
653
|
end
|
654
|
-
assert_has_search_params Sunspot.session,
|
654
|
+
assert_has_search_params Sunspot.session, :boost, Proc.new {
|
655
655
|
keywords 'great pizza' do
|
656
656
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
657
657
|
end
|
658
|
-
}
|
658
|
+
}
|
659
659
|
end
|
660
660
|
|
661
661
|
def test_boost_matcher_doesnt_match_on_boost_function_mismatch
|
@@ -664,11 +664,11 @@ class SunspotMatchersTestunitTest < Test::Unit::TestCase
|
|
664
664
|
boost(function { sum(:average_rating, product(:popularity, 10)) })
|
665
665
|
end
|
666
666
|
end
|
667
|
-
assert_has_no_search_params Sunspot.session,
|
667
|
+
assert_has_no_search_params Sunspot.session, :boost, Proc.new {
|
668
668
|
keywords 'great pizza' do
|
669
669
|
boost(function { sum(:average_rating, product(:popularity, 42)) })
|
670
670
|
end
|
671
|
-
}
|
671
|
+
}
|
672
672
|
end
|
673
673
|
|
674
674
|
# 'be a search for'
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_matchers_testunit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Christine Yen
|