sunspot_matchers 1.3.0.2 → 2.0.0.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.
@@ -2,9 +2,12 @@ require 'sunspot'
2
2
  require 'sunspot_matchers'
3
3
  require 'rspec'
4
4
 
5
- class Post; end
6
- class Blog; end
7
- class Person; end
5
+ class Post;
6
+ end
7
+ class Blog;
8
+ end
9
+ class Person;
10
+ end
8
11
 
9
12
  Sunspot.setup(Post) do
10
13
  text :body
@@ -24,7 +27,7 @@ end
24
27
 
25
28
  describe "Sunspot Matchers" do
26
29
  include SunspotMatchers
27
-
30
+
28
31
  before do
29
32
  Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session)
30
33
  end
@@ -75,10 +78,10 @@ describe "Sunspot Matchers" do
75
78
  keywords 'great pizza'
76
79
  keywords 'terrible pizza'
77
80
  end
78
- Sunspot.session.should have_search_params(:keywords, Proc.new {
81
+ Sunspot.session.should have_search_params(:keywords) {
79
82
  keywords 'great pizza'
80
83
  keywords 'terrible pizza'
81
- })
84
+ }
82
85
  end
83
86
 
84
87
  it "should work with any_param match" do
@@ -116,46 +119,46 @@ describe "Sunspot Matchers" do
116
119
  with :author_name, 'Mark Twain'
117
120
  with :author_name, 'John Twain'
118
121
  end
119
- Sunspot.session.should have_search_params(:with, Proc.new {
122
+ Sunspot.session.should have_search_params(:with) {
120
123
  with :author_name, 'Mark Twain'
121
124
  with :author_name, 'John Twain'
122
- })
125
+ }
123
126
  end
124
127
 
125
128
  it "should match for greater_than" do
126
129
  Sunspot.search(Post) do
127
130
  with(:category_ids).greater_than(1)
128
131
  end
129
- Sunspot.session.should have_search_params(:with, Proc.new {
132
+ Sunspot.session.should have_search_params(:with) {
130
133
  with(:category_ids).greater_than(1)
131
- })
134
+ }
132
135
  end
133
136
 
134
137
  it "should match for less_than" do
135
138
  Sunspot.search(Post) do
136
139
  with(:category_ids).less_than(1)
137
140
  end
138
- Sunspot.session.should have_search_params(:with, Proc.new {
141
+ Sunspot.session.should have_search_params(:with) {
139
142
  with(:category_ids).less_than(1)
140
- })
143
+ }
141
144
  end
142
145
 
143
146
  it "should match for range" do
144
147
  Sunspot.search(Post) do
145
148
  with :category_ids, 1..3
146
149
  end
147
- Sunspot.session.should have_search_params(:with, Proc.new {
150
+ Sunspot.session.should have_search_params(:with) {
148
151
  with :category_ids, 1..3
149
- })
152
+ }
150
153
  end
151
154
 
152
155
  it "should match any_of" do
153
156
  Sunspot.search(Post) do
154
- with(:category_ids).any_of [1,2]
157
+ with(:category_ids).any_of [1, 2]
155
158
  end
156
- Sunspot.session.should have_search_params(:with, Proc.new {
157
- with(:category_ids).any_of [1,2]
158
- })
159
+ Sunspot.session.should have_search_params(:with) {
160
+ with(:category_ids).any_of [1, 2]
161
+ }
159
162
  end
160
163
 
161
164
  it "should match any_of multiline" do
@@ -165,12 +168,12 @@ describe "Sunspot Matchers" do
165
168
  with :category_ids, 2
166
169
  end
167
170
  end
168
- Sunspot.session.should have_search_params(:with, Proc.new {
171
+ Sunspot.session.should have_search_params(:with) {
169
172
  any_of do
170
173
  with :category_ids, 1
171
174
  with :category_ids, 2
172
175
  end
173
- })
176
+ }
174
177
  end
175
178
 
176
179
  it "should match any_of and all_of" do
@@ -183,7 +186,7 @@ describe "Sunspot Matchers" do
183
186
  end
184
187
  end
185
188
  end
186
- Sunspot.session.should have_search_params(:with, Proc.new {
189
+ Sunspot.session.should have_search_params(:with) {
187
190
  any_of do
188
191
  with :category_ids, 1
189
192
  all_of do
@@ -191,7 +194,7 @@ describe "Sunspot Matchers" do
191
194
  with :category_ids, 3
192
195
  end
193
196
  end
194
- })
197
+ }
195
198
  end
196
199
 
197
200
  it "should work with any_param match" do
