18
18
require 'spec_helper'
19
19
20
20
describe Elasticsearch ::Persistence ::Repository do
21
-
22
21
describe '#create' do
23
-
24
22
before ( :all ) do
25
23
class RepositoryWithoutDSL
26
24
include Elasticsearch ::Persistence ::Repository
@@ -38,7 +36,6 @@ class RepositoryWithoutDSL
38
36
end
39
37
40
38
context 'when options are provided' do
41
-
42
39
let ( :repository ) do
43
40
RepositoryWithoutDSL . create ( document_type : 'note' )
44
41
end
@@ -49,7 +46,6 @@ class RepositoryWithoutDSL
49
46
end
50
47
51
48
context 'when a block is passed' do
52
-
53
49
let ( :repository ) do
54
50
RepositoryWithoutDSL . create ( document_type : 'note' ) do
55
51
mapping dynamic : 'strict' do
@@ -59,11 +55,10 @@ class RepositoryWithoutDSL
59
55
end
60
56
61
57
it 'executes the block on the instance' do
62
- expect ( repository . mapping . to_hash ) . to eq ( note : { dynamic : 'strict' , properties : { foo : { type : 'text' } } } )
58
+ expect ( repository . mapping . to_hash ) . to eq ( { dynamic : 'strict' , properties : { foo : { type : 'text' } } } )
63
59
end
64
60
65
61
context 'when options are provided in the args and set in the block' do
66
-
67
62
let ( :repository ) do
68
63
RepositoryWithoutDSL . create ( mapping : double ( 'mapping' , to_hash : { } ) , document_type : 'note' ) do
69
64
mapping dynamic : 'strict' do
@@ -80,7 +75,6 @@ class RepositoryWithoutDSL
80
75
end
81
76
82
77
describe '#initialize' do
83
-
84
78
before ( :all ) do
85
79
class RepositoryWithoutDSL
86
80
include Elasticsearch ::Persistence ::Repository
@@ -98,7 +92,6 @@ class RepositoryWithoutDSL
98
92
end
99
93
100
94
context 'when options are not provided' do
101
-
102
95
let ( :repository ) do
103
96
RepositoryWithoutDSL . new
104
97
end
@@ -118,7 +111,6 @@ class RepositoryWithoutDSL
118
111
end
119
112
120
113
context 'when options are provided' do
121
-
122
114
let ( :client ) do
123
115
Elasticsearch ::Client . new
124
116
end
@@ -146,13 +138,11 @@ class RepositoryWithoutDSL
146
138
end
147
139
148
140
context 'when the DSL module is included' do
149
-
150
141
before ( :all ) do
151
142
class RepositoryWithDSL
152
143
include Elasticsearch ::Persistence ::Repository
153
144
include Elasticsearch ::Persistence ::Repository ::DSL
154
145
155
- document_type 'note'
156
146
index_name 'notes_repo'
157
147
klass Hash
158
148
client DEFAULT_CLIENT
@@ -179,7 +169,6 @@ class RepositoryWithDSL
179
169
end
180
170
181
171
context '#client' do
182
-
183
172
it 'allows the value to be set only once on the class' do
184
173
RepositoryWithDSL . client ( double ( 'client' , class : 'other_client' ) )
185
174
expect ( RepositoryWithDSL . client ) . to be ( DEFAULT_CLIENT )
@@ -199,7 +188,6 @@ class RepositoryWithDSL
199
188
end
200
189
201
190
context '#klass' do
202
-
203
191
it 'allows the value to be set only once on the class' do
204
192
RepositoryWithDSL . klass ( Array )
205
193
expect ( RepositoryWithDSL . klass ) . to eq ( Hash )
@@ -229,28 +217,7 @@ class RepositoryWithDSL
229
217
end
230
218
end
231
219
232
- context '#document_type' do
233
-
234
- it 'allows the value to be set only once on the class' do
235
- RepositoryWithDSL . document_type ( 'other_note' )
236
- expect ( RepositoryWithDSL . document_type ) . to eq ( 'note' )
237
- end
238
-
239
- it 'sets the value at the class level' do
240
- expect ( RepositoryWithDSL . document_type ) . to eq ( 'note' )
241
- end
242
-
243
- it 'sets the value as the default at the instance level' do
244
- expect ( RepositoryWithDSL . new . document_type ) . to eq ( 'note' )
245
- end
246
-
247
- it 'allows the value to be overridden with options on the instance' do
248
- expect ( RepositoryWithDSL . new ( document_type : 'other_note' ) . document_type ) . to eq ( 'other_note' )
249
- end
250
- end
251
-
252
220
context '#index_name' do
253
-
254
221
it 'allows the value to be set only once on the class' do
255
222
RepositoryWithDSL . index_name ( 'other_name' )
256
223
expect ( RepositoryWithDSL . index_name ) . to eq ( 'notes_repo' )
@@ -270,16 +237,14 @@ class RepositoryWithDSL
270
237
end
271
238
272
239
describe '#create_index!' do
273
-
274
240
context 'when the method is called on an instance' do
275
-
276
241
let ( :repository ) do
277
242
RepositoryWithDSL . new
278
243
end
279
244
280
245
before do
281
246
begin ; repository . delete_index! ; rescue ; end
282
- repository . create_index! ( include_type_name : true )
247
+ repository . create_index!
283
248
end
284
249
285
250
it 'creates the index' do
@@ -288,7 +253,6 @@ class RepositoryWithDSL
288
253
end
289
254
290
255
context 'when the method is called on the class' do
291
-
292
256
it 'raises a NotImplementedError' do
293
257
expect {
294
258
RepositoryWithDSL . create_index!
@@ -298,9 +262,7 @@ class RepositoryWithDSL
298
262
end
299
263
300
264
describe '#delete_index!' do
301
-
302
265
context 'when the method is called on an instance' do
303
-
304
266
let ( :repository ) do
305
267
RepositoryWithDSL . new
306
268
end
@@ -316,7 +278,6 @@ class RepositoryWithDSL
316
278
end
317
279
318
280
context 'when the method is called on the class' do
319
-
320
281
it 'raises a NotImplementedError' do
321
282
expect {
322
283
RepositoryWithDSL . delete_index!
@@ -326,15 +287,13 @@ class RepositoryWithDSL
326
287
end
327
288
328
289
describe '#refresh_index!' do
329
-
330
290
context 'when the method is called on an instance' do
331
-
332
291
let ( :repository ) do
333
292
RepositoryWithDSL . new
334
293
end
335
294
336
295
before do
337
- repository . create_index! ( include_type_name : true )
296
+ repository . create_index!
338
297
end
339
298
340
299
it 'refreshes the index' do
@@ -343,7 +302,6 @@ class RepositoryWithDSL
343
302
end
344
303
345
304
context 'when the method is called on the class' do
346
-
347
305
it 'raises a NotImplementedError' do
348
306
expect {
349
307
RepositoryWithDSL . refresh_index!
@@ -353,15 +311,13 @@ class RepositoryWithDSL
353
311
end
354
312
355
313
describe '#index_exists?' do
356
-
357
314
context 'when the method is called on an instance' do
358
-
359
315
let ( :repository ) do
360
316
RepositoryWithDSL . new
361
317
end
362
318
363
319
before do
364
- repository . create_index! ( include_type_name : true )
320
+ repository . create_index!
365
321
end
366
322
367
323
it 'determines if the index exists' do
@@ -377,7 +333,6 @@ class RepositoryWithDSL
377
333
end
378
334
379
335
context 'when the method is called on the class' do
380
-
381
336
it 'raises a NotImplementedError' do
382
337
expect {
383
338
RepositoryWithDSL . index_exists?
@@ -387,13 +342,15 @@ class RepositoryWithDSL
387
342
end
388
343
389
344
describe '#mapping' do
390
-
391
345
let ( :expected_mapping ) do
392
- { note : { dynamic : 'strict' ,
393
- properties : { foo : { type : 'object' ,
394
- properties : { bar : { type : 'text' } } } ,
395
- baz : { type : 'text' } }
396
- }
346
+ {
347
+ dynamic : 'strict' ,
348
+ properties : {
349
+ foo : {
350
+ type : 'object' ,
351
+ properties : { bar : { type : 'text' } } } ,
352
+ baz : { type : 'text' }
353
+ }
397
354
}
398
355
end
399
356
@@ -410,7 +367,6 @@ class RepositoryWithDSL
410
367
end
411
368
412
369
context 'when the instance has a different document type' do
413
-
414
370
let ( :expected_mapping ) do
415
371
{ other_note : { dynamic : 'strict' ,
416
372
properties : { foo : { type : 'object' ,
@@ -427,7 +383,6 @@ class RepositoryWithDSL
427
383
end
428
384
429
385
describe '#settings' do
430
-
431
386
it 'sets the value at the class level' do
432
387
expect ( RepositoryWithDSL . settings . to_hash ) . to eq ( number_of_shards : 1 , number_of_replicas : 0 )
433
388
end
@@ -443,7 +398,6 @@ class RepositoryWithDSL
443
398
end
444
399
445
400
context 'when the DSL module is not included' do
446
-
447
401
before ( :all ) do
448
402
class RepositoryWithoutDSL
449
403
include Elasticsearch ::Persistence ::Repository
@@ -546,26 +500,6 @@ class RepositoryWithoutDSL
546
500
let ( :repository ) do
547
501
RepositoryWithoutDSL . new ( client : DEFAULT_CLIENT , document_type : 'mytype' )
548
502
end
549
-
550
- context 'when the server is version >= 7.0' , if : server_version > '7.0' do
551
-
552
- context 'when the include_type_name option is specified' do
553
-
554
- it 'creates an index' do
555
- repository . create_index! ( include_type_name : true )
556
- expect ( repository . index_exists? ) . to eq ( true )
557
- end
558
- end
559
-
560
- context 'when the include_type_name option is not specified' do
561
-
562
- it 'raises an error' do
563
- expect {
564
- repository . create_index!
565
- } . to raise_exception ( Elastic ::Transport ::Transport ::Errors ::BadRequest )
566
- end
567
- end
568
- end
569
503
end
570
504
end
571
505
@@ -582,7 +516,7 @@ class RepositoryWithoutDSL
582
516
end
583
517
584
518
it 'deletes an index' do
585
- repository . create_index! ( include_type_name : true )
519
+ repository . create_index!
586
520
repository . delete_index!
587
521
expect ( repository . index_exists? ) . to eq ( false )
588
522
end
@@ -605,7 +539,7 @@ class RepositoryWithoutDSL
605
539
end
606
540
607
541
it 'refreshes an index' do
608
- repository . create_index! ( include_type_name : true )
542
+ repository . create_index!
609
543
expect ( repository . refresh_index! [ '_shards' ] ) . to be_a ( Hash )
610
544
end
611
545
end
@@ -627,7 +561,7 @@ class RepositoryWithoutDSL
627
561
end
628
562
629
563
it 'returns whether the index exists' do
630
- repository . create_index! ( include_type_name : true )
564
+ repository . create_index!
631
565
expect ( repository . index_exists? ) . to be ( true )
632
566
end
633
567
end
@@ -651,10 +585,14 @@ class RepositoryWithoutDSL
651
585
context 'when a block is passed to the create method' do
652
586
653
587
let ( :expected_mapping ) do
654
- { note : { dynamic : 'strict' ,
655
- properties : { foo : { type : 'object' ,
656
- properties : { bar : { type : 'text' } } } ,
657
- baz : { type : 'text' } }
588
+ {
589
+ dynamic : 'strict' ,
590
+ properties : {
591
+ foo : {
592
+ type : 'object' ,
593
+ properties : { bar : { type : 'text' } }
594
+ } ,
595
+ baz : { type : 'text' }
658
596
}
659
597
}
660
598
end
@@ -695,7 +633,6 @@ class RepositoryWithoutDSL
695
633
end
696
634
697
635
describe '#settings' do
698
-
699
636
it 'does not define the method at the class level' do
700
637
expect {
701
638
RepositoryWithoutDSL . settings
@@ -711,7 +648,6 @@ class RepositoryWithoutDSL
711
648
end
712
649
713
650
context 'when a block is passed to the #create method' do
714
-
715
651
let ( :repository ) do
716
652
RepositoryWithoutDSL . create ( document_type : 'note' ) do
717
653
settings number_of_shards : 1 , number_of_replicas : 0
@@ -723,13 +659,16 @@ class RepositoryWithoutDSL
723
659
end
724
660
725
661
context 'when a mapping is set in the block as well' do
726
-
727
662
let ( :expected_mapping ) do
728
- { note : { dynamic : 'strict' ,
729
- properties : { foo : { type : 'object' ,
730
- properties : { bar : { type : 'text' } } } ,
731
- baz : { type : 'text' } }
732
- }
663
+ {
664
+ dynamic : 'strict' ,
665
+ properties : {
666
+ foo : {
667
+ type : 'object' ,
668
+ properties : { bar : { type : 'text' } }
669
+ } ,
670
+ baz : { type : 'text' }
671
+ }
733
672
}
734
673
end
735
674
0 commit comments