1818require 'spec_helper'
1919
2020describe Elasticsearch ::Persistence ::Repository do
21-
2221 describe '#create' do
23-
2422 before ( :all ) do
2523 class RepositoryWithoutDSL
2624 include Elasticsearch ::Persistence ::Repository
@@ -38,7 +36,6 @@ class RepositoryWithoutDSL
3836 end
3937
4038 context 'when options are provided' do
41-
4239 let ( :repository ) do
4340 RepositoryWithoutDSL . create ( document_type : 'note' )
4441 end
@@ -49,7 +46,6 @@ class RepositoryWithoutDSL
4946 end
5047
5148 context 'when a block is passed' do
52-
5349 let ( :repository ) do
5450 RepositoryWithoutDSL . create ( document_type : 'note' ) do
5551 mapping dynamic : 'strict' do
@@ -59,11 +55,10 @@ class RepositoryWithoutDSL
5955 end
6056
6157 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' } } } )
6359 end
6460
6561 context 'when options are provided in the args and set in the block' do
66-
6762 let ( :repository ) do
6863 RepositoryWithoutDSL . create ( mapping : double ( 'mapping' , to_hash : { } ) , document_type : 'note' ) do
6964 mapping dynamic : 'strict' do
@@ -80,7 +75,6 @@ class RepositoryWithoutDSL
8075 end
8176
8277 describe '#initialize' do
83-
8478 before ( :all ) do
8579 class RepositoryWithoutDSL
8680 include Elasticsearch ::Persistence ::Repository
@@ -98,7 +92,6 @@ class RepositoryWithoutDSL
9892 end
9993
10094 context 'when options are not provided' do
101-
10295 let ( :repository ) do
10396 RepositoryWithoutDSL . new
10497 end
@@ -118,7 +111,6 @@ class RepositoryWithoutDSL
118111 end
119112
120113 context 'when options are provided' do
121-
122114 let ( :client ) do
123115 Elasticsearch ::Client . new
124116 end
@@ -146,13 +138,11 @@ class RepositoryWithoutDSL
146138 end
147139
148140 context 'when the DSL module is included' do
149-
150141 before ( :all ) do
151142 class RepositoryWithDSL
152143 include Elasticsearch ::Persistence ::Repository
153144 include Elasticsearch ::Persistence ::Repository ::DSL
154145
155- document_type 'note'
156146 index_name 'notes_repo'
157147 klass Hash
158148 client DEFAULT_CLIENT
@@ -179,7 +169,6 @@ class RepositoryWithDSL
179169 end
180170
181171 context '#client' do
182-
183172 it 'allows the value to be set only once on the class' do
184173 RepositoryWithDSL . client ( double ( 'client' , class : 'other_client' ) )
185174 expect ( RepositoryWithDSL . client ) . to be ( DEFAULT_CLIENT )
@@ -199,7 +188,6 @@ class RepositoryWithDSL
199188 end
200189
201190 context '#klass' do
202-
203191 it 'allows the value to be set only once on the class' do
204192 RepositoryWithDSL . klass ( Array )
205193 expect ( RepositoryWithDSL . klass ) . to eq ( Hash )
@@ -229,28 +217,7 @@ class RepositoryWithDSL
229217 end
230218 end
231219
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-
252220 context '#index_name' do
253-
254221 it 'allows the value to be set only once on the class' do
255222 RepositoryWithDSL . index_name ( 'other_name' )
256223 expect ( RepositoryWithDSL . index_name ) . to eq ( 'notes_repo' )
@@ -270,16 +237,14 @@ class RepositoryWithDSL
270237 end
271238
272239 describe '#create_index!' do
273-
274240 context 'when the method is called on an instance' do
275-
276241 let ( :repository ) do
277242 RepositoryWithDSL . new
278243 end
279244
280245 before do
281246 begin ; repository . delete_index! ; rescue ; end
282- repository . create_index! ( include_type_name : true )
247+ repository . create_index!
283248 end
284249
285250 it 'creates the index' do
@@ -288,7 +253,6 @@ class RepositoryWithDSL
288253 end
289254
290255 context 'when the method is called on the class' do
291-
292256 it 'raises a NotImplementedError' do
293257 expect {
294258 RepositoryWithDSL . create_index!
@@ -298,9 +262,7 @@ class RepositoryWithDSL
298262 end
299263
300264 describe '#delete_index!' do
301-
302265 context 'when the method is called on an instance' do
303-
304266 let ( :repository ) do
305267 RepositoryWithDSL . new
306268 end
@@ -316,7 +278,6 @@ class RepositoryWithDSL
316278 end
317279
318280 context 'when the method is called on the class' do
319-
320281 it 'raises a NotImplementedError' do
321282 expect {
322283 RepositoryWithDSL . delete_index!
@@ -326,15 +287,13 @@ class RepositoryWithDSL
326287 end
327288
328289 describe '#refresh_index!' do
329-
330290 context 'when the method is called on an instance' do
331-
332291 let ( :repository ) do
333292 RepositoryWithDSL . new
334293 end
335294
336295 before do
337- repository . create_index! ( include_type_name : true )
296+ repository . create_index!
338297 end
339298
340299 it 'refreshes the index' do
@@ -343,7 +302,6 @@ class RepositoryWithDSL
343302 end
344303
345304 context 'when the method is called on the class' do
346-
347305 it 'raises a NotImplementedError' do
348306 expect {
349307 RepositoryWithDSL . refresh_index!
@@ -353,15 +311,13 @@ class RepositoryWithDSL
353311 end
354312
355313 describe '#index_exists?' do
356-
357314 context 'when the method is called on an instance' do
358-
359315 let ( :repository ) do
360316 RepositoryWithDSL . new
361317 end
362318
363319 before do
364- repository . create_index! ( include_type_name : true )
320+ repository . create_index!
365321 end
366322
367323 it 'determines if the index exists' do
@@ -377,7 +333,6 @@ class RepositoryWithDSL
377333 end
378334
379335 context 'when the method is called on the class' do
380-
381336 it 'raises a NotImplementedError' do
382337 expect {
383338 RepositoryWithDSL . index_exists?
@@ -387,13 +342,15 @@ class RepositoryWithDSL
387342 end
388343
389344 describe '#mapping' do
390-
391345 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+ }
397354 }
398355 end
399356
@@ -410,7 +367,6 @@ class RepositoryWithDSL
410367 end
411368
412369 context 'when the instance has a different document type' do
413-
414370 let ( :expected_mapping ) do
415371 { other_note : { dynamic : 'strict' ,
416372 properties : { foo : { type : 'object' ,
@@ -427,7 +383,6 @@ class RepositoryWithDSL
427383 end
428384
429385 describe '#settings' do
430-
431386 it 'sets the value at the class level' do
432387 expect ( RepositoryWithDSL . settings . to_hash ) . to eq ( number_of_shards : 1 , number_of_replicas : 0 )
433388 end
@@ -443,7 +398,6 @@ class RepositoryWithDSL
443398 end
444399
445400 context 'when the DSL module is not included' do
446-
447401 before ( :all ) do
448402 class RepositoryWithoutDSL
449403 include Elasticsearch ::Persistence ::Repository
@@ -546,26 +500,6 @@ class RepositoryWithoutDSL
546500 let ( :repository ) do
547501 RepositoryWithoutDSL . new ( client : DEFAULT_CLIENT , document_type : 'mytype' )
548502 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
569503 end
570504 end
571505
@@ -582,7 +516,7 @@ class RepositoryWithoutDSL
582516 end
583517
584518 it 'deletes an index' do
585- repository . create_index! ( include_type_name : true )
519+ repository . create_index!
586520 repository . delete_index!
587521 expect ( repository . index_exists? ) . to eq ( false )
588522 end
@@ -605,7 +539,7 @@ class RepositoryWithoutDSL
605539 end
606540
607541 it 'refreshes an index' do
608- repository . create_index! ( include_type_name : true )
542+ repository . create_index!
609543 expect ( repository . refresh_index! [ '_shards' ] ) . to be_a ( Hash )
610544 end
611545 end
@@ -627,7 +561,7 @@ class RepositoryWithoutDSL
627561 end
628562
629563 it 'returns whether the index exists' do
630- repository . create_index! ( include_type_name : true )
564+ repository . create_index!
631565 expect ( repository . index_exists? ) . to be ( true )
632566 end
633567 end
@@ -651,10 +585,14 @@ class RepositoryWithoutDSL
651585 context 'when a block is passed to the create method' do
652586
653587 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' }
658596 }
659597 }
660598 end
@@ -695,7 +633,6 @@ class RepositoryWithoutDSL
695633 end
696634
697635 describe '#settings' do
698-
699636 it 'does not define the method at the class level' do
700637 expect {
701638 RepositoryWithoutDSL . settings
@@ -711,7 +648,6 @@ class RepositoryWithoutDSL
711648 end
712649
713650 context 'when a block is passed to the #create method' do
714-
715651 let ( :repository ) do
716652 RepositoryWithoutDSL . create ( document_type : 'note' ) do
717653 settings number_of_shards : 1 , number_of_replicas : 0
@@ -723,13 +659,16 @@ class RepositoryWithoutDSL
723659 end
724660
725661 context 'when a mapping is set in the block as well' do
726-
727662 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+ }
733672 }
734673 end
735674
0 commit comments