@@ -14,6 +14,10 @@ class UserRepo
14
14
end
15
15
end
16
16
17
+ after do
18
+ begin ; DEFAULT_REPOSITORY . delete_index! ; rescue ; end
19
+ end
20
+
17
21
describe '#initialize' do
18
22
19
23
context 'when options are not provided' do
@@ -118,19 +122,13 @@ class UserRepo
118
122
119
123
describe 'class methods' do
120
124
121
- before do
122
- if defined? ( NoteRepository )
123
- Object . send ( :remove_const , NoteRepository . name )
124
- end
125
+ before ( :all ) do
125
126
class NoteRepository
126
127
include Elasticsearch ::Persistence ::Repository
127
128
128
129
document_type 'note'
129
-
130
130
index_name 'notes_repo'
131
-
132
131
klass Hash
133
-
134
132
client ( _class : 'client' )
135
133
136
134
settings number_of_shards : 1 , number_of_replicas : 0 do
@@ -144,6 +142,16 @@ class NoteRepository
144
142
end
145
143
end
146
144
145
+ after ( :all ) do
146
+ if defined? ( NoteRepository )
147
+ Object . send ( :remove_const , NoteRepository . name )
148
+ end
149
+ end
150
+
151
+ after do
152
+ begin ; NoteRepository . delete_index! ; rescue ; end
153
+ end
154
+
147
155
context '#client' do
148
156
149
157
it 'allows the value to be set only once' do
@@ -160,7 +168,7 @@ class NoteRepository
160
168
end
161
169
162
170
it 'allows the value to be overwritten with options on the instance' do
163
- expect ( NoteRepository . new ( client : double ( 'client' , class : 'other_client ' ) ) . client . class ) . to eq ( 'other_client ' )
171
+ expect ( NoteRepository . new ( client : double ( 'client' , instance : 'other ' ) ) . client . instance ) . to eq ( 'other ' )
164
172
end
165
173
end
166
174
@@ -239,12 +247,33 @@ class NoteRepository
239
247
240
248
context 'when the method is called on an instance' do
241
249
250
+ let ( :repository ) do
251
+ DEFAULT_REPOSITORY
252
+ end
253
+
242
254
before do
243
- DEFAULT_REPOSITORY . create_index!
255
+ begin ; repository . delete_index! ; rescue ; end
256
+ repository . create_index!
244
257
end
245
258
246
259
it 'creates the index' do
247
- expect ( DEFAULT_REPOSITORY . index_exists? ) . to be ( true )
260
+ expect ( repository . index_exists? ) . to be ( true )
261
+ end
262
+ end
263
+
264
+ context 'when the method is called on the class' do
265
+
266
+ let ( :repository ) do
267
+ DEFAULT_REPOSITORY . class
268
+ end
269
+
270
+ before do
271
+ begin ; repository . delete_index! ; rescue ; end
272
+ repository . create_index!
273
+ end
274
+
275
+ it 'creates the index' do
276
+ expect ( repository . index_exists? ) . to be ( true )
248
277
end
249
278
end
250
279
end
@@ -253,13 +282,33 @@ class NoteRepository
253
282
254
283
context 'when the method is called on an instance' do
255
284
285
+ let ( :repository ) do
286
+ DEFAULT_REPOSITORY
287
+ end
288
+
256
289
before do
257
- DEFAULT_REPOSITORY . create_index!
258
- DEFAULT_REPOSITORY . delete_index!
290
+ repository . create_index!
291
+ begin ; repository . delete_index! ; rescue ; end
259
292
end
260
293
261
294
it 'creates the index' do
262
- expect ( DEFAULT_REPOSITORY . index_exists? ) . to be ( false )
295
+ expect ( repository . index_exists? ) . to be ( false )
296
+ end
297
+ end
298
+
299
+ context 'when the method is called on the class' do
300
+
301
+ let ( :repository ) do
302
+ DEFAULT_REPOSITORY . class
303
+ end
304
+
305
+ before do
306
+ begin ; repository . delete_index! ; rescue ; end
307
+ repository . create_index!
308
+ end
309
+
310
+ it 'creates the index' do
311
+ expect ( repository . index_exists? ) . to be ( true )
263
312
end
264
313
end
265
314
end
@@ -268,12 +317,31 @@ class NoteRepository
268
317
269
318
context 'when the method is called on an instance' do
270
319
320
+ let ( :repository ) do
321
+ DEFAULT_REPOSITORY
322
+ end
323
+
271
324
before do
272
- DEFAULT_REPOSITORY . create_index!
325
+ repository . create_index!
273
326
end
274
327
275
328
it 'creates the index' do
276
- expect ( DEFAULT_REPOSITORY . refresh_index! [ '_shards' ] ) . to be_a ( Hash )
329
+ expect ( repository . refresh_index! [ '_shards' ] ) . to be_a ( Hash )
330
+ end
331
+ end
332
+
333
+ context 'when the method is called on the class' do
334
+
335
+ let ( :repository ) do
336
+ DEFAULT_REPOSITORY . class
337
+ end
338
+
339
+ before do
340
+ repository . create_index!
341
+ end
342
+
343
+ it 'creates the index' do
344
+ expect ( repository . refresh_index! [ '_shards' ] ) . to be_a ( Hash )
277
345
end
278
346
end
279
347
end
@@ -282,12 +350,31 @@ class NoteRepository
282
350
283
351
context 'when the method is called on an instance' do
284
352
353
+ let ( :repository ) do
354
+ DEFAULT_REPOSITORY
355
+ end
356
+
285
357
before do
286
- DEFAULT_REPOSITORY . create_index!
358
+ repository . create_index!
287
359
end
288
360
289
361
it 'creates the index' do
290
- expect ( DEFAULT_REPOSITORY . index_exists? ) . to be ( true )
362
+ expect ( repository . index_exists? ) . to be ( true )
363
+ end
364
+ end
365
+
366
+ context 'when the method is called on the class' do
367
+
368
+ let ( :repository ) do
369
+ DEFAULT_REPOSITORY . class
370
+ end
371
+
372
+ before do
373
+ repository . create_index!
374
+ end
375
+
376
+ it 'creates the index' do
377
+ expect ( repository . index_exists? ) . to be ( true )
291
378
end
292
379
end
293
380
end
@@ -303,11 +390,6 @@ class NoteRepository
303
390
}
304
391
end
305
392
306
- it 'allows the value to be set only once' do
307
- NoteRepository . mapping ( dynamic : 'strict' ) { indexes :foo , type : 'long' }
308
- #expect(NoteRepository.mapping.to_hash).to eq('note')
309
- end
310
-
311
393
it 'sets the value at the class level' do
312
394
expect ( NoteRepository . mapping . to_hash ) . to eq ( expected_mapping )
313
395
end
@@ -343,11 +425,6 @@ class NoteRepository
343
425
344
426
describe '#settings' do
345
427
346
- it 'allows the value to be set only once' do
347
- NoteRepository . settings ( number_of_shards : 3 )
348
- #expect(NoteRepository.settings.to_hash).to eq()
349
- end
350
-
351
428
it 'sets the value at the class level' do
352
429
expect ( NoteRepository . settings . to_hash ) . to eq ( number_of_shards : 1 , number_of_replicas : 0 )
353
430
end
0 commit comments