chewy 7.1.0 → 7.2.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/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
|
@@ -46,18 +46,18 @@ describe Chewy::Fields::Root do
|
|
|
46
46
|
before do
|
|
47
47
|
stub_model(:city)
|
|
48
48
|
stub_index(:places) do
|
|
49
|
-
|
|
49
|
+
index_scope City
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
let(:city) { City.new(name: 'London', rating: 100) }
|
|
54
54
|
|
|
55
55
|
specify do
|
|
56
|
-
expect(PlacesIndex
|
|
56
|
+
expect(PlacesIndex.root.compose(city))
|
|
57
57
|
.to match(hash_including('name' => 'London', 'rating' => 100))
|
|
58
58
|
end
|
|
59
59
|
specify do
|
|
60
|
-
expect(PlacesIndex
|
|
60
|
+
expect(PlacesIndex.root.compose(city, fields: %i[name borogoves]))
|
|
61
61
|
.to eq('name' => 'London')
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -65,20 +65,18 @@ describe Chewy::Fields::Root do
|
|
|
65
65
|
context 'has children' do
|
|
66
66
|
before do
|
|
67
67
|
stub_index(:places) do
|
|
68
|
-
|
|
69
|
-
field :name, :rating
|
|
70
|
-
end
|
|
68
|
+
field :name, :rating
|
|
71
69
|
end
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
let(:city) { double(name: 'London', rating: 100) }
|
|
75
73
|
|
|
76
74
|
specify do
|
|
77
|
-
expect(PlacesIndex
|
|
75
|
+
expect(PlacesIndex.root.compose(city))
|
|
78
76
|
.to eq('name' => 'London', 'rating' => 100)
|
|
79
77
|
end
|
|
80
78
|
specify do
|
|
81
|
-
expect(PlacesIndex
|
|
79
|
+
expect(PlacesIndex.root.compose(city, fields: %i[name borogoves]))
|
|
82
80
|
.to eq('name' => 'London')
|
|
83
81
|
end
|
|
84
82
|
end
|
|
@@ -86,21 +84,19 @@ describe Chewy::Fields::Root do
|
|
|
86
84
|
context 'root value provided' do
|
|
87
85
|
before do
|
|
88
86
|
stub_index(:places) do
|
|
89
|
-
|
|
90
|
-
root value: ->(o) { {name: o.name + 'Modified', rating: o.rating.next} }
|
|
91
|
-
end
|
|
87
|
+
root value: ->(o) { {name: "#{o.name}Modified", rating: o.rating.next} }
|
|
92
88
|
end
|
|
93
89
|
end
|
|
94
90
|
|
|
95
91
|
let(:city) { double(name: 'London', rating: 100) }
|
|
96
92
|
|
|
97
93
|
specify do
|
|
98
|
-
expect(PlacesIndex
|
|
94
|
+
expect(PlacesIndex.root.compose(city))
|
|
99
95
|
.to eq('name' => 'LondonModified', 'rating' => 101)
|
|
100
96
|
end
|
|
101
97
|
|
|
102
98
|
specify do
|
|
103
|
-
expect(PlacesIndex
|
|
99
|
+
expect(PlacesIndex.root.compose(city, fields: %i[name borogoves]))
|
|
104
100
|
.to eq('name' => 'LondonModified')
|
|
105
101
|
end
|
|
106
102
|
end
|
|
@@ -108,11 +104,9 @@ describe Chewy::Fields::Root do
|
|
|
108
104
|
context 'complex evaluations' do
|
|
109
105
|
before do
|
|
110
106
|
stub_index(:places) do
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
field :rating
|
|
115
|
-
end
|
|
107
|
+
root value: ->(o) { {name: "#{o.name}Modified", rating: o.rating.next} } do
|
|
108
|
+
field :name, value: ->(o) { "#{o[:name]}Modified" }
|
|
109
|
+
field :rating
|
|
116
110
|
end
|
|
117
111
|
end
|
|
118
112
|
end
|
|
@@ -120,12 +114,12 @@ describe Chewy::Fields::Root do
|
|
|
120
114
|
let(:city) { double(name: 'London', rating: 100) }
|
|
121
115
|
|
|
122
116
|
specify do
|
|
123
|
-
expect(PlacesIndex
|
|
117
|
+
expect(PlacesIndex.root.compose(city))
|
|
124
118
|
.to eq('name' => 'LondonModifiedModified', 'rating' => 101)
|
|
125
119
|
end
|
|
126
120
|
|
|
127
121
|
specify do
|
|
128
|
-
expect(PlacesIndex
|
|
122
|
+
expect(PlacesIndex.root.compose(city, fields: %i[name borogoves]))
|
|
129
123
|
.to eq('name' => 'LondonModifiedModified')
|
|
130
124
|
end
|
|
131
125
|
end
|
|
@@ -134,14 +128,12 @@ describe Chewy::Fields::Root do
|
|
|
134
128
|
describe '#child_hash' do
|
|
135
129
|
before do
|
|
136
130
|
stub_index(:places) do
|
|
137
|
-
|
|
138
|
-
field :name, :rating
|
|
139
|
-
end
|
|
131
|
+
field :name, :rating
|
|
140
132
|
end
|
|
141
133
|
end
|
|
142
134
|
|
|
143
135
|
specify do
|
|
144
|
-
expect(PlacesIndex
|
|
136
|
+
expect(PlacesIndex.root.child_hash).to match(
|
|
145
137
|
name: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :name)),
|
|
146
138
|
rating: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :rating))
|
|
147
139
|
)
|
|
@@ -5,14 +5,12 @@ describe 'Time fields' do
|
|
|
5
5
|
|
|
6
6
|
before do
|
|
7
7
|
stub_index(:posts) do
|
|
8
|
-
|
|
9
|
-
field :published_at, type: 'date'
|
|
10
|
-
end
|
|
8
|
+
field :published_at, type: 'date'
|
|
11
9
|
end
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
before do
|
|
15
|
-
PostsIndex
|
|
13
|
+
PostsIndex.import(
|
|
16
14
|
double(published_at: ActiveSupport::TimeZone[-28_800].parse('2014/12/18 19:00')),
|
|
17
15
|
double(published_at: ActiveSupport::TimeZone[-21_600].parse('2014/12/18 20:00')),
|
|
18
16
|
double(published_at: ActiveSupport::TimeZone[-21_600].parse('2014/12/17 20:00'))
|
|
@@ -24,5 +22,7 @@ describe 'Time fields' do
|
|
|
24
22
|
|
|
25
23
|
specify { expect(PostsIndex.total).to eq(3) }
|
|
26
24
|
specify { expect(PostsIndex.filter(range: {published_at: {gte: range.min, lte: range.max}}).size).to eq(1) }
|
|
27
|
-
specify
|
|
25
|
+
specify do
|
|
26
|
+
expect(PostsIndex.filter(range: {published_at: {gt: range.min.utc, lt: (range.max + 1.hour).utc}}).size).to eq(2)
|
|
27
|
+
end
|
|
28
28
|
end
|
|
@@ -76,9 +76,15 @@ describe Chewy::Index::Actions do
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
specify do
|
|
79
|
-
expect
|
|
79
|
+
expect do
|
|
80
|
+
DummiesIndex.create!
|
|
81
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
|
|
82
|
+
end
|
|
83
|
+
specify do
|
|
84
|
+
expect do
|
|
85
|
+
DummiesIndex.create!('2013')
|
|
86
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/)
|
|
80
87
|
end
|
|
81
|
-
specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
|
|
82
88
|
end
|
|
83
89
|
|
|
84
90
|
context do
|
|
@@ -92,7 +98,9 @@ describe Chewy::Index::Actions do
|
|
|
92
98
|
specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
|
|
93
99
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
|
94
100
|
specify do
|
|
95
|
-
expect
|
|
101
|
+
expect do
|
|
102
|
+
DummiesIndex.create!('2013')
|
|
103
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
|
|
96
104
|
end
|
|
97
105
|
specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
|
|
98
106
|
|
|
@@ -183,7 +191,11 @@ describe Chewy::Index::Actions do
|
|
|
183
191
|
|
|
184
192
|
describe '.delete!' do
|
|
185
193
|
specify { expect { DummiesIndex.delete! }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) }
|
|
186
|
-
specify
|
|
194
|
+
specify do
|
|
195
|
+
expect do
|
|
196
|
+
DummiesIndex.delete!('2013')
|
|
197
|
+
end.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
|
198
|
+
end
|
|
187
199
|
|
|
188
200
|
context do
|
|
189
201
|
before do
|
|
@@ -337,7 +349,7 @@ describe Chewy::Index::Actions do
|
|
|
337
349
|
before do
|
|
338
350
|
stub_model(:city)
|
|
339
351
|
stub_index(:cities) do
|
|
340
|
-
|
|
352
|
+
index_scope City
|
|
341
353
|
end
|
|
342
354
|
end
|
|
343
355
|
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
|
@@ -359,9 +371,8 @@ describe Chewy::Index::Actions do
|
|
|
359
371
|
context do
|
|
360
372
|
before do
|
|
361
373
|
stub_index(:cities) do
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
end
|
|
374
|
+
index_scope City
|
|
375
|
+
field :name, type: 'object'
|
|
365
376
|
end
|
|
366
377
|
end
|
|
367
378
|
|
|
@@ -373,7 +384,7 @@ describe Chewy::Index::Actions do
|
|
|
373
384
|
before do
|
|
374
385
|
stub_model(:city)
|
|
375
386
|
stub_index(:cities) do
|
|
376
|
-
|
|
387
|
+
index_scope City
|
|
377
388
|
end
|
|
378
389
|
end
|
|
379
390
|
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
|
@@ -395,9 +406,8 @@ describe Chewy::Index::Actions do
|
|
|
395
406
|
context do
|
|
396
407
|
before do
|
|
397
408
|
stub_index(:cities) do
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
end
|
|
409
|
+
index_scope City
|
|
410
|
+
field :name, type: 'object'
|
|
401
411
|
end
|
|
402
412
|
end
|
|
403
413
|
|
|
@@ -409,7 +419,7 @@ describe Chewy::Index::Actions do
|
|
|
409
419
|
before do
|
|
410
420
|
stub_model(:city)
|
|
411
421
|
stub_index(:cities) do
|
|
412
|
-
|
|
422
|
+
index_scope City
|
|
413
423
|
end
|
|
414
424
|
end
|
|
415
425
|
|
|
@@ -500,7 +510,7 @@ describe Chewy::Index::Actions do
|
|
|
500
510
|
before do
|
|
501
511
|
stub_index(:cities) do
|
|
502
512
|
settings index: {refresh_interval: '2s'}
|
|
503
|
-
|
|
513
|
+
index_scope City
|
|
504
514
|
end
|
|
505
515
|
end
|
|
506
516
|
|
|
@@ -511,9 +521,11 @@ describe Chewy::Index::Actions do
|
|
|
511
521
|
end
|
|
512
522
|
|
|
513
523
|
specify do
|
|
514
|
-
expect(CitiesIndex.client.indices)
|
|
524
|
+
expect(CitiesIndex.client.indices)
|
|
525
|
+
.to receive(:put_settings).with(index: name, body: before_import_body).once
|
|
515
526
|
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
|
516
|
-
expect(CitiesIndex)
|
|
527
|
+
expect(CitiesIndex)
|
|
528
|
+
.to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
|
517
529
|
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
|
518
530
|
end
|
|
519
531
|
|
|
@@ -574,12 +586,11 @@ describe Chewy::Index::Actions do
|
|
|
574
586
|
xcontext 'applying journal' do
|
|
575
587
|
before do
|
|
576
588
|
stub_index(:cities) do
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
end
|
|
589
|
+
index_scope City
|
|
590
|
+
field :name, value: (lambda do
|
|
591
|
+
sleep(rating)
|
|
592
|
+
name
|
|
593
|
+
end)
|
|
583
594
|
end
|
|
584
595
|
end
|
|
585
596
|
|
|
@@ -649,18 +660,253 @@ describe Chewy::Index::Actions do
|
|
|
649
660
|
|
|
650
661
|
context 'other options' do
|
|
651
662
|
specify do
|
|
652
|
-
expect(CitiesIndex
|
|
663
|
+
expect(CitiesIndex).to receive(:import).with(parallel: true, journal: false).once.and_return(true)
|
|
653
664
|
expect(CitiesIndex.reset!(parallel: true)).to eq(true)
|
|
654
665
|
end
|
|
655
666
|
|
|
656
667
|
specify do
|
|
657
|
-
expect(CitiesIndex
|
|
668
|
+
expect(CitiesIndex)
|
|
669
|
+
.to receive(:import)
|
|
670
|
+
.with(suffix: 'suffix', parallel: true, journal: false, refresh: true)
|
|
671
|
+
.once.and_return(true)
|
|
658
672
|
expect(CitiesIndex.reset!('suffix', parallel: true)).to eq(true)
|
|
659
673
|
end
|
|
660
674
|
end
|
|
661
675
|
end
|
|
662
676
|
|
|
677
|
+
describe '.reset' do
|
|
678
|
+
before do
|
|
679
|
+
stub_model(:city)
|
|
680
|
+
stub_index(:cities) do
|
|
681
|
+
index_scope City
|
|
682
|
+
end
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
context do
|
|
686
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
|
687
|
+
|
|
688
|
+
specify { expect(CitiesIndex.reset).to eq(true) }
|
|
689
|
+
specify { expect(CitiesIndex.reset('2013')).to eq(true) }
|
|
690
|
+
|
|
691
|
+
context do
|
|
692
|
+
before { CitiesIndex.reset }
|
|
693
|
+
|
|
694
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
|
695
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
|
696
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities']) }
|
|
697
|
+
end
|
|
698
|
+
end
|
|
699
|
+
end
|
|
700
|
+
|
|
701
|
+
describe '.sync' do
|
|
702
|
+
before do
|
|
703
|
+
stub_model(:city)
|
|
704
|
+
stub_index(:cities) do
|
|
705
|
+
index_scope City
|
|
706
|
+
field :name
|
|
707
|
+
field :updated_at, type: 'date'
|
|
708
|
+
end
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
|
|
712
|
+
|
|
713
|
+
before do
|
|
714
|
+
CitiesIndex.import
|
|
715
|
+
cities.first.destroy
|
|
716
|
+
cities.last.update(name: 'Name5')
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
let!(:additional_city) { City.create!(name: 'Name4') }
|
|
720
|
+
|
|
721
|
+
specify do
|
|
722
|
+
expect(CitiesIndex.sync).to match(
|
|
723
|
+
count: 3,
|
|
724
|
+
missing: contain_exactly(cities.first.id.to_s, additional_city.id.to_s),
|
|
725
|
+
outdated: [cities.last.id.to_s]
|
|
726
|
+
)
|
|
727
|
+
end
|
|
728
|
+
specify do
|
|
729
|
+
expect { CitiesIndex.sync }.to update_index(CitiesIndex)
|
|
730
|
+
.and_reindex(additional_city, cities.last)
|
|
731
|
+
.and_delete(cities.first).only
|
|
732
|
+
end
|
|
733
|
+
end
|
|
734
|
+
|
|
663
735
|
describe '.journal' do
|
|
664
736
|
specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
|
|
665
737
|
end
|
|
738
|
+
|
|
739
|
+
describe '.clear_cache' do
|
|
740
|
+
before do
|
|
741
|
+
stub_model(:city)
|
|
742
|
+
stub_index(:cities) do
|
|
743
|
+
index_scope City
|
|
744
|
+
end
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
let(:index_name) { 'test_index' }
|
|
748
|
+
let(:index_name_with_prefix) { 'cities_test_index' }
|
|
749
|
+
let(:unexisted_index_name) { 'wrong_index' }
|
|
750
|
+
|
|
751
|
+
context 'with existing index' do
|
|
752
|
+
before do
|
|
753
|
+
CitiesIndex.create(index_name)
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
specify do
|
|
757
|
+
expect(CitiesIndex)
|
|
758
|
+
.to receive(:clear_cache)
|
|
759
|
+
.and_call_original
|
|
760
|
+
expect { CitiesIndex.clear_cache({index: index_name_with_prefix}) }
|
|
761
|
+
.not_to raise_error
|
|
762
|
+
end
|
|
763
|
+
end
|
|
764
|
+
|
|
765
|
+
context 'with unexisting index' do
|
|
766
|
+
specify do
|
|
767
|
+
expect(CitiesIndex)
|
|
768
|
+
.to receive(:clear_cache)
|
|
769
|
+
.and_call_original
|
|
770
|
+
expect { CitiesIndex.clear_cache({index: unexisted_index_name}) }
|
|
771
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
|
772
|
+
end
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
context 'without arguments' do
|
|
776
|
+
before do
|
|
777
|
+
CitiesIndex.create
|
|
778
|
+
end
|
|
779
|
+
|
|
780
|
+
specify do
|
|
781
|
+
expect(CitiesIndex)
|
|
782
|
+
.to receive(:clear_cache)
|
|
783
|
+
.and_call_original
|
|
784
|
+
expect { CitiesIndex.clear_cache }
|
|
785
|
+
.not_to raise_error
|
|
786
|
+
end
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
describe '.reindex' do
|
|
791
|
+
before do
|
|
792
|
+
stub_model(:city)
|
|
793
|
+
stub_index(:cities) do
|
|
794
|
+
index_scope City
|
|
795
|
+
end
|
|
796
|
+
CitiesIndex.create(source_index)
|
|
797
|
+
DummiesIndex.create(dest_index)
|
|
798
|
+
end
|
|
799
|
+
|
|
800
|
+
let(:source_index) { 'source_index' }
|
|
801
|
+
let(:source_index_with_prefix) { 'cities_source_index' }
|
|
802
|
+
let(:dest_index) { 'dest_index' }
|
|
803
|
+
let(:dest_index_with_prefix) { 'dummies_dest_index' }
|
|
804
|
+
let(:unexisting_index) { 'wrong_index' }
|
|
805
|
+
|
|
806
|
+
context 'with existing indexes' do
|
|
807
|
+
specify do
|
|
808
|
+
expect(CitiesIndex)
|
|
809
|
+
.to receive(:reindex)
|
|
810
|
+
.and_call_original
|
|
811
|
+
expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: dest_index_with_prefix) }
|
|
812
|
+
.not_to raise_error
|
|
813
|
+
end
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
context 'with unexisting indexes' do
|
|
817
|
+
context 'source index' do
|
|
818
|
+
specify do
|
|
819
|
+
expect(CitiesIndex)
|
|
820
|
+
.to receive(:reindex)
|
|
821
|
+
.and_call_original
|
|
822
|
+
expect { CitiesIndex.reindex(source: unexisting_index, dest: dest_index_with_prefix) }
|
|
823
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
|
824
|
+
end
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
context 'dest index' do
|
|
828
|
+
specify do
|
|
829
|
+
expect(CitiesIndex)
|
|
830
|
+
.to receive(:reindex)
|
|
831
|
+
.and_call_original
|
|
832
|
+
expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: unexisting_index) }
|
|
833
|
+
.not_to raise_error
|
|
834
|
+
end
|
|
835
|
+
end
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
context 'with missing indexes' do
|
|
839
|
+
context 'without dest index' do
|
|
840
|
+
specify do
|
|
841
|
+
expect(DummiesIndex)
|
|
842
|
+
.to receive(:reindex)
|
|
843
|
+
.and_call_original
|
|
844
|
+
expect { DummiesIndex.reindex(source: source_index_with_prefix) }
|
|
845
|
+
.not_to raise_error
|
|
846
|
+
end
|
|
847
|
+
end
|
|
848
|
+
|
|
849
|
+
context 'without source index' do
|
|
850
|
+
specify do
|
|
851
|
+
expect(CitiesIndex)
|
|
852
|
+
.to receive(:reindex)
|
|
853
|
+
.and_call_original
|
|
854
|
+
expect { CitiesIndex.reindex(dest: dest_index_with_prefix) }
|
|
855
|
+
.not_to raise_error
|
|
856
|
+
end
|
|
857
|
+
end
|
|
858
|
+
end
|
|
859
|
+
end
|
|
860
|
+
|
|
861
|
+
describe 'update_mapping' do
|
|
862
|
+
before do
|
|
863
|
+
stub_model(:city)
|
|
864
|
+
stub_index(:cities) do
|
|
865
|
+
index_scope City
|
|
866
|
+
end
|
|
867
|
+
CitiesIndex.create
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
let(:index_name) { CitiesIndex.index_name }
|
|
871
|
+
let(:body_hash) { {properties: {new_field: {type: :text}}} }
|
|
872
|
+
let(:unexisting_index) { 'wrong_index' }
|
|
873
|
+
let(:empty_body_hash) { {} }
|
|
874
|
+
|
|
875
|
+
context 'with existing index' do
|
|
876
|
+
specify do
|
|
877
|
+
expect { CitiesIndex.update_mapping(index_name, body_hash) }
|
|
878
|
+
.not_to raise_error
|
|
879
|
+
end
|
|
880
|
+
end
|
|
881
|
+
|
|
882
|
+
context 'with unexisting arguments' do
|
|
883
|
+
context 'index name' do
|
|
884
|
+
specify do
|
|
885
|
+
expect { CitiesIndex.update_mapping(unexisting_index, body_hash) }
|
|
886
|
+
.to raise_error Elasticsearch::Transport::Transport::Errors::NotFound
|
|
887
|
+
end
|
|
888
|
+
end
|
|
889
|
+
|
|
890
|
+
context 'body hash' do
|
|
891
|
+
specify do
|
|
892
|
+
expect { CitiesIndex.update_mapping(index_name, empty_body_hash) }
|
|
893
|
+
.not_to raise_error
|
|
894
|
+
end
|
|
895
|
+
end
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
context 'with only argument' do
|
|
899
|
+
specify do
|
|
900
|
+
expect { CitiesIndex.update_mapping(index_name) }
|
|
901
|
+
.not_to raise_error
|
|
902
|
+
end
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
context 'without arguments' do
|
|
906
|
+
specify do
|
|
907
|
+
expect { CitiesIndex.update_mapping }
|
|
908
|
+
.not_to raise_error
|
|
909
|
+
end
|
|
910
|
+
end
|
|
911
|
+
end
|
|
666
912
|
end
|