44require 'support/models/color'
55
66describe 'multi-search' do
7- def reset_indexes
7+ before do
88 [ Book , Color , Product ] . each do |klass |
99 klass . delete_all
10- klass . clear_index! ( true )
10+ klass . clear_index!
1111 end
12- end
1312
14- before do
15- reset_indexes
16-
17- Product . create! name : 'palm pixi plus' , href : 'ebay' , tags : [ 'terrible' ]
18- Product . create! name : 'lg vortex' , href : 'ebay' , tags : [ 'decent' ]
19- Product . create! name : 'palmpre' , href : 'ebay' , tags : [ 'discontinued' , 'worst phone ever' ]
13+ Product . insert_all ( [
14+ { name : 'palm pixi plus' , href : 'ebay' , tags : [ 'terrible' ] } ,
15+ { name : 'lg vortex' , href : 'ebay' , tags : [ 'decent' ] } ,
16+ { name : 'palmpre' , href : 'ebay' , tags : [ 'discontinued' , 'worst phone ever' ] }
17+ ] )
2018 Product . reindex!
2119
22- Color . create! name : 'blue' , short_name : 'blu' , hex : 0x0000FF
23- Color . create! name : 'black' , short_name : 'bla' , hex : 0x000000
24- Color . create! name : 'green' , short_name : 'gre' , hex : 0x00FF00
25-
26- Book . create! name : 'Steve Jobs' , author : 'Walter Isaacson'
27- Book . create! name : 'Moby Dick' , author : 'Herman Melville'
20+ Color . insert_all ( [
21+ { name : 'blue' , short_name : 'blu' , hex : 0x0000FF } ,
22+ { name : 'black' , short_name : 'bla' , hex : 0x000000 } ,
23+ { name : 'green' , short_name : 'gre' , hex : 0x00FF00 }
24+ ] )
25+ Color . reindex!
26+
27+ Book . insert_all ( [
28+ { name : 'Steve Jobs' , author : 'Walter Isaacson' } ,
29+ { name : 'Moby Dick' , author : 'Herman Melville' }
30+ ] )
31+ Book . reindex!
2832 end
2933
30- let! ( :palm_pixi_plus ) { Product . find_by name : 'palm pixi plus' }
31- let! ( :steve_jobs ) { Book . find_by name : 'Steve Jobs' }
32- let! ( :blue ) { Color . find_by name : 'blue' }
33- let! ( :black ) { Color . find_by name : 'black' }
34+ let ( :palm_pixi_plus ) { Product . find_by name : 'palm pixi plus' }
35+ let ( :steve_jobs ) { Book . find_by name : 'Steve Jobs' }
36+ let ( :blue ) { Color . find_by name : 'blue' }
37+ let ( :black ) { Color . find_by name : 'black' }
3438
3539 context 'with class keys' do
3640 it 'returns ORM records' do
@@ -40,8 +44,10 @@ def reset_indexes
4044 Color => { q : 'bl' }
4145 )
4246
43- expect ( results ) . to contain_exactly (
44- steve_jobs , palm_pixi_plus , blue , black
47+ expect ( results . to_h ) . to match (
48+ Book => [ steve_jobs ] ,
49+ Product => [ palm_pixi_plus ] ,
50+ Color => contain_exactly ( blue , black )
4551 )
4652 end
4753 end
@@ -65,11 +71,13 @@ def reset_indexes
6571 'colors' => { q : 'bl' , index_uid : Color . index . uid }
6672 )
6773
68- expect ( results ) . to contain_exactly (
69- a_hash_including ( 'author' => 'Walter Isaacson' , 'name' => 'Steve Jobs' ) ,
70- a_hash_including ( 'name' => 'palm pixi plus' ) ,
71- a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
72- a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
74+ expect ( results . to_h ) . to match (
75+ 'books' => [ a_hash_including ( 'author' => 'Walter Isaacson' , 'name' => 'Steve Jobs' ) ] ,
76+ 'products' => [ a_hash_including ( 'name' => 'palm pixi plus' ) ] ,
77+ 'colors' => contain_exactly (
78+ a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
79+ a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
80+ )
7381 )
7482 end
7583
@@ -82,10 +90,10 @@ def reset_indexes
8290 'nature_colors' => { q : 'green' , index_uid : index_uid }
8391 )
8492
85- expect ( results ) . to contain_exactly (
86- a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
87- a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' ) ,
88- a_hash_including ( 'name' => 'green' , 'short_name' => 'gre' )
93+ expect ( results . to_h ) . to match (
94+ 'bright_colors' => [ a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ] ,
95+ 'dark_colors' => [ a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' ) ] ,
96+ 'nature_colors' => [ a_hash_including ( 'name' => 'green' , 'short_name' => 'gre' ) ]
8997 )
9098 end
9199
@@ -97,8 +105,10 @@ def reset_indexes
97105 'colors' => { q : 'bl' , index_uid : Color . index . uid , class_name : 'Color' }
98106 )
99107
100- expect ( results ) . to contain_exactly (
101- steve_jobs , palm_pixi_plus , blue , black
108+ expect ( results . to_h ) . to match (
109+ 'books' => [ steve_jobs ] ,
110+ 'products' => [ palm_pixi_plus ] ,
111+ 'colors' => contain_exactly ( blue , black )
102112 )
103113 end
104114 end
@@ -113,11 +123,13 @@ def reset_indexes
113123 Color . index . uid => { q : 'bl' }
114124 )
115125
116- expect ( results ) . to contain_exactly (
117- a_hash_including ( 'author' => 'Walter Isaacson' , 'name' => 'Steve Jobs' ) ,
118- a_hash_including ( 'name' => 'palm pixi plus' ) ,
119- a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
120- a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
126+ expect ( results . to_h ) . to match (
127+ Book . index . uid => [ a_hash_including ( 'author' => 'Walter Isaacson' , 'name' => 'Steve Jobs' ) ] ,
128+ Product . index . uid . to_sym => [ a_hash_including ( 'name' => 'palm pixi plus' ) ] ,
129+ Color . index . uid => contain_exactly (
130+ a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
131+ a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
132+ )
121133 )
122134 end
123135
@@ -129,8 +141,10 @@ def reset_indexes
129141 Color . index . uid => { q : 'bl' , class_name : 'Color' }
130142 )
131143
132- expect ( results ) . to contain_exactly (
133- steve_jobs , palm_pixi_plus , blue , black
144+ expect ( results . to_h ) . to match (
145+ Book . index . uid => [ steve_jobs ] ,
146+ Product . index . uid . to_sym => [ palm_pixi_plus ] ,
147+ Color . index . uid => contain_exactly ( blue , black )
134148 )
135149 end
136150
@@ -154,10 +168,13 @@ def reset_indexes
154168 Color . index . uid => { q : 'bl' }
155169 )
156170
157- expect ( results ) . to contain_exactly (
158- steve_jobs , palm_pixi_plus ,
159- a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
160- a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
171+ expect ( results . to_h ) . to match (
172+ Book => [ steve_jobs ] ,
173+ Product . index_uid => [ palm_pixi_plus ] ,
174+ Color . index . uid => contain_exactly (
175+ a_hash_including ( 'name' => 'blue' , 'short_name' => 'blu' ) ,
176+ a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
177+ )
161178 )
162179 end
163180 end
@@ -172,9 +189,12 @@ def reset_indexes
172189 Color . index . uid => { q : 'bl' , page : 1 , 'hitsPerPage' => '1' }
173190 )
174191
175- expect ( results ) . to contain_exactly (
176- steve_jobs , palm_pixi_plus ,
177- a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
192+ expect ( results . to_h ) . to match (
193+ Book => [ steve_jobs ] ,
194+ Product => [ palm_pixi_plus ] ,
195+ Color . index_uid => contain_exactly (
196+ a_hash_including ( 'name' => 'black' , 'short_name' => 'bla' )
197+ )
178198 )
179199
180200 Meilisearch ::Rails . configuration [ :pagination_backend ] = nil
0 commit comments