chewy 8.0.0 → 8.1.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.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -0
  3. data/README.md +30 -16
  4. data/lib/chewy/errors.rb +3 -0
  5. data/lib/chewy/fields/root.rb +3 -3
  6. data/lib/chewy/index/crutch.rb +12 -2
  7. data/lib/chewy/index/import/bulk_builder.rb +4 -3
  8. data/lib/chewy/index/import/routine.rb +2 -1
  9. data/lib/chewy/index/import.rb +4 -4
  10. data/lib/chewy/index/witchcraft.rb +24 -8
  11. data/lib/chewy/multi_search.rb +1 -1
  12. data/lib/chewy/search/parameters/runtime_mappings.rb +14 -0
  13. data/lib/chewy/search/request.rb +18 -2
  14. data/lib/chewy/search/scrolling.rb +14 -6
  15. data/lib/chewy/stash.rb +10 -6
  16. data/lib/chewy/version.rb +1 -1
  17. metadata +5 -131
  18. data/.github/CODEOWNERS +0 -1
  19. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -39
  20. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  21. data/.github/PULL_REQUEST_TEMPLATE.md +0 -16
  22. data/.github/dependabot.yml +0 -42
  23. data/.github/workflows/ruby.yml +0 -61
  24. data/.gitignore +0 -22
  25. data/.rspec +0 -2
  26. data/.rubocop.yml +0 -64
  27. data/.rubocop_todo.yml +0 -225
  28. data/.yardopts +0 -5
  29. data/CODE_OF_CONDUCT.md +0 -14
  30. data/CONTRIBUTING.md +0 -63
  31. data/Gemfile +0 -22
  32. data/Guardfile +0 -25
  33. data/Rakefile +0 -17
  34. data/chewy.gemspec +0 -24
  35. data/docker-compose.yml +0 -14
  36. data/docs/README.md +0 -16
  37. data/docs/configuration.md +0 -440
  38. data/docs/import.md +0 -122
  39. data/docs/indexing.md +0 -329
  40. data/docs/querying.md +0 -72
  41. data/docs/rake_tasks.md +0 -108
  42. data/docs/testing.md +0 -41
  43. data/docs/troubleshooting.md +0 -101
  44. data/filters +0 -78
  45. data/gemfiles/base.gemfile +0 -12
  46. data/gemfiles/rails.7.2.activerecord.gemfile +0 -14
  47. data/gemfiles/rails.8.0.activerecord.gemfile +0 -14
  48. data/migration_guide.md +0 -56
  49. data/spec/chewy/config_spec.rb +0 -110
  50. data/spec/chewy/elastic_client_spec.rb +0 -26
  51. data/spec/chewy/fields/base_spec.rb +0 -700
  52. data/spec/chewy/fields/root_spec.rb +0 -142
  53. data/spec/chewy/fields/time_fields_spec.rb +0 -28
  54. data/spec/chewy/index/actions_spec.rb +0 -851
  55. data/spec/chewy/index/adapter/active_record_spec.rb +0 -663
  56. data/spec/chewy/index/adapter/object_spec.rb +0 -243
  57. data/spec/chewy/index/aliases_spec.rb +0 -49
  58. data/spec/chewy/index/import/bulk_builder_spec.rb +0 -494
  59. data/spec/chewy/index/import/bulk_request_spec.rb +0 -95
  60. data/spec/chewy/index/import/journal_builder_spec.rb +0 -87
  61. data/spec/chewy/index/import/routine_spec.rb +0 -110
  62. data/spec/chewy/index/import_spec.rb +0 -615
  63. data/spec/chewy/index/mapping_spec.rb +0 -135
  64. data/spec/chewy/index/observe/active_record_methods_spec.rb +0 -68
  65. data/spec/chewy/index/observe/callback_spec.rb +0 -139
  66. data/spec/chewy/index/observe_spec.rb +0 -143
  67. data/spec/chewy/index/settings_spec.rb +0 -136
  68. data/spec/chewy/index/specification_spec.rb +0 -156
  69. data/spec/chewy/index/syncer_spec.rb +0 -118
  70. data/spec/chewy/index/witchcraft_spec.rb +0 -245
  71. data/spec/chewy/index/wrapper_spec.rb +0 -100
  72. data/spec/chewy/index_spec.rb +0 -269
  73. data/spec/chewy/journal_spec.rb +0 -223
  74. data/spec/chewy/minitest/helpers_spec.rb +0 -194
  75. data/spec/chewy/minitest/search_index_receiver_spec.rb +0 -120
  76. data/spec/chewy/multi_search_spec.rb +0 -84
  77. data/spec/chewy/rake_helper_spec.rb +0 -656
  78. data/spec/chewy/repository_spec.rb +0 -50
  79. data/spec/chewy/rspec/build_query_spec.rb +0 -34
  80. data/spec/chewy/rspec/helpers_spec.rb +0 -61
  81. data/spec/chewy/rspec/update_index_spec.rb +0 -313
  82. data/spec/chewy/runtime/version_spec.rb +0 -48
  83. data/spec/chewy/runtime_spec.rb +0 -9
  84. data/spec/chewy/search/loader_spec.rb +0 -83
  85. data/spec/chewy/search/pagination/kaminari_examples.rb +0 -69
  86. data/spec/chewy/search/pagination/kaminari_spec.rb +0 -21
  87. data/spec/chewy/search/parameters/aggs_spec.rb +0 -5
  88. data/spec/chewy/search/parameters/bool_storage_examples.rb +0 -53
  89. data/spec/chewy/search/parameters/collapse_spec.rb +0 -5
  90. data/spec/chewy/search/parameters/docvalue_fields_spec.rb +0 -5
  91. data/spec/chewy/search/parameters/explain_spec.rb +0 -5
  92. data/spec/chewy/search/parameters/filter_spec.rb +0 -5
  93. data/spec/chewy/search/parameters/hash_storage_examples.rb +0 -59
  94. data/spec/chewy/search/parameters/highlight_spec.rb +0 -5
  95. data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +0 -67
  96. data/spec/chewy/search/parameters/indices_spec.rb +0 -99
  97. data/spec/chewy/search/parameters/integer_storage_examples.rb +0 -32
  98. data/spec/chewy/search/parameters/knn_spec.rb +0 -5
  99. data/spec/chewy/search/parameters/limit_spec.rb +0 -5
  100. data/spec/chewy/search/parameters/load_spec.rb +0 -60
  101. data/spec/chewy/search/parameters/min_score_spec.rb +0 -32
  102. data/spec/chewy/search/parameters/none_spec.rb +0 -5
  103. data/spec/chewy/search/parameters/offset_spec.rb +0 -5
  104. data/spec/chewy/search/parameters/order_spec.rb +0 -72
  105. data/spec/chewy/search/parameters/post_filter_spec.rb +0 -5
  106. data/spec/chewy/search/parameters/preference_spec.rb +0 -5
  107. data/spec/chewy/search/parameters/profile_spec.rb +0 -5
  108. data/spec/chewy/search/parameters/query_spec.rb +0 -5
  109. data/spec/chewy/search/parameters/query_storage_examples.rb +0 -434
  110. data/spec/chewy/search/parameters/request_cache_spec.rb +0 -67
  111. data/spec/chewy/search/parameters/rescore_spec.rb +0 -62
  112. data/spec/chewy/search/parameters/script_fields_spec.rb +0 -5
  113. data/spec/chewy/search/parameters/search_after_spec.rb +0 -35
  114. data/spec/chewy/search/parameters/search_type_spec.rb +0 -5
  115. data/spec/chewy/search/parameters/source_spec.rb +0 -162
  116. data/spec/chewy/search/parameters/storage_spec.rb +0 -60
  117. data/spec/chewy/search/parameters/stored_fields_spec.rb +0 -126
  118. data/spec/chewy/search/parameters/string_array_storage_examples.rb +0 -63
  119. data/spec/chewy/search/parameters/string_storage_examples.rb +0 -32
  120. data/spec/chewy/search/parameters/suggest_spec.rb +0 -5
  121. data/spec/chewy/search/parameters/terminate_after_spec.rb +0 -5
  122. data/spec/chewy/search/parameters/timeout_spec.rb +0 -5
  123. data/spec/chewy/search/parameters/track_scores_spec.rb +0 -5
  124. data/spec/chewy/search/parameters/track_total_hits_spec.rb +0 -5
  125. data/spec/chewy/search/parameters/version_spec.rb +0 -5
  126. data/spec/chewy/search/parameters_spec.rb +0 -161
  127. data/spec/chewy/search/query_proxy_spec.rb +0 -95
  128. data/spec/chewy/search/request_spec.rb +0 -886
  129. data/spec/chewy/search/response_spec.rb +0 -180
  130. data/spec/chewy/search/scrolling_spec.rb +0 -171
  131. data/spec/chewy/search_spec.rb +0 -127
  132. data/spec/chewy/stash_spec.rb +0 -85
  133. data/spec/chewy/strategy/active_job_spec.rb +0 -73
  134. data/spec/chewy/strategy/atomic_no_refresh_spec.rb +0 -60
  135. data/spec/chewy/strategy/atomic_spec.rb +0 -61
  136. data/spec/chewy/strategy/delayed_sidekiq_spec.rb +0 -225
  137. data/spec/chewy/strategy/lazy_sidekiq_spec.rb +0 -214
  138. data/spec/chewy/strategy/sidekiq_spec.rb +0 -52
  139. data/spec/chewy/strategy_spec.rb +0 -125
  140. data/spec/chewy_spec.rb +0 -100
  141. data/spec/spec_helper.rb +0 -69
  142. data/spec/support/active_record.rb +0 -124
  143. data/spec/support/class_helpers.rb +0 -16
  144. data/spec/support/fail_helpers.rb +0 -13
