@@ -91,6 +91,8 @@ def reset_indexes
91
91
92
92
context 'when :class_name is also present' do
93
93
it 'loads results from the correct models' do
94
+ allow ( Meilisearch ::Rails . logger ) . to receive ( :warn ) . and_return ( nil )
95
+
94
96
results = Meilisearch ::Rails . multi_search (
95
97
'books' => { q : 'Steve' , index_uid : Book . index . uid , class_name : 'Book' } ,
96
98
'products' => { q : 'palm' , limit : 1 , index_uid : Product . index . uid , class_name : 'Product' } ,
@@ -122,6 +124,18 @@ def reset_indexes
122
124
end
123
125
124
126
context 'when class_name is specified' do
127
+ let ( :logger ) { instance_double ( 'Logger' , warn : nil ) }
128
+
129
+ before do
130
+ allow ( Meilisearch ::Rails ) . to receive ( :logger ) . and_return ( logger )
131
+ end
132
+
133
+ it 'warns about deprecation' do
134
+ results = Meilisearch ::Rails . multi_search ( Book . index . uid => { q : 'Steve' , class_name : 'Book' } )
135
+ expect ( results . to_h [ Book . index . uid ] ) . to contain_exactly ( steve_jobs )
136
+ expect ( logger ) . to have_received ( :warn ) . with ( a_string_matching ( ':class_name' ) )
137
+ end
138
+
125
139
it 'returns ORM records' do
126
140
results = Meilisearch ::Rails . multi_search (
127
141
Book . index . uid => { q : 'Steve' , class_name : 'Book' } ,
@@ -150,7 +164,7 @@ def reset_indexes
150
164
it 'returns a mixture of ORM records and hashes' do
151
165
results = Meilisearch ::Rails . multi_search (
152
166
Book => { q : 'Steve' } ,
153
- Product . index . uid => { q : 'palm' , limit : 1 , class_name : ' Product' } ,
167
+ Product . index . uid => { q : 'palm' , limit : 1 , collection : Product } ,
154
168
Color . index . uid => { q : 'bl' }
155
169
)
156
170
@@ -183,8 +197,8 @@ def reset_indexes
183
197
184
198
context 'with collections' do
185
199
it 'fetches items from the given collection' do
186
- results = MeiliSearch ::Rails . multi_search (
187
- Product . index . uid => { q : 'palm' , class_name : 'Product ', collection : Product . where ( 'tags LIKE "%terrible%"' ) } ,
200
+ results = Meilisearch ::Rails . multi_search (
201
+ Product => { q : 'palm' , collection : Product . where ( 'tags LIKE "%terrible%"' ) } ,
188
202
Color => { q : 'bl' , collection : Color . where ( short_name : 'bla' ) }
189
203
)
190
204
@@ -194,15 +208,15 @@ def reset_indexes
194
208
end
195
209
196
210
it 'infers the model' do
197
- results = MeiliSearch ::Rails . multi_search (
211
+ results = Meilisearch ::Rails . multi_search (
198
212
'colors' => { q : 'bl' , collection : Color . all , index_uid : Color . index . uid }
199
213
)
200
214
201
215
expect ( results . to_h [ 'colors' ] ) . to contain_exactly ( blue , black )
202
216
end
203
217
204
218
it 'infers the index as well as the model' do
205
- results = MeiliSearch ::Rails . multi_search (
219
+ results = Meilisearch ::Rails . multi_search (
206
220
'colors' => { q : 'bl' , collection : Color }
207
221
)
208
222
0 commit comments