sphinx 0.9.10 → 0.9.10.2043

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,850 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Sphinx::Client, 'disconnected' do
4
+ before :each do
5
+ @sphinx = Sphinx::Client.new
6
+ end
7
+
8
+ context 'in SetServer method' do
9
+ it 'should raise an error when host is not String' do
10
+ expect {
11
+ @sphinx.SetServer(1234, 1234)
12
+ }.to raise_error(ArgumentError)
13
+ end
14
+
15
+ it 'should raise an error when port is not Integer' do
16
+ expect {
17
+ @sphinx.SetServer('hello', 'world')
18
+ }.to raise_error(ArgumentError)
19
+ end
20
+ end
21
+
22
+ context 'in SetConnectTimeout method' do
23
+ it 'should raise an error when timeout is not Integer' do
24
+ expect {
25
+ @sphinx.SetConnectTimeout('timeout')
26
+ }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'should raise an error when retries is not Integer' do
30
+ expect {
31
+ @sphinx.SetConnectTimeout(1, 'retries')
32
+ }.to raise_error(ArgumentError)
33
+ end
34
+
35
+ it 'should raise an error when retries is less than 1' do
36
+ expect {
37
+ @sphinx.SetConnectTimeout(1, 0)
38
+ }.to raise_error(ArgumentError)
39
+
40
+ expect {
41
+ @sphinx.SetConnectTimeout(1, -1)
42
+ }.to raise_error(ArgumentError)
43
+ end
44
+ end
45
+
46
+ context 'in SetRequestTimeout method' do
47
+ it 'should raise an error when timeout is not Integer' do
48
+ expect {
49
+ @sphinx.SetRequestTimeout('timeout')
50
+ }.to raise_error(ArgumentError)
51
+ end
52
+
53
+ it 'should raise an error when retries is not Integer' do
54
+ expect {
55
+ @sphinx.SetRequestTimeout(1, 'retries')
56
+ }.to raise_error(ArgumentError)
57
+ end
58
+
59
+ it 'should raise an error when retries is less than 1' do
60
+ expect {
61
+ @sphinx.SetRequestTimeout(1, 0)
62
+ }.to raise_error(ArgumentError)
63
+
64
+ expect {
65
+ @sphinx.SetRequestTimeout(1, -1)
66
+ }.to raise_error(ArgumentError)
67
+ end
68
+ end
69
+
70
+ context 'in SetLimits method' do
71
+ it 'should raise an error when offset is not Integer' do
72
+ expect {
73
+ @sphinx.SetLimits('offset', 1, 0, 0)
74
+ }.to raise_error(ArgumentError)
75
+ end
76
+
77
+ it 'should raise an error when limit is not Integer' do
78
+ expect {
79
+ @sphinx.SetLimits(0, 'limit', 0, 0)
80
+ }.to raise_error(ArgumentError)
81
+ end
82
+
83
+ it 'should raise an error when max is not Integer' do
84
+ expect {
85
+ @sphinx.SetLimits(0, 1, 'max', 0)
86
+ }.to raise_error(ArgumentError)
87
+ end
88
+
89
+ it 'should raise an error when cutoff is not Integer' do
90
+ expect {
91
+ @sphinx.SetLimits(0, 1, 0, 'cutoff')
92
+ }.to raise_error(ArgumentError)
93
+ end
94
+
95
+ it 'should raise an error when offset is less than zero' do
96
+ expect {
97
+ @sphinx.SetLimits(-1, 1, 0, 0)
98
+ }.to raise_error(ArgumentError)
99
+ end
100
+
101
+ it 'should raise an error when limit is less than 1' do
102
+ expect {
103
+ @sphinx.SetLimits(0, 0, 0, 0)
104
+ }.to raise_error(ArgumentError)
105
+ end
106
+
107
+ it 'should raise an error when max is less than zero' do
108
+ expect {
109
+ @sphinx.SetLimits(0, 1, -1, 0)
110
+ }.to raise_error(ArgumentError)
111
+ end
112
+
113
+ it 'should raise an error when cutoff is less than zero' do
114
+ expect {
115
+ @sphinx.SetLimits(0, 1, 0, -1)
116
+ }.to raise_error(ArgumentError)
117
+ end
118
+ end
119
+
120
+ context 'in SetMaxQueryTime method' do
121
+ it 'should raise an error when max is not Integer' do
122
+ expect {
123
+ @sphinx.SetMaxQueryTime('max')
124
+ }.to raise_error(ArgumentError)
125
+ end
126
+
127
+
128
+ it 'should raise an error when max is less than zero' do
129
+ expect {
130
+ @sphinx.SetMaxQueryTime(-1)
131
+ }.to raise_error(ArgumentError)
132
+ end
133
+ end
134
+
135
+ context 'in SetMatchMode method' do
136
+ it 'should raise an error when mode is not Integer, String or Symbol' do
137
+ expect {
138
+ @sphinx.SetMatchMode([])
139
+ }.to raise_error(ArgumentError)
140
+ end
141
+
142
+ it 'should raise an error when mode is invalid' do
143
+ expect {
144
+ @sphinx.SetMatchMode('invalid')
145
+ }.to raise_error(ArgumentError)
146
+
147
+ expect {
148
+ @sphinx.SetMatchMode(:invalid)
149
+ }.to raise_error(ArgumentError)
150
+
151
+ expect {
152
+ @sphinx.SetMatchMode(100)
153
+ }.to raise_error(ArgumentError)
154
+ end
155
+ end
156
+
157
+ context 'in SetRankingMode method' do
158
+ it 'should raise an error when ranker is not Integer, String or Symbol' do
159
+ expect {
160
+ @sphinx.SetRankingMode([])
161
+ }.to raise_error(ArgumentError)
162
+ end
163
+
164
+ it 'should raise an error when ranker is invalid' do
165
+ expect {
166
+ @sphinx.SetRankingMode('invalid')
167
+ }.to raise_error(ArgumentError)
168
+
169
+ expect {
170
+ @sphinx.SetRankingMode(:invalid)
171
+ }.to raise_error(ArgumentError)
172
+
173
+ expect {
174
+ @sphinx.SetRankingMode(100)
175
+ }.to raise_error(ArgumentError)
176
+ end
177
+ end
178
+
179
+ context 'in SetSortMode method' do
180
+ it 'should raise an error when mode is not Integer, String or Symbol' do
181
+ expect {
182
+ @sphinx.SetSortMode([])
183
+ }.to raise_error(ArgumentError)
184
+ end
185
+
186
+ it 'should raise an error when mode is invalid' do
187
+ expect {
188
+ @sphinx.SetSortMode('invalid')
189
+ }.to raise_error(ArgumentError)
190
+
191
+ expect {
192
+ @sphinx.SetSortMode(:invalid)
193
+ }.to raise_error(ArgumentError)
194
+
195
+ expect {
196
+ @sphinx.SetSortMode(100)
197
+ }.to raise_error(ArgumentError)
198
+ end
199
+
200
+ it 'should raise an error when sortby is not String' do
201
+ expect {
202
+ @sphinx.SetSortMode(:relevance, [])
203
+ }.to raise_error(ArgumentError)
204
+ end
205
+
206
+ it 'should raise an error when sortby is empty' do
207
+ expect {
208
+ @sphinx.SetSortMode(:attr_desc)
209
+ }.to raise_error(ArgumentError)
210
+ end
211
+ end
212
+
213
+ context 'in SetWeights method' do
214
+ it 'should raise an error when weights is not Array' do
215
+ expect {
216
+ @sphinx.SetWeights({})
217
+ }.to raise_error(ArgumentError)
218
+ end
219
+
220
+ it 'should raise an error when weights is not Array of Integers' do
221
+ expect {
222
+ @sphinx.SetWeights([1, 'a'])
223
+ }.to raise_error(ArgumentError)
224
+ end
225
+ end
226
+
227
+ context 'in SetFieldWeights method' do
228
+ it 'should raise an error when weights is not Hash' do
229
+ expect {
230
+ @sphinx.SetFieldWeights([])
231
+ }.to raise_error(ArgumentError)
232
+ end
233
+
234
+ it 'should raise an error when weights is not Hash map of strings to integers' do
235
+ expect {
236
+ @sphinx.SetFieldWeights('a' => 'b', :c => 5)
237
+ }.to raise_error(ArgumentError)
238
+
239
+ expect {
240
+ @sphinx.SetFieldWeights(:a => 'b', :c => 5)
241
+ }.to raise_error(ArgumentError)
242
+
243
+ expect {
244
+ @sphinx.SetFieldWeights(1 => 1, :c => 5)
245
+ }.to raise_error(ArgumentError)
246
+
247
+ expect {
248
+ @sphinx.SetFieldWeights(1 => 'a', :c => 5)
249
+ }.to raise_error(ArgumentError)
250
+
251
+ expect {
252
+ @sphinx.SetFieldWeights(:a => 1, :c => 5)
253
+ }.to_not raise_error(ArgumentError)
254
+
255
+ expect {
256
+ @sphinx.SetFieldWeights('a' => 1, :c => 5)
257
+ }.to_not raise_error(ArgumentError)
258
+ end
259
+ end
260
+
261
+ context 'in SetIndexWeights method' do
262
+ it 'should raise an error when weights is not Hash' do
263
+ expect {
264
+ @sphinx.SetIndexWeights([])
265
+ }.to raise_error(ArgumentError)
266
+ end
267
+
268
+ it 'should raise an error when weights is not Hash map of strings to integers' do
269
+ expect {
270
+ @sphinx.SetIndexWeights('a' => 'b', :c => 5)
271
+ }.to raise_error(ArgumentError)
272
+
273
+ expect {
274
+ @sphinx.SetIndexWeights(:a => 'b', :c => 5)
275
+ }.to raise_error(ArgumentError)
276
+
277
+ expect {
278
+ @sphinx.SetIndexWeights(1 => 1, :c => 5)
279
+ }.to raise_error(ArgumentError)
280
+
281
+ expect {
282
+ @sphinx.SetIndexWeights(1 => 'a', :c => 5)
283
+ }.to raise_error(ArgumentError)
284
+
285
+ expect {
286
+ @sphinx.SetIndexWeights(:a => 1, :c => 5)
287
+ }.to_not raise_error(ArgumentError)
288
+
289
+ expect {
290
+ @sphinx.SetIndexWeights('a' => 1, :c => 5)
291
+ }.to_not raise_error(ArgumentError)
292
+ end
293
+ end
294
+
295
+ context 'in SetIDRange method' do
296
+ it 'should raise an error when min is not Integer' do
297
+ expect {
298
+ @sphinx.SetIDRange('min', 0)
299
+ }.to raise_error(ArgumentError)
300
+ end
301
+
302
+ it 'should raise an error when max is not Integer' do
303
+ expect {
304
+ @sphinx.SetIDRange(0, 'max')
305
+ }.to raise_error(ArgumentError)
306
+ end
307
+
308
+ it 'should raise an error when max is less than zero' do
309
+ expect {
310
+ @sphinx.SetIDRange(2, 1)
311
+ }.to raise_error(ArgumentError)
312
+ end
313
+ end
314
+
315
+ context 'in SetFilter method' do
316
+ it 'should raise an error when attribute is not String or Symbol' do
317
+ expect {
318
+ @sphinx.SetFilter(1, [1, 2])
319
+ }.to raise_error(ArgumentError)
320
+
321
+ expect {
322
+ @sphinx.SetFilter('attr', [1, 2])
323
+ }.to_not raise_error(ArgumentError)
324
+
325
+ expect {
326
+ @sphinx.SetFilter(:attr, [1, 2])
327
+ }.to_not raise_error(ArgumentError)
328
+ end
329
+
330
+ it 'should raise an error when values is not Array' do
331
+ expect {
332
+ @sphinx.SetFilter(:attr, {})
333
+ }.to raise_error(ArgumentError)
334
+ end
335
+
336
+ it 'should raise an error when values is not Array of Integers' do
337
+ expect {
338
+ @sphinx.SetFilter(:attr, [1, 'a'])
339
+ }.to raise_error(ArgumentError)
340
+ end
341
+
342
+ it 'should raise an error when values is empty Array' do
343
+ expect {
344
+ @sphinx.SetFilter(:attr, [])
345
+ }.to raise_error(ArgumentError)
346
+ end
347
+
348
+ it 'should raise an error when exclude is not Boolean' do
349
+ expect {
350
+ @sphinx.SetFilter(:attr, [1, 2], 'true')
351
+ }.to raise_error(ArgumentError)
352
+
353
+ expect {
354
+ @sphinx.SetFilter(:attr, [1, 2], true)
355
+ }.to_not raise_error(ArgumentError)
356
+
357
+ expect {
358
+ @sphinx.SetFilter(:attr, [1, 2], false)
359
+ }.to_not raise_error(ArgumentError)
360
+ end
361
+ end
362
+
363
+ context 'in SetFilterRange method' do
364
+ it 'should raise an error when attribute is not String or Symbol' do
365
+ expect {
366
+ @sphinx.SetFilterRange(1, 1, 2)
367
+ }.to raise_error(ArgumentError)
368
+
369
+ expect {
370
+ @sphinx.SetFilterRange('attr', 1, 2)
371
+ }.to_not raise_error(ArgumentError)
372
+
373
+ expect {
374
+ @sphinx.SetFilterRange(:attr, 1, 2)
375
+ }.to_not raise_error(ArgumentError)
376
+ end
377
+
378
+ it 'should raise an error when min is not Integer' do
379
+ expect {
380
+ @sphinx.SetFilterRange(:attr, 'min', 0)
381
+ }.to raise_error(ArgumentError)
382
+ end
383
+
384
+ it 'should raise an error when max is not Integer' do
385
+ expect {
386
+ @sphinx.SetFilterRange(:attr, 0, 'max')
387
+ }.to raise_error(ArgumentError)
388
+ end
389
+
390
+ it 'should raise an error when max is less than zero' do
391
+ expect {
392
+ @sphinx.SetFilterRange(:attr, 2, 1)
393
+ }.to raise_error(ArgumentError)
394
+ end
395
+
396
+ it 'should raise an error when exclude is not Boolean' do
397
+ expect {
398
+ @sphinx.SetFilterRange(:attr, 1, 2, 'true')
399
+ }.to raise_error(ArgumentError)
400
+
401
+ expect {
402
+ @sphinx.SetFilterRange(:attr, 1, 2, true)
403
+ }.to_not raise_error(ArgumentError)
404
+
405
+ expect {
406
+ @sphinx.SetFilterRange(:attr, 1, 2, false)
407
+ }.to_not raise_error(ArgumentError)
408
+ end
409
+ end
410
+
411
+ context 'in SetFilterFloatRange method' do
412
+ it 'should raise an error when attribute is not String or Symbol' do
413
+ expect {
414
+ @sphinx.SetFilterFloatRange(1, 1, 2)
415
+ }.to raise_error(ArgumentError)
416
+
417
+ expect {
418
+ @sphinx.SetFilterFloatRange('attr', 1, 2)
419
+ }.to_not raise_error(ArgumentError)
420
+
421
+ expect {
422
+ @sphinx.SetFilterFloatRange(:attr, 1, 2)
423
+ }.to_not raise_error(ArgumentError)
424
+ end
425
+
426
+ it 'should raise an error when min is not Integer or Float' do
427
+ expect {
428
+ @sphinx.SetFilterFloatRange(:attr, 'min', 1)
429
+ }.to raise_error(ArgumentError)
430
+
431
+ expect {
432
+ @sphinx.SetFilterFloatRange(:attr, 0, 1)
433
+ }.to_not raise_error(ArgumentError)
434
+
435
+ expect {
436
+ @sphinx.SetFilterFloatRange(:attr, 0.1, 1)
437
+ }.to_not raise_error(ArgumentError)
438
+ end
439
+
440
+ it 'should raise an error when max is not Integer or Float' do
441
+ expect {
442
+ @sphinx.SetFilterFloatRange(:attr, 0, 'max')
443
+ }.to raise_error(ArgumentError)
444
+
445
+ expect {
446
+ @sphinx.SetFilterFloatRange(:attr, 0, 1)
447
+ }.to_not raise_error(ArgumentError)
448
+
449
+ expect {
450
+ @sphinx.SetFilterFloatRange(:attr, 0, 1.1)
451
+ }.to_not raise_error(ArgumentError)
452
+ end
453
+
454
+ it 'should raise an error when max is less than zero' do
455
+ expect {
456
+ @sphinx.SetFilterFloatRange(:attr, 2, 1)
457
+ }.to raise_error(ArgumentError)
458
+ end
459
+
460
+ it 'should raise an error when exclude is not Boolean' do
461
+ expect {
462
+ @sphinx.SetFilterFloatRange(:attr, 1, 2, 'true')
463
+ }.to raise_error(ArgumentError)
464
+
465
+ expect {
466
+ @sphinx.SetFilterFloatRange(:attr, 1, 2, true)
467
+ }.to_not raise_error(ArgumentError)
468
+
469
+ expect {
470
+ @sphinx.SetFilterFloatRange(:attr, 1, 2, false)
471
+ }.to_not raise_error(ArgumentError)
472
+ end
473
+ end
474
+
475
+ context 'in SetGeoAnchor method' do
476
+ it 'should raise an error when attrlat is not String or Symbol' do
477
+ expect {
478
+ @sphinx.SetGeoAnchor(1, 'attrlong', 1, 2)
479
+ }.to raise_error(ArgumentError)
480
+
481
+ expect {
482
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1, 2)
483
+ }.to_not raise_error(ArgumentError)
484
+
485
+ expect {
486
+ @sphinx.SetGeoAnchor(:attrlat, 'attrlong', 1, 2)
487
+ }.to_not raise_error(ArgumentError)
488
+ end
489
+
490
+ it 'should raise an error when attrlong is not String or Symbol' do
491
+ expect {
492
+ @sphinx.SetGeoAnchor('attrlat', 1, 1, 2)
493
+ }.to raise_error(ArgumentError)
494
+
495
+ expect {
496
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1, 2)
497
+ }.to_not raise_error(ArgumentError)
498
+
499
+ expect {
500
+ @sphinx.SetGeoAnchor('attrlat', :attrlong, 1, 2)
501
+ }.to_not raise_error(ArgumentError)
502
+ end
503
+
504
+ it 'should raise an error when lat is not Integer or Float' do
505
+ expect {
506
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 'a', 2)
507
+ }.to raise_error(ArgumentError)
508
+
509
+ expect {
510
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1, 2)
511
+ }.to_not raise_error(ArgumentError)
512
+
513
+ expect {
514
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1.1, 2)
515
+ }.to_not raise_error(ArgumentError)
516
+ end
517
+
518
+ it 'should raise an error when long is not Integer or Float' do
519
+ expect {
520
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1, 'a')
521
+ }.to raise_error(ArgumentError)
522
+
523
+ expect {
524
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1, 2)
525
+ }.to_not raise_error(ArgumentError)
526
+
527
+ expect {
528
+ @sphinx.SetGeoAnchor('attrlat', 'attrlong', 1.1, 2)
529
+ }.to_not raise_error(ArgumentError)
530
+ end
531
+ end
532
+
533
+ context 'in SetGroupBy method' do
534
+ it 'should raise an error when attribute is not String or Symbol' do
535
+ expect {
536
+ @sphinx.SetGroupBy(1, :day)
537
+ }.to raise_error(ArgumentError)
538
+
539
+ expect {
540
+ @sphinx.SetGroupBy('attr', :day)
541
+ }.to_not raise_error(ArgumentError)
542
+
543
+ expect {
544
+ @sphinx.SetGroupBy(:attr, :day)
545
+ }.to_not raise_error(ArgumentError)
546
+ end
547
+
548
+ it 'should raise an error when func is invalid' do
549
+ expect {
550
+ @sphinx.SetGroupBy(:attr, 'invalid')
551
+ }.to raise_error(ArgumentError)
552
+
553
+ expect {
554
+ @sphinx.SetGroupBy(:attr, :invalid)
555
+ }.to raise_error(ArgumentError)
556
+
557
+ expect {
558
+ @sphinx.SetGroupBy(:attr, 100)
559
+ }.to raise_error(ArgumentError)
560
+ end
561
+
562
+ it 'should raise an error when groupsort is not String' do
563
+ expect {
564
+ @sphinx.SetGroupBy(1, :day, 1)
565
+ }.to raise_error(ArgumentError)
566
+
567
+ expect {
568
+ @sphinx.SetGroupBy('attr', :day, 'groupsort')
569
+ }.to_not raise_error(ArgumentError)
570
+ end
571
+ end
572
+
573
+ context 'in SetGroupDistinct method' do
574
+ it 'should raise an error when attribute is not String or Symbol' do
575
+ expect {
576
+ @sphinx.SetGroupDistinct(1)
577
+ }.to raise_error(ArgumentError)
578
+
579
+ expect {
580
+ @sphinx.SetGroupDistinct('attr')
581
+ }.to_not raise_error(ArgumentError)
582
+
583
+ expect {
584
+ @sphinx.SetGroupDistinct(:attr)
585
+ }.to_not raise_error(ArgumentError)
586
+ end
587
+ end
588
+
589
+ context 'in SetRetries method' do
590
+ it 'should raise an error when count is not Integer' do
591
+ expect {
592
+ @sphinx.SetRetries('count', 0)
593
+ }.to raise_error(ArgumentError)
594
+ end
595
+
596
+ it 'should raise an error when delay is not Integer' do
597
+ expect {
598
+ @sphinx.SetRetries(0, 'delay')
599
+ }.to raise_error(ArgumentError)
600
+ end
601
+ end
602
+
603
+ context 'in SetOverride method' do
604
+ it 'should raise an error when attribute is not String or Symbol' do
605
+ expect {
606
+ @sphinx.SetOverride(1, :integer, {})
607
+ }.to raise_error(ArgumentError)
608
+
609
+ expect {
610
+ @sphinx.SetOverride('attr', :integer, {})
611
+ }.to_not raise_error(ArgumentError)
612
+
613
+ expect {
614
+ @sphinx.SetOverride(:attr, :integer, {})
615
+ }.to_not raise_error(ArgumentError)
616
+ end
617
+
618
+ it 'should raise an error when attrtype is invalid' do
619
+ expect {
620
+ @sphinx.SetOverride(:attr, 'invalid', {})
621
+ }.to raise_error(ArgumentError)
622
+
623
+ expect {
624
+ @sphinx.SetOverride(:attr, :invalid, {})
625
+ }.to raise_error(ArgumentError)
626
+
627
+ expect {
628
+ @sphinx.SetOverride(:attr, 100, {})
629
+ }.to raise_error(ArgumentError)
630
+ end
631
+
632
+ it 'should raise an error when values is not Hash' do
633
+ expect {
634
+ @sphinx.SetOverride(:attr, :integer, [])
635
+ }.to raise_error(ArgumentError)
636
+ end
637
+
638
+ it "should raise an error when values Hash keys are not Integers" do
639
+ expect {
640
+ @sphinx.SetOverride(:attr, :integer, { 'a' => 10 })
641
+ }.to raise_error(ArgumentError)
642
+
643
+ expect {
644
+ @sphinx.SetOverride(:attr, :integer, { 10 => 10 })
645
+ }.to_not raise_error(ArgumentError)
646
+ end
647
+
648
+ [:integer, :ordinal, :bool, :bigint].each do |attrtype|
649
+ it "should raise an error when attrtype is \"#{attrtype}\" and values Hash values are not Integers" do
650
+ expect {
651
+ @sphinx.SetOverride(:attr, attrtype, { 10 => '10' })
652
+ }.to raise_error(ArgumentError)
653
+
654
+ expect {
655
+ @sphinx.SetOverride(:attr, attrtype, { 10 => 10 })
656
+ }.to_not raise_error(ArgumentError)
657
+ end
658
+ end
659
+
660
+ it "should raise an error when attrtype is \"timestamp\" and values Hash values are not Integers or Time" do
661
+ expect {
662
+ @sphinx.SetOverride(:attr, :timestamp, { 10 => '10' })
663
+ }.to raise_error(ArgumentError)
664
+
665
+ expect {
666
+ @sphinx.SetOverride(:attr, :timestamp, { 10 => 10 })
667
+ }.to_not raise_error(ArgumentError)
668
+
669
+ expect {
670
+ @sphinx.SetOverride(:attr, :timestamp, { 10 => Time.now })
671
+ }.to_not raise_error(ArgumentError)
672
+ end
673
+
674
+ it "should raise an error when attrtype is \"float\" and values Hash values are not Integers or Floats" do
675
+ expect {
676
+ @sphinx.SetOverride(:attr, :float, { 10 => '10' })
677
+ }.to raise_error(ArgumentError)
678
+
679
+ expect {
680
+ @sphinx.SetOverride(:attr, :float, { 10 => 10 })
681
+ }.to_not raise_error(ArgumentError)
682
+
683
+ expect {
684
+ @sphinx.SetOverride(:attr, :float, { 10 => 10.1 })
685
+ }.to_not raise_error(ArgumentError)
686
+ end
687
+ end
688
+
689
+ context 'in SetSelect method' do
690
+ it 'should raise an error when select is not String' do
691
+ expect {
692
+ @sphinx.SetSelect(:select)
693
+ }.to raise_error(ArgumentError)
694
+
695
+ expect {
696
+ @sphinx.SetSelect(1)
697
+ }.to raise_error(ArgumentError)
698
+
699
+ expect {
700
+ @sphinx.SetSelect('select')
701
+ }.to_not raise_error(ArgumentError)
702
+ end
703
+ end
704
+
705
+ context 'in BuildExcerpts method' do
706
+ it 'should raise an error when docs is not Array of Strings' do
707
+ expect {
708
+ @sphinx.BuildExcerpts(1, 'index', 'words')
709
+ }.to raise_error(ArgumentError)
710
+
711
+ expect {
712
+ @sphinx.BuildExcerpts('doc', 'index', 'words')
713
+ }.to raise_error(ArgumentError)
714
+
715
+ expect {
716
+ @sphinx.BuildExcerpts([1], 'index', 'words')
717
+ }.to raise_error(ArgumentError)
718
+
719
+ expect {
720
+ @sphinx.BuildExcerpts(['doc'], 'index', 'words')
721
+ }.to_not raise_error(ArgumentError)
722
+ end
723
+
724
+ it 'should raise an error when index is not String or Symbol' do
725
+ expect {
726
+ @sphinx.BuildExcerpts(['doc'], 1, 'words')
727
+ }.to raise_error(ArgumentError)
728
+
729
+ expect {
730
+ @sphinx.BuildExcerpts(['doc'], 'index', 'words')
731
+ }.to_not raise_error(ArgumentError)
732
+
733
+ expect {
734
+ @sphinx.BuildExcerpts(['doc'], :index, 'words')
735
+ }.to_not raise_error(ArgumentError)
736
+ end
737
+
738
+ it 'should raise an error when words is not String' do
739
+ expect {
740
+ @sphinx.BuildExcerpts(['doc'], 'index', 1)
741
+ }.to raise_error(ArgumentError)
742
+ end
743
+
744
+ it 'should raise an error when opts is not Hash' do
745
+ expect {
746
+ @sphinx.BuildExcerpts(['doc'], 'index', 'words', [])
747
+ }.to raise_error(ArgumentError)
748
+ end
749
+ end
750
+
751
+ context 'in BuildKeywords method' do
752
+ it 'should raise an error when query is not String' do
753
+ expect {
754
+ @sphinx.BuildExcerpts([], 'index', true)
755
+ }.to raise_error(ArgumentError)
756
+ end
757
+
758
+ it 'should raise an error when index is not String or Symbol' do
759
+ expect {
760
+ @sphinx.BuildKeywords('query', 1, true)
761
+ }.to raise_error(ArgumentError)
762
+
763
+ expect {
764
+ @sphinx.BuildKeywords('query', 'index', true)
765
+ }.to_not raise_error(ArgumentError)
766
+
767
+ expect {
768
+ @sphinx.BuildKeywords('query', :index, true)
769
+ }.to_not raise_error(ArgumentError)
770
+ end
771
+
772
+ it 'should raise an error when hits is not Boolean' do
773
+ expect {
774
+ @sphinx.BuildKeywords('query', :index, 1)
775
+ }.to raise_error(ArgumentError)
776
+
777
+ expect {
778
+ @sphinx.BuildKeywords('query', :index, true)
779
+ }.to_not raise_error(ArgumentError)
780
+
781
+ expect {
782
+ @sphinx.BuildKeywords('query', :index, false)
783
+ }.to_not raise_error(ArgumentError)
784
+ end
785
+ end
786
+
787
+ context 'in UpdateAttributes method' do
788
+ it 'should raise an error when index is not String or Symbol' do
789
+ expect {
790
+ @sphinx.UpdateAttributes(1, [:attr1, :attr2], { 10 => [1, 2], 20 => [3, 4] }, false)
791
+ }.to raise_error(ArgumentError)
792
+
793
+ expect {
794
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [1, 2], 20 => [3, 4] }, false)
795
+ }.to_not raise_error(ArgumentError)
796
+
797
+ expect {
798
+ @sphinx.UpdateAttributes(:index, [:attr1, :attr2], { 10 => [1, 2], 20 => [3, 4] }, false)
799
+ }.to_not raise_error(ArgumentError)
800
+ end
801
+
802
+ it 'should raise an error when mva is not Boolean' do
803
+ expect {
804
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [1, 2], 20 => [3, 4] }, 1)
805
+ }.to raise_error(ArgumentError)
806
+
807
+ expect {
808
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [1, 2], 20 => [3, 4] }, false)
809
+ }.to_not raise_error(ArgumentError)
810
+
811
+ expect {
812
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [[1], [2]], 20 => [[3], [4]] }, true)
813
+ }.to_not raise_error(ArgumentError)
814
+ end
815
+
816
+ it 'should raise an error when values is not Hash' do
817
+ expect {
818
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], [], 1)
819
+ }.to raise_error(ArgumentError)
820
+ end
821
+
822
+ it 'should raise an error when mva is false and values is not Hash map of Integers to Arrays of Integers' do
823
+ expect {
824
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 'a' => [1, 2], 20 => [3, 4] }, false)
825
+ }.to raise_error(ArgumentError)
826
+
827
+ expect {
828
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [1, 2], 20 => ['3', 4] }, false)
829
+ }.to raise_error(ArgumentError)
830
+
831
+ expect {
832
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [1, 2], 20 => 5 }, false)
833
+ }.to raise_error(ArgumentError)
834
+ end
835
+
836
+ it 'should raise an error when mva is true and values is not Hash map of Integers to Arrays of Arrays of Integers' do
837
+ expect {
838
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 'a' => [[1], [2]], 20 => [[3], [4]] }, true)
839
+ }.to raise_error(ArgumentError)
840
+
841
+ expect {
842
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [[1], [2]], 20 => 5 }, true)
843
+ }.to raise_error(ArgumentError)
844
+
845
+ expect {
846
+ @sphinx.UpdateAttributes('index', [:attr1, :attr2], { 10 => [[1], [2]], 20 => [3, [4]] }, true)
847
+ }.to raise_error(ArgumentError)
848
+ end
849
+ end
850
+ end