@@ -1,851 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Index::Actions do
4
- before { drop_indices }
5
-
6
- before do
7
- stub_index :dummies
8
- stub_index :dummies_suffixed
9
- end
10
-
11
- describe '.exists?' do
12
- specify { expect(DummiesIndex.exists?).to eq(false) }
13
-
14
- context do
15
- before { DummiesIndex.create }
16
- specify { expect(DummiesIndex.exists?).to eq(true) }
17
- end
18
- end
19
-
20
- describe '.create' do
21
- specify { expect(DummiesIndex.create['acknowledged']).to eq(true) }
22
- specify { expect(DummiesIndex.create('2013')['acknowledged']).to eq(true) }
23
-
24
- context do
25
- before { DummiesIndex.create }
26
- specify { expect(DummiesIndex.create).to eq(false) }
27
- specify { expect(DummiesIndex.create('2013')).to eq(false) }
28
- end
29
-
30
- context do
31
- before do
32
- DummiesIndex.create '2013'
33
- DummiesSuffixedIndex.create 'should_not_appear'
34
- end
35
-
36
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
37
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
38
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
39
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
40
- specify { expect(DummiesIndex.create('2013')).to eq(false) }
41
- specify { expect(DummiesIndex.create('2014')['acknowledged']).to eq(true) }
42
-
43
- context do
44
- before { DummiesIndex.create '2014' }
45
-
46
- specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
47
- end
48
- end
49
-
50
- context do
51
- before do
52
- DummiesIndex.create '2013', alias: false
53
- DummiesSuffixedIndex.create 'should_not_appear'
54
- end
55
-
56
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
57
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
58
- specify { expect(DummiesIndex.aliases).to eq([]) }
59
- specify { expect(DummiesIndex.indexes).to eq([]) }
60
- specify { expect(DummiesIndex.exists?).to eq(false) }
61
- # Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
62
- # it would be awesome to have the following specs passing
63
- # specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
64
- # specify { expect(DummiesIndex.exists?).to eq(true) }
65
- end
66
- end
67
-
68
- describe '.create!' do
69
- specify { expect(DummiesIndex.create!['acknowledged']).to eq(true) }
70
- specify { expect(DummiesIndex.create!('2013')['acknowledged']).to eq(true) }
71
-
72
- context do
73
- before do
74
- DummiesIndex.create
75
- DummiesSuffixedIndex.create 'should_not_appear'
76
- end
77
-
78
- specify do
79
- expect do
80
- DummiesIndex.create!
81
- end.to raise_error(Elastic::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(Elastic::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/)
87
- end
88
- end
89
-
90
- context do
91
- before do
92
- DummiesIndex.create! '2013'
93
- DummiesSuffixedIndex.create! 'should_not_appear'
94
- end
95
-
96
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
97
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
98
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
99
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
100
- specify do
101
- expect do
102
- DummiesIndex.create!('2013')
103
- end.to raise_error(Elastic::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
104
- end
105
- specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
106
-
107
- context do
108
- before { DummiesIndex.create! '2014' }
109
-
110
- specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
111
- end
112
- end
113
-
114
- context do
115
- before do
116
- DummiesIndex.create! '2013', alias: false
117
- DummiesSuffixedIndex.create! 'should_not_appear'
118
- end
119
-
120
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
121
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
122
- specify { expect(DummiesIndex.aliases).to eq([]) }
123
- specify { expect(DummiesIndex.indexes).to eq([]) }
124
- specify { expect(DummiesIndex.exists?).to eq(false) }
125
- # Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
126
- # it would be awesome to have the following specs passing
127
- # specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
128
- # specify { expect(DummiesIndex.exists?).to eq(true) }
129
- end
130
- end
131
-
132
- describe '.delete' do
133
- specify { expect(DummiesIndex.delete).to eq(false) }
134
- specify { expect(DummiesIndex.delete('dummies_2013')).to eq(false) }
135
-
136
- context do
137
- before do
138
- DummiesIndex.create
139
- DummiesSuffixedIndex.create 'should_not_appear'
140
- end
141
-
142
- specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
143
-
144
- context do
145
- before { DummiesIndex.delete }
146
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
147
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
148
- end
149
- end
150
-
151
- context do
152
- before do
153
- DummiesIndex.create '2013'
154
- DummiesSuffixedIndex.create 'should_not_appear'
155
- end
156
-
157
- specify { expect(DummiesIndex.delete('2013')['acknowledged']).to eq(true) }
158
-
159
- context do
160
- before { DummiesIndex.delete('2013') }
161
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
162
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
163
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
164
- end
165
-
166
- context do
167
- before do
168
- DummiesIndex.create '2014'
169
- end
170
-
171
- specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
172
-
173
- context do
174
- before { DummiesIndex.delete }
175
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
176
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
177
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
178
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
179
- end
180
-
181
- context do
182
- before { DummiesIndex.delete('2014') }
183
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
184
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
185
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
186
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
187
- end
188
- end
189
- end
190
- end
191
-
192
- describe '.delete!' do
193
- specify { expect { DummiesIndex.delete! }.to raise_error(Elastic::Transport::Transport::Errors::NotFound) }
194
- specify do
195
- expect do
196
- DummiesIndex.delete!('2013')
197
- end.to raise_error(Elastic::Transport::Transport::Errors::NotFound)
198
- end
199
-
200
- context do
201
- before do
202
- DummiesIndex.create
203
- DummiesSuffixedIndex.create 'should_not_appear'
204
- end
205
-
206
- specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
207
-
208
- context do
209
- before { DummiesIndex.delete! }
210
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
211
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
212
- end
213
- end
214
-
215
- context do
216
- before do
217
- DummiesIndex.create '2013'
218
- DummiesSuffixedIndex.create 'should_not_appear'
219
- end
220
-
221
- specify { expect(DummiesIndex.delete!('2013')['acknowledged']).to eq(true) }
222
-
223
- context do
224
- before { DummiesIndex.delete!('2013') }
225
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
226
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
227
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
228
- end
229
-
230
- context do
231
- before { DummiesIndex.create '2014' }
232
-
233
- specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
234
-
235
- context do
236
- before { DummiesIndex.delete! }
237
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
238
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
239
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
240
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
241
- end
242
-
243
- context do
244
- before { DummiesIndex.delete!('2014') }
245
- specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
246
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
247
- specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
248
- specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
249
- end
250
- end
251
- end
252
- end
253
-
254
- describe '.purge' do
255
- specify { expect(DummiesIndex.purge['acknowledged']).to eq(true) }
256
- specify { expect(DummiesIndex.purge('2013')['acknowledged']).to eq(true) }
257
-
258
- context do
259
- before { DummiesIndex.purge }
260
- specify { expect(DummiesIndex).to be_exists }
261
- specify { expect(DummiesIndex.aliases).to eq([]) }
262
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
263
-
264
- context do
265
- before { DummiesIndex.purge }
266
- specify { expect(DummiesIndex).to be_exists }
267
- specify { expect(DummiesIndex.aliases).to eq([]) }
268
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
269
- end
270
-
271
- context do
272
- before { DummiesIndex.purge('2013') }
273
- specify { expect(DummiesIndex).to be_exists }
274
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
275
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
276
- end
277
- end
278
-
279
- context do
280
- before { DummiesIndex.purge('2013') }
281
- specify { expect(DummiesIndex).to be_exists }
282
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
283
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
284
-
285
- context do
286
- before { DummiesIndex.purge }
287
- specify { expect(DummiesIndex).to be_exists }
288
- specify { expect(DummiesIndex.aliases).to eq([]) }
289
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
290
- end
291
-
292
- context do
293
- before { DummiesIndex.purge('2014') }
294
- specify { expect(DummiesIndex).to be_exists }
295
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
296
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
297
- end
298
- end
299
- end
300
-
301
- describe '.purge!' do
302
- specify { expect(DummiesIndex.purge!['acknowledged']).to eq(true) }
303
- specify { expect(DummiesIndex.purge!('2013')['acknowledged']).to eq(true) }
304
-
305
- context do
306
- before { DummiesIndex.purge! }
307
- specify { expect(DummiesIndex).to be_exists }
308
- specify { expect(DummiesIndex.aliases).to eq([]) }
309
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
310
-
311
- context do
312
- before { DummiesIndex.purge! }
313
- specify { expect(DummiesIndex).to be_exists }
314
- specify { expect(DummiesIndex.aliases).to eq([]) }
315
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
316
- end
317
-
318
- context do
319
- before { DummiesIndex.purge!('2013') }
320
- specify { expect(DummiesIndex).to be_exists }
321
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
322
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
323
- end
324
- end
325
-
326
- context do
327
- before { DummiesIndex.purge!('2013') }
328
- specify { expect(DummiesIndex).to be_exists }
329
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
330
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
331
-
332
- context do
333
- before { DummiesIndex.purge! }
334
- specify { expect(DummiesIndex).to be_exists }
335
- specify { expect(DummiesIndex.aliases).to eq([]) }
336
- specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
337
- end
338
-
339
- context do
340
- before { DummiesIndex.purge!('2014') }
341
- specify { expect(DummiesIndex).to be_exists }
342
- specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
343
- specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
344
- end
345
- end
346
- end
347
-
348
- describe '.import', :orm do
349
- before do
350
- stub_model(:city)
351
- stub_index(:cities) do
352
- index_scope City
353
- end
354
- end
355
- let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
356
-
357
- specify { expect(CitiesIndex.import).to eq(true) }
358
-
359
- specify 'with an empty array' do
360
- expect(CitiesIndex).not_to receive(:exists?)
361
- expect(CitiesIndex).not_to receive(:create!)
362
- expect(CitiesIndex.import([])).to eq(true)
363
- end
364
-
365
- specify 'with an empty relation' do
366
- expect(CitiesIndex).not_to receive(:exists?)
367
- expect(CitiesIndex).not_to receive(:create!)
368
- expect(CitiesIndex.import(City.where('1 = 2'))).to eq(true)
369
- end
370
-
371
- context do
372
- before do
373
- stub_index(:cities) do
374
- index_scope City
375
- field :name, type: 'object'
376
- end
377
- end
378
-
379
- specify { expect(CitiesIndex.import(city: dummy_cities)).to eq(false) }
380
- end
381
- end
382
-
383
- describe '.import!', :orm do
384
- before do
385
- stub_model(:city)
386
- stub_index(:cities) do
387
- index_scope City
388
- end
389
- end
390
- let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
391
-
392
- specify { expect(CitiesIndex.import!).to eq(true) }
393
-
394
- specify 'with an empty array' do
395
- expect(CitiesIndex).not_to receive(:exists?)
396
- expect(CitiesIndex).not_to receive(:create!)
397
- expect(CitiesIndex.import!([])).to eq(true)
398
- end
399
-
400
- specify 'with an empty relation' do
401
- expect(CitiesIndex).not_to receive(:exists?)
402
- expect(CitiesIndex).not_to receive(:create!)
403
- expect(CitiesIndex.import!(City.where('1 = 2'))).to eq(true)
404
- end
405
-
406
- context do
407
- before do
408
- stub_index(:cities) do
409
- index_scope City
410
- field :name, type: 'object'
411
- end
412
- end
413
-
414
- specify { expect { CitiesIndex.import!(city: dummy_cities) }.to raise_error Chewy::ImportFailed }
415
- end
416
- end
417
-
418
- describe '.reset!', :orm do
419
- before do
420
- stub_model(:city)
421
- stub_index(:cities) do
422
- index_scope City
423
- end
424
- end
425
-
426
- context do
427
- before { City.create!(id: 1, name: 'Moscow') }
428
-
429
- specify { expect(CitiesIndex.reset!).to eq(true) }
430
- specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
431
-
432
- context do
433
- before { CitiesIndex.reset! }
434
-
435
- specify { expect(CitiesIndex.all).to have(1).item }
436
- specify { expect(CitiesIndex.aliases).to eq([]) }
437
- specify { expect(CitiesIndex.indexes).to eq(['cities']) }
438
-
439
- context do
440
- before { CitiesIndex.reset!('2013') }
441
-
442
- specify { expect(CitiesIndex.all).to have(1).item }
443
- specify { expect(CitiesIndex.aliases).to eq(['cities']) }
444
- specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
445
- end
446
-
447
- context do
448
- before { CitiesIndex.reset! }
449
-
450
- specify { expect(CitiesIndex.all).to have(1).item }
451
- specify { expect(CitiesIndex.aliases).to eq([]) }
452
- specify { expect(CitiesIndex.indexes).to eq(['cities']) }
453
- end
454
- end
455
-
456
- context do
457
- before { CitiesIndex.reset!('2013') }
458
-
459
- specify { expect(CitiesIndex.all).to have(1).item }
460
- specify { expect(CitiesIndex.aliases).to eq(['cities']) }
461
- specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
462
-
463
- context do
464
- before { CitiesIndex.reset!('2014') }
465
-
466
- specify { expect(CitiesIndex.all).to have(1).item }
467
- specify { expect(CitiesIndex.aliases).to eq(['cities']) }
468
- specify { expect(CitiesIndex.indexes).to eq(['cities_2014']) }
469
- specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
470
- end
471
-
472
- context do
473
- before { CitiesIndex.reset! }
474
-
475
- specify { expect(CitiesIndex.all).to have(1).item }
476
- specify { expect(CitiesIndex.aliases).to eq([]) }
477
- specify { expect(CitiesIndex.indexes).to eq(['cities']) }
478
- specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
479
- end
480
- end
481
- end
482
-
483
- context 'reset_disable_refresh_interval' do
484
- let(:suffix) { Time.now.to_i }
485
- let(:name) { CitiesIndex.index_name(suffix: suffix) }
486
- let(:before_import_body) do
487
- {
488
- index: {refresh_interval: -1}
489
- }
490
- end
491
- let(:after_import_body) do
492
- {
493
- index: {refresh_interval: '1s'}
494
- }
495
- end
496
-
497
- before { CitiesIndex.reset!('2013') }
498
- before { allow(Chewy).to receive(:reset_disable_refresh_interval).and_return(reset_disable_refresh_interval) }
499
-
500
- context 'activated' do
501
- let(:reset_disable_refresh_interval) { true }
502
- specify do
503
- expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
504
- expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
505
- expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
506
- expect(CitiesIndex.reset!(suffix)).to eq(true)
507
- end
508
-
509
- context 'refresh_interval already defined' do
510
- before do
511
- stub_index(:cities) do
512
- settings index: {refresh_interval: '2s'}
513
- index_scope City
514
- end
515
- end
516
-
517
- let(:after_import_body) do
518
- {
519
- index: {refresh_interval: '2s'}
520
- }
521
- end
522
-
523
- specify do
524
- expect(CitiesIndex.client.indices)
525
- .to receive(:put_settings).with(index: name, body: before_import_body).once
526
- expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
527
- expect(CitiesIndex)
528
- .to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
529
- expect(CitiesIndex.reset!(suffix)).to eq(true)
530
- end
531
-
532
- specify 'uses empty index settings if not defined' do
533
- allow(Chewy).to receive(:wait_for_status).and_return(nil)
534
- allow(CitiesIndex).to receive(:settings_hash).and_return({})
535
- expect(CitiesIndex.reset!(suffix)).to eq(true)
536
- end
537
- end
538
- end
539
-
540
- context 'not activated' do
541
- let(:reset_disable_refresh_interval) { false }
542
- specify do
543
- expect(CitiesIndex.client.indices).not_to receive(:put_settings)
544
- expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
545
- expect(CitiesIndex.reset!(suffix)).to eq(true)
546
- end
547
- end
548
- end
549
-
550
- context 'reset_no_replicas' do
551
- let(:suffix) { Time.now.to_i }
552
- let(:name) { CitiesIndex.index_name(suffix: suffix) }
553
- let(:before_import_body) do
554
- {
555
- index: {number_of_replicas: 0}
556
- }
557
- end
558
- let(:after_import_body) do
559
- {
560
- index: {number_of_replicas: 0}
561
- }
562
- end
563
-
564
- before { allow(Chewy).to receive(:reset_no_replicas).and_return(reset_no_replicas) }
565
-
566
- context 'activated' do
567
- let(:reset_no_replicas) { true }
568
- specify do
569
- expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
570
- expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
571
- expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
572
- expect(CitiesIndex.reset!(suffix)).to eq(true)
573
- end
574
- end
575
-
576
- context 'not activated' do
577
- let(:reset_no_replicas) { false }
578
- specify do
579
- expect(CitiesIndex.client.indices).not_to receive(:put_settings)
580
- expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
581
- expect(CitiesIndex.reset!(suffix)).to eq(true)
582
- end
583
- end
584
- end
585
-
586
- context 'journaling' do
587
- before { City.create!(id: 1, name: 'Moscow') }
588
-
589
- specify do
590
- CitiesIndex.reset!
591
- expect(Chewy::Stash::Journal.count).to eq(0)
592
- end
593
-
594
- specify do
595
- CitiesIndex.reset! journal: true
596
- expect(Chewy::Stash::Journal.count).to be > 0
597
- end
598
- end
599
-
600
- context 'other options' do
601
- specify do
602
- expect(CitiesIndex).to receive(:import).with(parallel: true, journal: false).once.and_return(true)
603
- expect(CitiesIndex.reset!(parallel: true)).to eq(true)
604
- end
605
-
606
- specify do
607
- expect(CitiesIndex)
608
- .to receive(:import)
609
- .with(suffix: 'suffix', parallel: true, journal: false, refresh: true)
610
- .once.and_return(true)
611
- expect(CitiesIndex.reset!('suffix', parallel: true)).to eq(true)
612
- end
613
- end
614
- end
615
-
616
- describe '.reset' do
617
- before do
618
- stub_model(:city)
619
- stub_index(:cities) do
620
- index_scope City
621
- end
622
- end
623
-
624
- context do
625
- before { City.create!(id: 1, name: 'Moscow') }
626
-
627
- specify { expect(CitiesIndex.reset).to eq(true) }
628
- specify { expect(CitiesIndex.reset('2013')).to eq(true) }
629
-
630
- context do
631
- before { CitiesIndex.reset }
632
-
633
- specify { expect(CitiesIndex.all).to have(1).item }
634
- specify { expect(CitiesIndex.aliases).to eq([]) }
635
- specify { expect(CitiesIndex.indexes).to eq(['cities']) }
636
- end
637
- end
638
- end
639
-
640
- describe '.sync' do
641
- before do
642
- stub_model(:city)
643
- stub_index(:cities) do
644
- index_scope City
645
- field :name
646
- field :updated_at, type: 'date'
647
- end
648
- end
649
-
650
- let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
651
-
652
- before do
653
- CitiesIndex.import
654
- cities.first.destroy
655
- cities.last.update(name: 'Name5')
656
- end
657
-
658
- let!(:additional_city) { City.create!(name: 'Name4') }
659
-
660
- specify do
661
- expect(CitiesIndex.sync).to match(
662
- count: 3,
663
- missing: contain_exactly(cities.first.id.to_s, additional_city.id.to_s),
664
- outdated: [cities.last.id.to_s]
665
- )
666
- end
667
- specify do
668
- expect { CitiesIndex.sync }.to update_index(CitiesIndex)
669
- .and_reindex(additional_city, cities.last)
670
- .and_delete(cities.first).only
671
- end
672
- end
673
-
674
- describe '.journal' do
675
- specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
676
- end
677
-
678
- describe '.clear_cache' do
679
- before do
680
- stub_model(:city)
681
- stub_index(:cities) do
682
- index_scope City
683
- end
684
- end
685
-
686
- let(:index_name) { 'test_index' }
687
- let(:index_name_with_prefix) { 'cities_test_index' }
688
- let(:unexisted_index_name) { 'wrong_index' }
689
-
690
- context 'with existing index' do
691
- before do
692
- CitiesIndex.create(index_name)
693
- end
694
-
695
- specify do
696
- expect(CitiesIndex)
697
- .to receive(:clear_cache)
698
- .and_call_original
699
- expect { CitiesIndex.clear_cache({index: index_name_with_prefix}) }
700
- .not_to raise_error
701
- end
702
- end
703
-
704
- context 'with unexisting index' do
705
- specify do
706
- expect(CitiesIndex)
707
- .to receive(:clear_cache)
708
- .and_call_original
709
- expect { CitiesIndex.clear_cache({index: unexisted_index_name}) }
710
- .to raise_error Elastic::Transport::Transport::Errors::NotFound
711
- end
712
- end
713
-
714
- context 'without arguments' do
715
- before do
716
- CitiesIndex.create
717
- end
718
-
719
- specify do
720
- expect(CitiesIndex)
721
- .to receive(:clear_cache)
722
- .and_call_original
723
- expect { CitiesIndex.clear_cache }
724
- .not_to raise_error
725
- end
726
- end
727
- end
728
-
729
- describe '.reindex' do
730
- before do
731
- stub_model(:city)
732
- stub_index(:cities) do
733
- index_scope City
734
- end
735
- CitiesIndex.create(source_index)
736
- DummiesIndex.create(dest_index)
737
- end
738
-
739
- let(:source_index) { 'source_index' }
740
- let(:source_index_with_prefix) { 'cities_source_index' }
741
- let(:dest_index) { 'dest_index' }
742
- let(:dest_index_with_prefix) { 'dummies_dest_index' }
743
- let(:unexisting_index) { 'wrong_index' }
744
-
745
- context 'with existing indexes' do
746
- specify do
747
- expect(CitiesIndex)
748
- .to receive(:reindex)
749
- .and_call_original
750
- expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: dest_index_with_prefix) }
751
- .not_to raise_error
752
- end
753
- end
754
-
755
- context 'with unexisting indexes' do
756
- context 'source index' do
757
- specify do
758
- expect(CitiesIndex)
759
- .to receive(:reindex)
760
- .and_call_original
761
- expect { CitiesIndex.reindex(source: unexisting_index, dest: dest_index_with_prefix) }
762
- .to raise_error Elastic::Transport::Transport::Errors::NotFound
763
- end
764
- end
765
-
766
- context 'dest index' do
767
- specify do
768
- expect(CitiesIndex)
769
- .to receive(:reindex)
770
- .and_call_original
771
- expect { CitiesIndex.reindex(source: source_index_with_prefix, dest: unexisting_index) }
772
- .not_to raise_error
773
- end
774
- end
775
- end
776
-
777
- context 'with missing indexes' do
778
- context 'without dest index' do
779
- specify do
780
- expect(DummiesIndex)
781
- .to receive(:reindex)
782
- .and_call_original
783
- expect { DummiesIndex.reindex(source: source_index_with_prefix) }
784
- .not_to raise_error
785
- end
786
- end
787
-
788
- context 'without source index' do
789
- specify do
790
- expect(CitiesIndex)
791
- .to receive(:reindex)
792
- .and_call_original
793
- expect { CitiesIndex.reindex(dest: dest_index_with_prefix) }
794
- .not_to raise_error
795
- end
796
- end
797
- end
798
- end
799
-
800
- describe 'update_mapping' do
801
- before do
802
- stub_model(:city)
803
- stub_index(:cities) do
804
- index_scope City
805
- end
806
- CitiesIndex.create
807
- end
808
-
809
- let(:index_name) { CitiesIndex.index_name }
810
- let(:body_hash) { {properties: {new_field: {type: :text}}} }
811
- let(:unexisting_index) { 'wrong_index' }
812
- let(:empty_body_hash) { {} }
813
-
814
- context 'with existing index' do
815
- specify do
816
- expect { CitiesIndex.update_mapping(index_name, body_hash) }
817
- .not_to raise_error
818
- end
819
- end
820
-
821
- context 'with unexisting arguments' do
822
- context 'index name' do
823
- specify do
824
- expect { CitiesIndex.update_mapping(unexisting_index, body_hash) }
825
- .to raise_error Elastic::Transport::Transport::Errors::NotFound
826
- end
827
- end
828
-
829
- context 'body hash' do
830
- specify do
831
- expect { CitiesIndex.update_mapping(index_name, empty_body_hash) }
832
- .not_to raise_error
833
- end
834
- end
835
- end
836
-
837
- context 'with only argument' do
838
- specify do
839
- expect { CitiesIndex.update_mapping(index_name) }
840
- .not_to raise_error
841
- end
842
- end
843
-
844
- context 'without arguments' do
845
- specify do
846
- expect { CitiesIndex.update_mapping }
847
- .not_to raise_error
848
- end
849
- end
850
- end
851
- end