@@ -37,6 +37,7 @@ public function test_update_adds_object_to_index()
37
37
$ table ->shouldReceive ('where ' )
38
38
->with ('id ' , '= ' , 1 )
39
39
->andReturnSelf ();
40
+
40
41
$ table ->shouldReceive ('update ' )
41
42
->with (['searchable ' => 'foo ' ]);
42
43
@@ -97,6 +98,24 @@ public function test_search()
97
98
98
99
$ engine ->search ($ builder );
99
100
}
101
+
102
+ public function test_search_with_soft_delete ()
103
+ {
104
+ list ($ engine , $ db ) = $ this ->getEngine ();
105
+
106
+ $ table = $ this ->setDbExpectations ($ db );
107
+
108
+ $ table ->shouldReceive ('skip ' )->with (0 )->andReturnSelf ()
109
+ ->shouldReceive ('limit ' )->with (5 )->andReturnSelf ()
110
+ ->shouldReceive ('where ' )->with ('bar ' , 1 )->andReturnSelf ()
111
+ ->shouldReceive ('where ' )->with ('deleted_at ' , null );
112
+ $ db ->shouldReceive ('select ' )->with (null , ['foo ' , 1 ]);
113
+
114
+ $ builder = new Builder (new TestWithSoftDeleteModel (), 'foo ' );
115
+ $ builder ->where ('bar ' , 1 )->take (5 );
116
+
117
+ $ engine ->search ($ builder );
118
+ }
100
119
101
120
public function test_map_correctly_maps_results_to_models ()
102
121
{
@@ -168,7 +187,7 @@ protected function setDbExpectations($db, $skip = 0, $limit = 5)
168
187
->shouldReceive ('orderBy ' )->with ('rank ' , 'desc ' )->andReturnSelf ()
169
188
->shouldReceive ('orderBy ' )->with ('id ' )->andReturnSelf ()
170
189
->shouldReceive ('toSql ' );
171
-
190
+
172
191
return $ table ;
173
192
}
174
193
}
@@ -227,3 +246,60 @@ public function searchableAdditionalArray()
227
246
return $ this ->searchableAdditionalArray ;
228
247
}
229
248
}
249
+
250
+ class TestWithSoftDeleteModel extends Model
251
+ {
252
+ use \Illuminate \Database \Eloquent \SoftDeletes;
253
+
254
+ public $ id = 1 ;
255
+
256
+ public $ text = 'Foo ' ;
257
+
258
+ protected $ searchableOptions = [
259
+ 'rank ' => [
260
+ 'fields ' => [
261
+ 'nullable ' => 'B ' ,
262
+ ],
263
+ ],
264
+ ];
265
+
266
+ protected $ searchableAdditionalArray = [];
267
+
268
+ public function searchableAs ()
269
+ {
270
+ return 'searchable ' ;
271
+ }
272
+
273
+ public function getKeyName ()
274
+ {
275
+ return 'id ' ;
276
+ }
277
+
278
+ public function getKey ()
279
+ {
280
+ return $ this ->id ;
281
+ }
282
+
283
+ public function getTable ()
284
+ {
285
+ return 'table ' ;
286
+ }
287
+
288
+ public function toSearchableArray ()
289
+ {
290
+ return [
291
+ 'text ' => $ this ->text ,
292
+ 'nullable ' => null ,
293
+ ];
294
+ }
295
+
296
+ public function searchableOptions ()
297
+ {
298
+ return $ this ->searchableOptions ;
299
+ }
300
+
301
+ public function searchableAdditionalArray ()
302
+ {
303
+ return $ this ->searchableAdditionalArray ;
304
+ }
305
+ }
0 commit comments