@@ -243,46 +246,46 @@ describe "Sunspot Matchers" do
243
246
  without :author_name, 'Mark Twain'
244
247
  without :author_name, 'John Twain'
245
248
  end
246
- Sunspot.session.should have_search_params(:without, Proc.new {
249
+ Sunspot.session.should have_search_params(:without) {
247
250
  without :author_name, 'Mark Twain'
248
251
  without :author_name, 'John Twain'
249
- })
252
+ }
250
253
  end
251
254
 
252
255
  it "should match for greater_than" do
253
256
  Sunspot.search(Post) do
254
257
  without(:category_ids).greater_than(1)
255
258
  end
256
- Sunspot.session.should have_search_params(:without, Proc.new {
259
+ Sunspot.session.should have_search_params(:without) {
257
260
  without(:category_ids).greater_than(1)
258
- })
261
+ }
259
262
  end
260
263
 
261
264
  it "should match for less_than" do
262
265
  Sunspot.search(Post) do
263
266
  without(:category_ids).less_than(1)
264
267
  end
265
- Sunspot.session.should have_search_params(:without, Proc.new {
268
+ Sunspot.session.should have_search_params(:without) {
266
269
  without(:category_ids).less_than(1)
267
- })
270
+ }
268
271
  end
269
272
 
270
273
  it "should match for range" do
271
274
  Sunspot.search(Post) do
272
275
  without :category_ids, 1..3
273
276
  end
274
- Sunspot.session.should have_search_params(:without, Proc.new {
277
+ Sunspot.session.should have_search_params(:without) {
275
278
  without :category_ids, 1..3
276
- })
279
+ }
277
280
  end
278
281
 
279
282
  it "should match any_of" do
280
283
  Sunspot.search(Post) do
281
- without(:category_ids).any_of [1,2]
284
+ without(:category_ids).any_of [1, 2]
282
285
  end
283
- Sunspot.session.should have_search_params(:without, Proc.new {
284
- without(:category_ids).any_of [1,2]
285
- })
286
+ Sunspot.session.should have_search_params(:without) {
287
+ without(:category_ids).any_of [1, 2]
288
+ }
286
289
  end
287
290
 
288
291
  it "should match any_of multiline" do
@@ -292,12 +295,12 @@ describe "Sunspot Matchers" do
292
295
  without :category_ids, 2
293
296
  end
294
297
  end
295
- Sunspot.session.should have_search_params(:without, Proc.new {
298
+ Sunspot.session.should have_search_params(:without) {
296
299
  any_of do
297
300
  without :category_ids, 1
298
301
  without :category_ids, 2
299
302
  end
300
- })
303
+ }
301
304
  end
302
305
 
303
306
  it "should match any_of and all_of" do
@@ -310,7 +313,7 @@ describe "Sunspot Matchers" do
310
313
  end
311
314
  end
312
315
  end
313
- Sunspot.session.should have_search_params(:without, Proc.new {
316
+ Sunspot.session.should have_search_params(:without) {
314
317
  any_of do
315
318
  without :category_ids, 1
316
319
  all_of do
@@ -318,7 +321,7 @@ describe "Sunspot Matchers" do
318
321
  without :category_ids, 3
319
322
  end
320
323
  end
321
- })
324
+ }
322
325
  end
323
326
 
324
327
  it "should work with any_param match" do
@@ -400,10 +403,10 @@ describe "Sunspot Matchers" do
400
403
  order_by :published_at, :asc
401
404
  order_by :average_rating, :asc
402
405
  end
403
- Sunspot.session.should have_search_params(:order_by, Proc.new {
406
+ Sunspot.session.should have_search_params(:order_by) {
404
407
  order_by :published_at, :asc
405
408
  order_by :average_rating, :asc
406
- })
409
+ }
407
410
  end
408
411
 
409
412
  it "should not match if multiple orderings are reversed" do
@@ -411,10 +414,10 @@ describe "Sunspot Matchers" do
411
414
  order_by :average_rating, :asc
412
415
  order_by :published_at, :asc
413
416
  end
414
- Sunspot.session.should_not have_search_params(:order_by, Proc.new {
417
+ Sunspot.session.should_not have_search_params(:order_by) {
415
418
  order_by :published_at, :asc
416
419
  order_by :average_rating, :asc
417
- })
420
+ }
418
421
  end
419
422
 
420
423
  it "should match when using random" do
@@ -422,10 +425,10 @@ describe "Sunspot Matchers" do
422
425
  order_by :average_rating, :asc
423
426
  order_by :random
424
427
  end
