elasticsearch-model 7.2.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +22 -22
- data/Rakefile +7 -6
- data/elasticsearch-model.gemspec +5 -5
- data/examples/activerecord_associations.rb +1 -1
- data/examples/activerecord_custom_analyzer.rb +2 -2
- data/gemfiles/{6.0.gemfile → 6.1.gemfile} +6 -6
- data/gemfiles/{5.0.gemfile → 7.0.gemfile} +8 -7
- data/gemfiles/{3.0.gemfile → 7.1.gemfile} +9 -8
- data/lib/elasticsearch/model/adapter.rb +0 -2
- data/lib/elasticsearch/model/adapters/active_record.rb +0 -4
- data/lib/elasticsearch/model/adapters/default.rb +0 -4
- data/lib/elasticsearch/model/adapters/mongoid.rb +9 -11
- data/lib/elasticsearch/model/adapters/multiple.rb +0 -1
- data/lib/elasticsearch/model/importing.rb +1 -12
- data/lib/elasticsearch/model/indexing.rb +6 -19
- data/lib/elasticsearch/model/multimodel.rb +1 -10
- data/lib/elasticsearch/model/naming.rb +7 -58
- data/lib/elasticsearch/model/proxy.rb +6 -7
- data/lib/elasticsearch/model/response/result.rb +0 -6
- data/lib/elasticsearch/model/searching.rb +2 -3
- data/lib/elasticsearch/model/version.rb +1 -1
- data/lib/elasticsearch/model.rb +6 -3
- data/spec/elasticsearch/model/adapter_spec.rb +0 -11
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +48 -76
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +6 -78
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +6 -2
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +1 -5
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +0 -8
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +1 -4
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +9 -11
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +1 -11
- data/spec/elasticsearch/model/importing_spec.rb +6 -35
- data/spec/elasticsearch/model/indexing_spec.rb +45 -170
- data/spec/elasticsearch/model/module_spec.rb +0 -1
- data/spec/elasticsearch/model/multimodel_spec.rb +2 -8
- data/spec/elasticsearch/model/naming_spec.rb +0 -68
- data/spec/elasticsearch/model/proxy_spec.rb +8 -2
- data/spec/elasticsearch/model/response/aggregations_spec.rb +4 -4
- data/spec/elasticsearch/model/response/base_spec.rb +0 -1
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +3 -4
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +0 -1
- data/spec/elasticsearch/model/response/records_spec.rb +0 -1
- data/spec/elasticsearch/model/response/response_spec.rb +0 -1
- data/spec/elasticsearch/model/response/result_spec.rb +0 -17
- data/spec/elasticsearch/model/response/results_spec.rb +0 -1
- data/spec/elasticsearch/model/searching_search_request_spec.rb +5 -6
- data/spec/spec_helper.rb +9 -11
- data/spec/support/app/answer.rb +0 -1
- data/spec/support/app/article.rb +0 -2
- data/spec/support/app/article_no_type.rb +1 -1
- data/spec/support/app/namespaced_book.rb +0 -2
- data/spec/support/app/parent_and_child_searchable.rb +6 -4
- data/spec/support/app/question.rb +0 -1
- metadata +15 -16
- data/gemfiles/4.0.gemfile +0 -36
@@ -18,7 +18,6 @@
|
|
18
18
|
require 'spec_helper'
|
19
19
|
|
20
20
|
describe Elasticsearch::Model::Indexing do
|
21
|
-
|
22
21
|
before(:all) do
|
23
22
|
class ::DummyIndexingModel
|
24
23
|
extend ActiveModel::Naming
|
@@ -38,7 +37,6 @@ describe Elasticsearch::Model::Indexing do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
describe 'the Settings class' do
|
41
|
-
|
42
40
|
it 'should be convertible to a hash' do
|
43
41
|
expect(Elasticsearch::Model::Indexing::Settings.new(foo: 'bar').to_hash).to eq(foo: 'bar')
|
44
42
|
end
|
@@ -49,13 +47,11 @@ describe Elasticsearch::Model::Indexing do
|
|
49
47
|
end
|
50
48
|
|
51
49
|
describe '#settings' do
|
52
|
-
|
53
50
|
it 'returns an instance of the Settings class' do
|
54
51
|
expect(DummyIndexingModel.settings).to be_a(Elasticsearch::Model::Indexing::Settings)
|
55
52
|
end
|
56
53
|
|
57
54
|
context 'when the settings are updated' do
|
58
|
-
|
59
55
|
before do
|
60
56
|
DummyIndexingModel.settings(foo: 'boo')
|
61
57
|
DummyIndexingModel.settings(bar: 'bam')
|
@@ -67,7 +63,6 @@ describe Elasticsearch::Model::Indexing do
|
|
67
63
|
end
|
68
64
|
|
69
65
|
context 'when the settings are updated with a yml file' do
|
70
|
-
|
71
66
|
before do
|
72
67
|
DummyIndexingModel.settings File.open('spec/support/model.yml')
|
73
68
|
DummyIndexingModel.settings bar: 'bam'
|
@@ -79,7 +74,6 @@ describe Elasticsearch::Model::Indexing do
|
|
79
74
|
end
|
80
75
|
|
81
76
|
context 'when the settings are updated with a json file' do
|
82
|
-
|
83
77
|
before do
|
84
78
|
DummyIndexingModel.settings File.open('spec/support/model.json')
|
85
79
|
DummyIndexingModel.settings bar: 'bam'
|
@@ -92,68 +86,23 @@ describe Elasticsearch::Model::Indexing do
|
|
92
86
|
end
|
93
87
|
|
94
88
|
describe '#mappings' do
|
95
|
-
|
96
89
|
let(:expected_mapping_hash) do
|
97
|
-
{
|
90
|
+
{ foo: 'bar', :properties => {} }
|
98
91
|
end
|
99
92
|
|
100
93
|
it 'returns an instance of the Mappings class' do
|
101
94
|
expect(DummyIndexingModel.mappings).to be_a(Elasticsearch::Model::Indexing::Mappings)
|
102
95
|
end
|
103
96
|
|
104
|
-
it 'does not raise an exception when there is no type passed to the #initialize method' do
|
105
|
-
expect(Elasticsearch::Model::Indexing::Mappings.new)
|
106
|
-
end
|
107
|
-
|
108
97
|
it 'should be convertible to a hash' do
|
109
|
-
expect(Elasticsearch::Model::Indexing::Mappings.new(
|
98
|
+
expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).to_hash).to eq(expected_mapping_hash)
|
110
99
|
end
|
111
100
|
|
112
101
|
it 'should be convertible to json' do
|
113
|
-
expect(Elasticsearch::Model::Indexing::Mappings.new(
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when a type is specified' do
|
117
|
-
|
118
|
-
let(:mappings) do
|
119
|
-
Elasticsearch::Model::Indexing::Mappings.new(:mytype)
|
120
|
-
end
|
121
|
-
|
122
|
-
before do
|
123
|
-
mappings.indexes :foo, { type: 'boolean', include_in_all: false }
|
124
|
-
mappings.indexes :bar
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'creates the correct mapping definition' do
|
128
|
-
expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean')
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'uses text as the default field type' do
|
132
|
-
expect(mappings.to_hash[:mytype][:properties][:bar][:type]).to eq('text')
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'when the \'include_type_name\' option is specified' do
|
136
|
-
|
137
|
-
let(:mappings) do
|
138
|
-
Elasticsearch::Model::Indexing::Mappings.new(:mytype, include_type_name: true)
|
139
|
-
end
|
140
|
-
|
141
|
-
before do
|
142
|
-
mappings.indexes :foo, { type: 'boolean', include_in_all: false }
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'creates the correct mapping definition' do
|
146
|
-
expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean')
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'sets the \'include_type_name\' option' do
|
150
|
-
expect(mappings.to_hash[:mytype][:include_type_name]).to eq(true)
|
151
|
-
end
|
152
|
-
end
|
102
|
+
expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).as_json).to eq(expected_mapping_hash)
|
153
103
|
end
|
154
104
|
|
155
|
-
context '
|
156
|
-
|
105
|
+
context 'basic mappings' do
|
157
106
|
let(:mappings) do
|
158
107
|
Elasticsearch::Model::Indexing::Mappings.new
|
159
108
|
end
|
@@ -173,9 +122,8 @@ describe Elasticsearch::Model::Indexing do
|
|
173
122
|
end
|
174
123
|
|
175
124
|
context 'when specific mappings are defined' do
|
176
|
-
|
177
125
|
let(:mappings) do
|
178
|
-
Elasticsearch::Model::Indexing::Mappings.new(
|
126
|
+
Elasticsearch::Model::Indexing::Mappings.new(include_type_name: true)
|
179
127
|
end
|
180
128
|
|
181
129
|
before do
|
@@ -184,15 +132,14 @@ describe Elasticsearch::Model::Indexing do
|
|
184
132
|
end
|
185
133
|
|
186
134
|
it 'creates the correct mapping definition' do
|
187
|
-
expect(mappings.to_hash[:
|
135
|
+
expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean')
|
188
136
|
end
|
189
137
|
|
190
138
|
it 'uses text as the default type' do
|
191
|
-
expect(mappings.to_hash[:
|
139
|
+
expect(mappings.to_hash[:properties][:bar][:type]).to eq('text')
|
192
140
|
end
|
193
141
|
|
194
142
|
context 'when mappings are defined for multiple fields' do
|
195
|
-
|
196
143
|
before do
|
197
144
|
mappings.indexes :my_field, type: 'text' do
|
198
145
|
indexes :raw, type: 'keyword'
|
@@ -200,14 +147,13 @@ describe Elasticsearch::Model::Indexing do
|
|
200
147
|
end
|
201
148
|
|
202
149
|
it 'defines the mapping for all the fields' do
|
203
|
-
expect(mappings.to_hash[:
|
204
|
-
expect(mappings.to_hash[:
|
205
|
-
expect(mappings.to_hash[:
|
150
|
+
expect(mappings.to_hash[:properties][:my_field][:type]).to eq('text')
|
151
|
+
expect(mappings.to_hash[:properties][:my_field][:fields][:raw][:type]).to eq('keyword')
|
152
|
+
expect(mappings.to_hash[:properties][:my_field][:fields][:raw][:properties]).to be_nil
|
206
153
|
end
|
207
154
|
end
|
208
155
|
|
209
156
|
context 'when embedded properties are defined' do
|
210
|
-
|
211
157
|
before do
|
212
158
|
mappings.indexes :foo do
|
213
159
|
indexes :bar
|
@@ -227,31 +173,30 @@ describe Elasticsearch::Model::Indexing do
|
|
227
173
|
end
|
228
174
|
|
229
175
|
it 'defines mappings for the embedded properties' do
|
230
|
-
expect(mappings.to_hash[:
|
231
|
-
expect(mappings.to_hash[:
|
232
|
-
expect(mappings.to_hash[:
|
176
|
+
expect(mappings.to_hash[:properties][:foo][:type]).to eq('object')
|
177
|
+
expect(mappings.to_hash[:properties][:foo][:properties][:bar][:type]).to eq('text')
|
178
|
+
expect(mappings.to_hash[:properties][:foo][:fields]).to be_nil
|
233
179
|
|
234
|
-
expect(mappings.to_hash[:
|
235
|
-
expect(mappings.to_hash[:
|
236
|
-
expect(mappings.to_hash[:
|
180
|
+
expect(mappings.to_hash[:properties][:foo_object][:type]).to eq('object')
|
181
|
+
expect(mappings.to_hash[:properties][:foo_object][:properties][:bar][:type]).to eq('text')
|
182
|
+
expect(mappings.to_hash[:properties][:foo_object][:fields]).to be_nil
|
237
183
|
|
238
|
-
expect(mappings.to_hash[:
|
239
|
-
expect(mappings.to_hash[:
|
240
|
-
expect(mappings.to_hash[:
|
184
|
+
expect(mappings.to_hash[:properties][:foo_nested][:type]).to eq('nested')
|
185
|
+
expect(mappings.to_hash[:properties][:foo_nested][:properties][:bar][:type]).to eq('text')
|
186
|
+
expect(mappings.to_hash[:properties][:foo_nested][:fields]).to be_nil
|
241
187
|
|
242
|
-
expect(mappings.to_hash[:
|
243
|
-
expect(mappings.to_hash[:
|
244
|
-
expect(mappings.to_hash[:
|
188
|
+
expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:type]).to eq(:nested)
|
189
|
+
expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:properties]).not_to be_nil
|
190
|
+
expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:fields]).to be_nil
|
245
191
|
end
|
246
192
|
|
247
193
|
it 'defines the settings' do
|
248
|
-
expect(mappings.to_hash[:
|
194
|
+
expect(mappings.to_hash[:include_type_name]).to be(true)
|
249
195
|
end
|
250
196
|
end
|
251
197
|
end
|
252
198
|
|
253
199
|
context 'when the method is called on a class' do
|
254
|
-
|
255
200
|
before do
|
256
201
|
DummyIndexingModel.mappings(foo: 'boo')
|
257
202
|
DummyIndexingModel.mappings(bar: 'bam')
|
@@ -266,7 +211,6 @@ describe Elasticsearch::Model::Indexing do
|
|
266
211
|
end
|
267
212
|
|
268
213
|
context 'when the method is called with a block' do
|
269
|
-
|
270
214
|
before do
|
271
215
|
DummyIndexingModel.mapping do
|
272
216
|
indexes :foo, type: 'boolean'
|
@@ -279,16 +223,14 @@ describe Elasticsearch::Model::Indexing do
|
|
279
223
|
end
|
280
224
|
|
281
225
|
context 'when the class has a document_type' do
|
282
|
-
|
283
226
|
before do
|
284
227
|
DummyIndexingModel.instance_variable_set(:@mapping, nil)
|
285
|
-
DummyIndexingModel.document_type(:mytype)
|
286
228
|
DummyIndexingModel.mappings(foo: 'boo')
|
287
229
|
DummyIndexingModel.mappings(bar: 'bam')
|
288
230
|
end
|
289
231
|
|
290
232
|
let(:expected_mappings_hash) do
|
291
|
-
{
|
233
|
+
{ foo: "boo", bar: "bam", properties: {} }
|
292
234
|
end
|
293
235
|
|
294
236
|
it 'sets the mappings' do
|
@@ -299,7 +241,6 @@ describe Elasticsearch::Model::Indexing do
|
|
299
241
|
end
|
300
242
|
|
301
243
|
describe 'instance methods' do
|
302
|
-
|
303
244
|
before(:all) do
|
304
245
|
class ::DummyIndexingModelWithCallbacks
|
305
246
|
extend Elasticsearch::Model::Indexing::ClassMethods
|
@@ -366,9 +307,7 @@ describe Elasticsearch::Model::Indexing do
|
|
366
307
|
end
|
367
308
|
|
368
309
|
context 'when the module is included' do
|
369
|
-
|
370
310
|
context 'when the model uses the old ActiveModel::Dirty' do
|
371
|
-
|
372
311
|
before do
|
373
312
|
DummyIndexingModelWithOldDirty.__send__ :include, Elasticsearch::Model::Indexing::InstanceMethods
|
374
313
|
end
|
@@ -390,7 +329,6 @@ describe Elasticsearch::Model::Indexing do
|
|
390
329
|
end
|
391
330
|
|
392
331
|
context 'when the model users the current ActiveModel::Dirty' do
|
393
|
-
|
394
332
|
before do
|
395
333
|
DummyIndexingModelWithCallbacks.__send__ :include, Elasticsearch::Model::Indexing::InstanceMethods
|
396
334
|
end
|
@@ -413,12 +351,10 @@ describe Elasticsearch::Model::Indexing do
|
|
413
351
|
end
|
414
352
|
|
415
353
|
describe '#index_document' do
|
416
|
-
|
417
354
|
before do
|
418
355
|
expect(instance).to receive(:client).and_return(client)
|
419
356
|
expect(instance).to receive(:as_indexed_json).and_return('JSON')
|
420
357
|
expect(instance).to receive(:index_name).and_return('foo')
|
421
|
-
expect(instance).to receive(:document_type).twice.and_return('bar')
|
422
358
|
expect(instance).to receive(:id).and_return('1')
|
423
359
|
end
|
424
360
|
|
@@ -431,9 +367,8 @@ describe Elasticsearch::Model::Indexing do
|
|
431
367
|
end
|
432
368
|
|
433
369
|
context 'when no options are passed to the method' do
|
434
|
-
|
435
370
|
before do
|
436
|
-
expect(client).to receive(:index).with(index: 'foo',
|
371
|
+
expect(client).to receive(:index).with({ index: 'foo', id: '1', body: 'JSON' }).and_return(true)
|
437
372
|
end
|
438
373
|
|
439
374
|
it 'provides the method on an instance' do
|
@@ -442,9 +377,8 @@ describe Elasticsearch::Model::Indexing do
|
|
442
377
|
end
|
443
378
|
|
444
379
|
context 'when extra options are passed to the method' do
|
445
|
-
|
446
380
|
before do
|
447
|
-
expect(client).to receive(:index).with(index: 'foo',
|
381
|
+
expect(client).to receive(:index).with({ index: 'foo', id: '1', body: 'JSON', parent: 'A' }).and_return(true)
|
448
382
|
end
|
449
383
|
|
450
384
|
it 'passes the extra options to the method call on the client' do
|
@@ -454,11 +388,9 @@ describe Elasticsearch::Model::Indexing do
|
|
454
388
|
end
|
455
389
|
|
456
390
|
describe '#delete_document' do
|
457
|
-
|
458
391
|
before do
|
459
392
|
expect(instance).to receive(:client).and_return(client)
|
460
393
|
expect(instance).to receive(:index_name).and_return('foo')
|
461
|
-
expect(instance).to receive(:document_type).twice.and_return('bar')
|
462
394
|
expect(instance).to receive(:id).and_return('1')
|
463
395
|
end
|
464
396
|
|
@@ -471,9 +403,8 @@ describe Elasticsearch::Model::Indexing do
|
|
471
403
|
end
|
472
404
|
|
473
405
|
context 'when no options are passed to the method' do
|
474
|
-
|
475
406
|
before do
|
476
|
-
expect(client).to receive(:delete).with(index: 'foo',
|
407
|
+
expect(client).to receive(:delete).with({ index: 'foo', id: '1' }).and_return(true)
|
477
408
|
end
|
478
409
|
|
479
410
|
it 'provides the method on an instance' do
|
@@ -482,9 +413,8 @@ describe Elasticsearch::Model::Indexing do
|
|
482
413
|
end
|
483
414
|
|
484
415
|
context 'when extra options are passed to the method' do
|
485
|
-
|
486
416
|
before do
|
487
|
-
expect(client).to receive(:delete).with(index: 'foo',
|
417
|
+
expect(client).to receive(:delete).with({ index: 'foo', id: '1', parent: 'A' }).and_return(true)
|
488
418
|
end
|
489
419
|
|
490
420
|
it 'passes the extra options to the method call on the client' do
|
@@ -494,7 +424,6 @@ describe Elasticsearch::Model::Indexing do
|
|
494
424
|
end
|
495
425
|
|
496
426
|
describe '#update_document' do
|
497
|
-
|
498
427
|
let(:client) do
|
499
428
|
double('client')
|
500
429
|
end
|
@@ -504,7 +433,6 @@ describe Elasticsearch::Model::Indexing do
|
|
504
433
|
end
|
505
434
|
|
506
435
|
context 'when no changes are present' do
|
507
|
-
|
508
436
|
before do
|
509
437
|
expect(instance).to receive(:index_document).and_return(true)
|
510
438
|
expect(client).to receive(:update).never
|
@@ -517,19 +445,16 @@ describe Elasticsearch::Model::Indexing do
|
|
517
445
|
end
|
518
446
|
|
519
447
|
context 'when changes are present' do
|
520
|
-
|
521
448
|
before do
|
522
449
|
allow(instance).to receive(:client).and_return(client)
|
523
450
|
allow(instance).to receive(:index_name).and_return('foo')
|
524
|
-
allow(instance).to receive(:document_type).and_return('bar')
|
525
451
|
allow(instance).to receive(:id).and_return('1')
|
526
452
|
end
|
527
453
|
|
528
454
|
context 'when the changes are included in the as_indexed_json representation' do
|
529
|
-
|
530
455
|
before do
|
531
456
|
instance.instance_variable_set(:@__changed_model_attributes, { foo: 'bar' })
|
532
|
-
expect(client).to receive(:update).with(index: 'foo',
|
457
|
+
expect(client).to receive(:update).with({ index: 'foo', id: '1', body: { doc: { foo: 'bar' } } }).and_return(true)
|
533
458
|
end
|
534
459
|
|
535
460
|
it 'updates the document' do
|
@@ -538,14 +463,13 @@ describe Elasticsearch::Model::Indexing do
|
|
538
463
|
end
|
539
464
|
|
540
465
|
context 'when the changes are not all included in the as_indexed_json representation' do
|
541
|
-
|
542
466
|
let(:instance) do
|
543
467
|
DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new
|
544
468
|
end
|
545
469
|
|
546
470
|
before do
|
547
471
|
instance.instance_variable_set(:@__changed_model_attributes, {'foo' => 'B', 'bar' => 'D' })
|
548
|
-
expect(client).to receive(:update).with(index: 'foo',
|
472
|
+
expect(client).to receive(:update).with({ index: 'foo', id: '1', body: { doc: { foo: 'B' } } }).and_return(true)
|
549
473
|
end
|
550
474
|
|
551
475
|
it 'updates the document' do
|
@@ -554,7 +478,6 @@ describe Elasticsearch::Model::Indexing do
|
|
554
478
|
end
|
555
479
|
|
556
480
|
context 'when none of the changes are included in the as_indexed_json representation' do
|
557
|
-
|
558
481
|
let(:instance) do
|
559
482
|
DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new
|
560
483
|
end
|
@@ -569,7 +492,6 @@ describe Elasticsearch::Model::Indexing do
|
|
569
492
|
end
|
570
493
|
|
571
494
|
context 'when there are partial updates' do
|
572
|
-
|
573
495
|
let(:instance) do
|
574
496
|
DummyIndexingModelWithCallbacksAndCustomAsIndexedJson.new
|
575
497
|
end
|
@@ -577,7 +499,7 @@ describe Elasticsearch::Model::Indexing do
|
|
577
499
|
before do
|
578
500
|
instance.instance_variable_set(:@__changed_model_attributes, { 'foo' => { 'bar' => 'BAR'} })
|
579
501
|
expect(instance).to receive(:as_indexed_json).and_return('foo' => 'BAR')
|
580
|
-
expect(client).to receive(:update).with(index: 'foo',
|
502
|
+
expect(client).to receive(:update).with({ index: 'foo', id: '1', body: { doc: { 'foo' => 'BAR' } } }).and_return(true)
|
581
503
|
end
|
582
504
|
|
583
505
|
it 'updates the document' do
|
@@ -588,7 +510,6 @@ describe Elasticsearch::Model::Indexing do
|
|
588
510
|
end
|
589
511
|
|
590
512
|
describe '#update_document_attributes' do
|
591
|
-
|
592
513
|
let(:client) do
|
593
514
|
double('client')
|
594
515
|
end
|
@@ -598,19 +519,16 @@ describe Elasticsearch::Model::Indexing do
|
|
598
519
|
end
|
599
520
|
|
600
521
|
context 'when changes are present' do
|
601
|
-
|
602
522
|
before do
|
603
523
|
expect(instance).to receive(:client).and_return(client)
|
604
524
|
expect(instance).to receive(:index_name).and_return('foo')
|
605
|
-
expect(instance).to receive(:document_type).twice.and_return('bar')
|
606
525
|
expect(instance).to receive(:id).and_return('1')
|
607
526
|
instance.instance_variable_set(:@__changed_model_attributes, { author: 'john' })
|
608
527
|
end
|
609
528
|
|
610
529
|
context 'when no options are specified' do
|
611
|
-
|
612
530
|
before do
|
613
|
-
expect(client).to receive(:update).with(index: 'foo',
|
531
|
+
expect(client).to receive(:update).with({ index: 'foo', id: '1', body: { doc: { title: 'green' } } }).and_return(true)
|
614
532
|
end
|
615
533
|
|
616
534
|
it 'updates the document' do
|
@@ -619,9 +537,8 @@ describe Elasticsearch::Model::Indexing do
|
|
619
537
|
end
|
620
538
|
|
621
539
|
context 'when extra options are provided' do
|
622
|
-
|
623
540
|
before do
|
624
|
-
expect(client).to receive(:update).with(index: 'foo',
|
541
|
+
expect(client).to receive(:update).with({ index: 'foo', id: '1', body: { doc: { title: 'green' } }, refresh: true }).and_return(true)
|
625
542
|
end
|
626
543
|
|
627
544
|
it 'updates the document' do
|
@@ -633,7 +550,6 @@ describe Elasticsearch::Model::Indexing do
|
|
633
550
|
end
|
634
551
|
|
635
552
|
describe '#index_exists?' do
|
636
|
-
|
637
553
|
before do
|
638
554
|
expect(DummyIndexingModel).to receive(:client).and_return(client)
|
639
555
|
end
|
@@ -649,8 +565,7 @@ describe Elasticsearch::Model::Indexing do
|
|
649
565
|
end
|
650
566
|
end
|
651
567
|
|
652
|
-
context 'when the index does not
|
653
|
-
|
568
|
+
context 'when the index does not exist' do
|
654
569
|
let(:client) do
|
655
570
|
double('client', indices: double('indices', exists: false))
|
656
571
|
end
|
@@ -662,7 +577,6 @@ describe Elasticsearch::Model::Indexing do
|
|
662
577
|
end
|
663
578
|
|
664
579
|
describe '#delete_index!' do
|
665
|
-
|
666
580
|
before(:all) do
|
667
581
|
class ::DummyIndexingModelForRecreate
|
668
582
|
extend ActiveModel::Naming
|
@@ -677,19 +591,7 @@ describe Elasticsearch::Model::Indexing do
|
|
677
591
|
|
678
592
|
context 'when the index is not found' do
|
679
593
|
let(:logger) { nil }
|
680
|
-
let(:
|
681
|
-
Elasticsearch::Transport::Client.new(logger: logger)
|
682
|
-
end
|
683
|
-
|
684
|
-
let(:client) do
|
685
|
-
double('client', indices: indices, transport: transport)
|
686
|
-
end
|
687
|
-
|
688
|
-
let(:indices) do
|
689
|
-
double('indices').tap do |ind|
|
690
|
-
expect(ind).to receive(:delete).and_raise(NotFound)
|
691
|
-
end
|
692
|
-
end
|
594
|
+
let(:client) { Elasticsearch::Client.new(logger: logger, transport_options: { ssl: { verify: false } }) }
|
693
595
|
|
694
596
|
before do
|
695
597
|
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)
|
@@ -705,32 +607,26 @@ describe Elasticsearch::Model::Indexing do
|
|
705
607
|
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
|
706
608
|
end
|
707
609
|
|
708
|
-
let(:client) do
|
709
|
-
double('client', indices: indices, transport: transport)
|
710
|
-
end
|
711
|
-
|
712
610
|
it 'deletes the index without raising an exception' do
|
713
611
|
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
|
714
612
|
end
|
715
613
|
|
716
614
|
it 'logs the message that the index is not found' do
|
717
|
-
expect(logger).to receive(:debug)
|
615
|
+
expect(logger).to receive(:debug).at_least(:once)
|
718
616
|
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
|
719
617
|
end
|
720
618
|
end
|
721
619
|
end
|
722
620
|
|
723
621
|
context 'when the force option is not provided' do
|
724
|
-
|
725
622
|
it 'raises an exception' do
|
726
623
|
expect {
|
727
624
|
DummyIndexingModelForRecreate.delete_index!
|
728
|
-
}.to raise_exception(NotFound)
|
625
|
+
}.to raise_exception(Elastic::Transport::Transport::Errors::NotFound)
|
729
626
|
end
|
730
627
|
end
|
731
628
|
|
732
629
|
context 'when the exception is not NotFound' do
|
733
|
-
|
734
630
|
let(:indices) do
|
735
631
|
double('indices').tap do |ind|
|
736
632
|
expect(ind).to receive(:delete).and_raise(Exception)
|
@@ -746,7 +642,6 @@ describe Elasticsearch::Model::Indexing do
|
|
746
642
|
end
|
747
643
|
|
748
644
|
context 'when an index name is provided in the options' do
|
749
|
-
|
750
645
|
before do
|
751
646
|
expect(DummyIndexingModelForRecreate).to receive(:client).and_return(client)
|
752
647
|
expect(indices).to receive(:delete).with(index: 'custom-foo')
|
@@ -767,7 +662,6 @@ describe Elasticsearch::Model::Indexing do
|
|
767
662
|
end
|
768
663
|
|
769
664
|
describe '#create_index' do
|
770
|
-
|
771
665
|
before(:all) do
|
772
666
|
class ::DummyIndexingModelForCreate
|
773
667
|
extend ActiveModel::Naming
|
@@ -797,14 +691,12 @@ describe Elasticsearch::Model::Indexing do
|
|
797
691
|
end
|
798
692
|
|
799
693
|
context 'when the index does not exist' do
|
800
|
-
|
801
694
|
before do
|
802
695
|
expect(DummyIndexingModelForCreate).to receive(:client).and_return(client)
|
803
696
|
expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(false)
|
804
697
|
end
|
805
698
|
|
806
699
|
context 'when options are not provided' do
|
807
|
-
|
808
700
|
let(:expected_body) do
|
809
701
|
{ mappings: { properties: { foo: { analyzer: 'keyword',
|
810
702
|
type: 'text' } } },
|
@@ -812,7 +704,7 @@ describe Elasticsearch::Model::Indexing do
|
|
812
704
|
end
|
813
705
|
|
814
706
|
before do
|
815
|
-
expect(indices).to receive(:create).with(index: 'foo', body: expected_body).and_return(true)
|
707
|
+
expect(indices).to receive(:create).with({ index: 'foo', body: expected_body }).and_return(true)
|
816
708
|
end
|
817
709
|
|
818
710
|
it 'creates the index' do
|
@@ -821,14 +713,13 @@ describe Elasticsearch::Model::Indexing do
|
|
821
713
|
end
|
822
714
|
|
823
715
|
context 'when options are provided' do
|
824
|
-
|
825
716
|
let(:expected_body) do
|
826
717
|
{ mappings: { foobar: { properties: { foo: { analyzer: 'bar' } } } },
|
827
718
|
settings: { index: { number_of_shards: 3 } } }
|
828
719
|
end
|
829
720
|
|
830
721
|
before do
|
831
|
-
expect(indices).to receive(:create).with(index: 'foobar', body: expected_body).and_return(true)
|
722
|
+
expect(indices).to receive(:create).with({ index: 'foobar', body: expected_body }).and_return(true)
|
832
723
|
end
|
833
724
|
|
834
725
|
it 'creates the index' do
|
@@ -842,7 +733,6 @@ describe Elasticsearch::Model::Indexing do
|
|
842
733
|
end
|
843
734
|
|
844
735
|
context 'when the index exists' do
|
845
|
-
|
846
736
|
before do
|
847
737
|
expect(DummyIndexingModelForCreate).to receive(:index_exists?).and_return(true)
|
848
738
|
expect(indices).to receive(:create).never
|
@@ -854,7 +744,6 @@ describe Elasticsearch::Model::Indexing do
|
|
854
744
|
end
|
855
745
|
|
856
746
|
context 'when creating the index raises an exception' do
|
857
|
-
|
858
747
|
before do
|
859
748
|
expect(DummyIndexingModelForCreate).to receive(:client).and_return(client)
|
860
749
|
expect(DummyIndexingModelForCreate).to receive(:delete_index!).and_return(true)
|
@@ -870,11 +759,10 @@ describe Elasticsearch::Model::Indexing do
|
|
870
759
|
end
|
871
760
|
|
872
761
|
context 'when an index name is provided in the options' do
|
873
|
-
|
874
762
|
before do
|
875
763
|
expect(DummyIndexingModelForCreate).to receive(:client).and_return(client).twice
|
876
764
|
expect(indices).to receive(:exists).and_return(false)
|
877
|
-
expect(indices).to receive(:create).with(index: 'custom-foo', body: expected_body)
|
765
|
+
expect(indices).to receive(:create).with({ index: 'custom-foo', body: expected_body })
|
878
766
|
end
|
879
767
|
|
880
768
|
let(:expected_body) do
|
@@ -892,7 +780,6 @@ describe Elasticsearch::Model::Indexing do
|
|
892
780
|
end
|
893
781
|
|
894
782
|
describe '#refresh_index!' do
|
895
|
-
|
896
783
|
before(:all) do
|
897
784
|
class ::DummyIndexingModelForRefresh
|
898
785
|
extend ActiveModel::Naming
|
@@ -914,15 +801,7 @@ describe Elasticsearch::Model::Indexing do
|
|
914
801
|
end
|
915
802
|
|
916
803
|
let(:client) do
|
917
|
-
|
918
|
-
end
|
919
|
-
|
920
|
-
let(:transport) do
|
921
|
-
Elasticsearch::Transport::Client.new(logger: nil)
|
922
|
-
end
|
923
|
-
|
924
|
-
let(:indices) do
|
925
|
-
double('indices')
|
804
|
+
Elasticsearch::Client.new(logger: nil)
|
926
805
|
end
|
927
806
|
|
928
807
|
before do
|
@@ -932,7 +811,7 @@ describe Elasticsearch::Model::Indexing do
|
|
932
811
|
context 'when the force option is true' do
|
933
812
|
context 'when the operation raises a NotFound exception' do
|
934
813
|
before do
|
935
|
-
expect(
|
814
|
+
expect(client).to receive_message_chain(:indices, :refresh).and_raise(NotFound)
|
936
815
|
end
|
937
816
|
|
938
817
|
it 'does not raise an exception' do
|
@@ -945,11 +824,7 @@ describe Elasticsearch::Model::Indexing do
|
|
945
824
|
end
|
946
825
|
|
947
826
|
let(:client) do
|
948
|
-
|
949
|
-
end
|
950
|
-
|
951
|
-
let(:transport) do
|
952
|
-
Elasticsearch::Transport::Client.new(logger: logger)
|
827
|
+
Elasticsearch::Client.new(logger: logger)
|
953
828
|
end
|
954
829
|
|
955
830
|
it 'does not raise an exception' do
|
@@ -965,7 +840,7 @@ describe Elasticsearch::Model::Indexing do
|
|
965
840
|
|
966
841
|
context 'when the operation raises another type of exception' do
|
967
842
|
before do
|
968
|
-
expect(
|
843
|
+
expect(client).to receive_message_chain(:indices, :refresh).and_raise(Exception)
|
969
844
|
end
|
970
845
|
|
971
846
|
it 'does not raise an exception' do
|
@@ -978,7 +853,7 @@ describe Elasticsearch::Model::Indexing do
|
|
978
853
|
|
979
854
|
context 'when an index name is provided in the options' do
|
980
855
|
before do
|
981
|
-
expect(
|
856
|
+
expect(client).to receive_message_chain(:indices, :refresh).with(index: 'custom-foo')
|
982
857
|
end
|
983
858
|
|
984
859
|
it 'uses the index name' do
|
@@ -65,7 +65,6 @@ describe Elasticsearch::Model do
|
|
65
65
|
expect(DummyIncludingModel).to respond_to(:mapping)
|
66
66
|
expect(DummyIncludingModel).to respond_to(:settings)
|
67
67
|
expect(DummyIncludingModel).to respond_to(:index_name)
|
68
|
-
expect(DummyIncludingModel).to respond_to(:document_type)
|
69
68
|
expect(DummyIncludingModel).to respond_to(:import)
|
70
69
|
end
|
71
70
|
|