@@ -12,6 +12,8 @@ def self.foo
12
12
end
13
13
end
14
14
15
+ class NotFound < Exception ; end
16
+
15
17
context "Settings class" do
16
18
should "be convertible to hash" do
17
19
hash = { foo : 'bar' }
@@ -382,19 +384,40 @@ class ::DummyIndexingModelForRecreate
382
384
end
383
385
end
384
386
385
- should "delete the index without raising exception" do
387
+ should "delete the index without raising exception when the index is not found " do
386
388
client = stub ( 'client' )
387
389
indices = stub ( 'indices' )
388
390
client . stubs ( :indices ) . returns ( indices )
389
391
390
- indices . expects ( :delete ) . returns ( { } ) . then . raises ( Exception ) . at_least_once
392
+ indices . expects ( :delete ) . returns ( { } ) . then . raises ( NotFound ) . at_least_once
391
393
392
394
DummyIndexingModelForRecreate . expects ( :client ) . returns ( client ) . at_least_once
393
395
394
- assert_nothing_raised do
395
- DummyIndexingModelForRecreate . delete_index!
396
- DummyIndexingModelForRecreate . delete_index!
397
- end
396
+ assert_nothing_raised { DummyIndexingModelForRecreate . delete_index! force : true }
397
+ end
398
+
399
+ should "raise an exception without the force option" do
400
+ client = stub ( 'client' )
401
+ indices = stub ( 'indices' )
402
+ client . stubs ( :indices ) . returns ( indices )
403
+
404
+ indices . expects ( :delete ) . raises ( NotFound )
405
+
406
+ DummyIndexingModelForRecreate . expects ( :client ) . returns ( client )
407
+
408
+ assert_raise { DummyIndexingModelForRecreate . delete_index! }
409
+ end
410
+
411
+ should "raise a regular exception when deleting the index" do
412
+ client = stub ( 'client' )
413
+ indices = stub ( 'indices' )
414
+ client . stubs ( :indices ) . returns ( indices )
415
+
416
+ indices . expects ( :delete ) . raises ( Exception )
417
+
418
+ DummyIndexingModelForRecreate . expects ( :client ) . returns ( client )
419
+
420
+ assert_raise { DummyIndexingModelForRecreate . delete_index! force : true }
398
421
end
399
422
400
423
should "create the index with correct settings and mappings when it doesn't exist" do
@@ -430,19 +453,18 @@ class ::DummyIndexingModelForRecreate
430
453
assert_nothing_raised { DummyIndexingModelForRecreate . create_index! }
431
454
end
432
455
433
- should "not raise exception during index creation" do
456
+ should "raise exception during index creation" do
434
457
client = stub ( 'client' )
435
458
indices = stub ( 'indices' )
436
459
client . stubs ( :indices ) . returns ( indices )
437
460
461
+ indices . expects ( :delete ) . returns ( { } )
438
462
indices . expects ( :exists ) . returns ( false )
439
- indices . expects ( :create ) . raises ( Exception ) . at_least_once
463
+ indices . expects ( :create ) . raises ( Exception )
440
464
441
465
DummyIndexingModelForRecreate . expects ( :client ) . returns ( client ) . at_least_once
442
466
443
- assert_nothing_raised do
444
- DummyIndexingModelForRecreate . create_index!
445
- end
467
+ assert_raise { DummyIndexingModelForRecreate . create_index! force : true }
446
468
end
447
469
448
470
should "delete the index first with the force option" do
@@ -461,7 +483,19 @@ class ::DummyIndexingModelForRecreate
461
483
end
462
484
end
463
485
464
- should "refresh the index without raising exception" do
486
+ should "refresh the index without raising exception with the force option" do
487
+ client = stub ( 'client' )
488
+ indices = stub ( 'indices' )
489
+ client . stubs ( :indices ) . returns ( indices )
490
+
491
+ indices . expects ( :refresh ) . returns ( { } ) . then . raises ( NotFound ) . at_least_once
492
+
493
+ DummyIndexingModelForRecreate . expects ( :client ) . returns ( client ) . at_least_once
494
+
495
+ assert_nothing_raised { DummyIndexingModelForRecreate . refresh_index! force : true }
496
+ end
497
+
498
+ should "raise a regular exception when refreshing the index" do
465
499
client = stub ( 'client' )
466
500
indices = stub ( 'indices' )
467
501
client . stubs ( :indices ) . returns ( indices )
@@ -470,10 +504,7 @@ class ::DummyIndexingModelForRecreate
470
504
471
505
DummyIndexingModelForRecreate . expects ( :client ) . returns ( client ) . at_least_once
472
506
473
- assert_nothing_raised do
474
- DummyIndexingModelForRecreate . refresh_index!
475
- DummyIndexingModelForRecreate . refresh_index!
476
- end
507
+ assert_nothing_raised { DummyIndexingModelForRecreate . refresh_index! force : true }
477
508
end
478
509
479
510
context "with a custom index name" do
0 commit comments