425
- Sunspot.session.should have_search_params(:order_by, Proc.new {
428
+ Sunspot.session.should have_search_params(:order_by) {
426
429
  order_by :average_rating, :asc
427
430
  order_by :random
428
- })
431
+ }
429
432
  end
430
433
 
431
434
  it "should not match when random is missing" do
@@ -433,9 +436,9 @@ describe "Sunspot Matchers" do
433
436
  order_by :average_rating, :asc
434
437
  order_by :random
435
438
  end
436
- Sunspot.session.should_not have_search_params(:order_by, Proc.new {
439
+ Sunspot.session.should_not have_search_params(:order_by) {
437
440
  order_by :average_rating, :asc
438
- })
441
+ }
439
442
  end
440
443
 
441
444
  it "should match when using score" do
@@ -443,10 +446,10 @@ describe "Sunspot Matchers" do
443
446
  order_by :average_rating, :asc
444
447
  order_by :score
445
448
  end
446
- Sunspot.session.should have_search_params(:order_by, Proc.new {
449
+ Sunspot.session.should have_search_params(:order_by) {
447
450
  order_by :average_rating, :asc
448
451
  order_by :score
449
- })
452
+ }
450
453
  end
451
454
 
452
455
  it "should not match when score is missing" do
@@ -454,9 +457,9 @@ describe "Sunspot Matchers" do
454
457
  order_by :average_rating, :asc
455
458
  order_by :score
456
459
  end
457
- Sunspot.session.should_not have_search_params(:order_by, Proc.new {
460
+ Sunspot.session.should_not have_search_params(:order_by) {
458
461
  order_by :average_rating, :asc
459
- })
462
+ }
460
463
  end
461
464
 
462
465
  it "should work with any_param match on direction" do
@@ -523,10 +526,10 @@ describe "Sunspot Matchers" do
523
526
  category_filter = with(:category_ids, 2)
524
527
  facet(:category_ids, :exclude => category_filter)
525
528
  end
526
- Sunspot.session.should have_search_params(:facet, Proc.new {
529
+ Sunspot.session.should have_search_params(:facet) {
527
530
  category_filter = with(:category_ids, 2)
528
531
  facet(:category_ids, :exclude => category_filter)
529
- })
532
+ }
530
533
  end
531
534
  end
532
535
 
@@ -542,7 +545,7 @@ describe "Sunspot Matchers" do
542
545
  end
543
546
  end
544
547
  end
545
- Sunspot.session.should have_search_params(:facet, Proc.new {
548
+ Sunspot.session.should have_search_params(:facet) {
546
549
  facet(:average_rating) do
547
550
  row(1.0..2.0) do
548
551
  with(:average_rating, 1.0..2.0)
@@ -551,7 +554,7 @@ describe "Sunspot Matchers" do
551
554
  with(:average_rating, 2.0..3.0)
552
555
  end
553
556
  end
554
- })
557
+ }
555
558
  end
556
559
 
557
560
  it "should not match if actual search is missing a facet" do
@@ -562,7 +565,7 @@ describe "Sunspot Matchers" do
562
565
  end
563
566
  end
564
567
  end
565
- Sunspot.session.should_not have_search_params(:facet, Proc.new {
568
+ Sunspot.session.should_not have_search_params(:facet) {
566
569
  facet(:average_rating) do
567
570
  row(1.0..2.0) do
568
571
  with(:average_rating, 1.0..2.0)
@@ -571,7 +574,7 @@ describe "Sunspot Matchers" do
571
574
  with(:average_rating, 2.0..3.0)
572
575
  end
573
576
  end
574
- })
577
+ }
575
578
  end
576
579
 
577
580
  it "should not match if facet query is different" do
@@ -585,7 +588,7 @@ describe "Sunspot Matchers" do
585
588
  end
586
589
  end
587
590
  end
588
- Sunspot.session.should_not have_search_params(:facet, Proc.new {
591
+ Sunspot.session.should_not have_search_params(:facet) {
589
592
  facet(:average_rating) do
590
593
  row(1.0..2.0) do
591
594
  with(:average_rating, 1.0..2.0)
@@ -594,7 +597,7 @@ describe "Sunspot Matchers" do
594
597
  with(:average_rating, 2.0..4.0)
595
598
  end
596
599
  end
597
- })
600
+ }
598
601
  end
599
602
  end
600
603
  end
@@ -606,11 +609,11 @@ describe "Sunspot Matchers" do
606
609
  boost_fields :body => 2.0
607
610
  end
608
611
  end
609
- Sunspot.session.should have_search_params(:boost, Proc.new {
612
+ Sunspot.session.should have_search_params(:boost) {
610
613
  keywords 'great pizza' do
611
614
  boost_fields :body => 2.0
612
615
  end
613
- })
616
+ }
614
617
  end
615
618
 
616
619
  it "should not match if field boost does not match" do
@@ -619,11 +622,11 @@ describe "Sunspot Matchers" do
619
622
  boost_fields :body => 2.0
620
623
  end
621
624
  end
622
- Sunspot.session.should_not have_search_params(:boost, Proc.new {
625
+ Sunspot.session.should_not have_search_params(:boost) {
623
626
  keywords 'great pizza' do
624
627
  boost_fields :body => 3.0
625
628
  end
626
- })
629
+ }
627
630
  end
628
631
 
629
632
  it "should match if boost query matches" do
@@ -634,13 +637,13 @@ describe "Sunspot Matchers" do
634
637
  end
635
638
  end
636
639
  end
637
- Sunspot.session.should have_search_params(:boost, Proc.new {
640
+ Sunspot.session.should have_search_params(:boost) {
638
641
  keywords 'great pizza' do
639
642
  boost(2.0) do
640
643
  with :blog_id, 4
641
644
  end
642
645
  end
643
- })
646
+ }
644
647
  end
645
648
 
646
649
  it "should not match if boost query does not match" do
@@ -651,13 +654,13 @@ describe "Sunspot Matchers" do
651
654
  end
652
655
  end
653
656
  end
654
- Sunspot.session.should_not have_search_params(:boost, Proc.new {
657
+ Sunspot.session.should_not have_search_params(:boost) {
655
658
  keywords 'great pizza' do
656
659
  boost(2.0) do
657
660
  with :blog_id, 5
658
661
  end
659
662
  end
660
- })
663
+ }
661
664
  end
662
665
 
663
666
  it "should match if boost function matches" do
@@ -666,11 +669,11 @@ describe "Sunspot Matchers" do
666
669
  boost(function { sum(:average_rating, product(:popularity, 10)) })
667
670
  end
668
671
  end
669
- Sunspot.session.should have_search_params(:boost, Proc.new {
672
+ Sunspot.session.should have_search_params(:boost) {
670
673
  keywords 'great pizza' do
671
674
  boost(function { sum(:average_rating, product(:popularity, 10)) })
672
675
  end
673
- })
676
+ }
674
677
  end
675
678
 
676
679
  it "should not match if boost function does not match" do
@@ -679,11 +682,28 @@ describe "Sunspot Matchers" do
679
682
  boost(function { sum(:average_rating, product(:popularity, 10)) })
680
683
  end
681
684
  end
682
- Sunspot.session.should_not have_search_params(:boost, Proc.new {
685
+ Sunspot.session.should_not have_search_params(:boost) {
683
686
  keywords 'great pizza' do
684
687
  boost(function { sum(:average_rating, product(:popularity, 42)) })
685
688
  end
686
- })
689
+ }
690
+ end
691
+ end
692
+
693
+ describe "group matcher" do
694
+ it "should match if grouping a field" do
695
+ Sunspot.search(Post) do
696
+ keywords 'great pizza'
697
+ group :author_name
698
+ end
699
+ Sunspot.session.should have_search_params(:group, :author_name)
700
+ end
701
+
702
+ it "should match if grouping a field" do
703
+ Sunspot.search(Post) do
704
+ keywords 'great pizza'
705
+ end
706
+ Sunspot.session.should_not have_search_params(:group, :author_name)
687
707
  end
688
708
  end
689
709
 
@@ -728,8 +748,16 @@ describe "Sunspot Matchers" do
728
748
  end
729
749
 
730
750
  describe "have_searchable_field" do
751
+ context "it works with instances as well as classes" do
752
+ describe Post do
753
+ it { should have_searchable_field(:body) }
754
+ end
755
+ end
756
+
731
757
  it "should succeed if the model has the given field" do
732
758
  Post.should have_searchable_field(:body)
759
+ Post.should have_searchable_field(:author_name)
760
+ Post.should have_searchable_field(:blog_id)
733
761
  end
734
762
 
735
763
  it "should fail if the model does not have the given field" do
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_development_dependency "bundler", ">= 1.0.0"
18
18
  s.add_development_dependency "rspec", "~> 2.4.0"
19
- s.add_development_dependency "sunspot", "~> 1.3.0"
19
+ s.add_development_dependency "sunspot", "~> 2.0.0"
20
20
  s.add_development_dependency "rake"
21
21
 
22
22
  s.files = `git ls-files`.split("\n")