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,656 +0,0 @@
1
- require 'spec_helper'
2
- require 'rake'
3
-
4
- describe Chewy::RakeHelper, :orm do
5
- before { drop_indices }
6
-
7
- before do
8
- described_class.instance_variable_set(:@journal_exists, journal_exists)
9
-
10
- stub_model(:city)
11
- stub_model(:country)
12
-
13
- stub_index(:cities) do
14
- index_scope City
15
- field :name
16
- field :updated_at, type: 'date'
17
- end
18
- stub_index(:countries) do
19
- index_scope Country
20
- end
21
- stub_index(:users)
22
-
23
- allow(described_class).to receive(:all_indexes) { [CitiesIndex, CountriesIndex, UsersIndex] }
24
- end
25
-
26
- let(:journal_exists) { true }
27
- let!(:cities) { Array.new(3) { |i| City.create!(name: "Name#{i + 1}") } }
28
- let!(:countries) { Array.new(2) { |i| Country.create!(name: "Name#{i + 1}") } }
29
- let(:journal) do
30
- Chewy::Stash::Journal.import([
31
- {
32
- index_name: 'cities',
33
- type_name: 'city',
34
- action: 'index',
35
- references: cities.first(2).map(&:id).map(&:to_s)
36
- .map(&:to_json).map(&Base64.method(:encode64)),
37
- created_at: 2.minutes.since
38
- },
39
- {
40
- index_name: 'countries',
41
- type_name: 'country',
42
- action: 'index',
43
- references: [Base64.encode64(countries.first.id.to_s.to_json)],
44
- created_at: 4.minutes.since
45
- }
46
- ])
47
- end
48
-
49
- describe '.reset' do
50
- before { journal }
51
-
52
- specify do
53
- output = StringIO.new
54
- expect { described_class.reset(output: output) }
55
- .to update_index(CitiesIndex)
56
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
57
- \\AResetting CitiesIndex
58
- Imported CitiesIndex in \\d+s, stats: index 3
59
- Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
60
- Imported CitiesIndex in \\d+s, stats: index 2
61
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
62
- Resetting CountriesIndex
63
- Imported CountriesIndex in \\d+s, stats: index 2
64
- Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
65
- Imported CountriesIndex in \\d+s, stats: index 1
66
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
67
- Resetting UsersIndex
68
- Imported UsersIndex in 1s, stats:\s
69
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
70
- Total: \\d+s\\Z
71
- OUTPUT
72
- end
73
-
74
- specify do
75
- output = StringIO.new
76
- expect { described_class.reset(only: 'cities', output: output) }
77
- .to update_index(CitiesIndex)
78
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
79
- \\AResetting CitiesIndex
80
- Imported CitiesIndex in \\d+s, stats: index 3
81
- Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
82
- Imported CitiesIndex in \\d+s, stats: index 2
83
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
84
- Total: \\d+s\\Z
85
- OUTPUT
86
- end
87
-
88
- specify do
89
- output = StringIO.new
90
- expect { described_class.reset(except: [CitiesIndex, CountriesIndex], output: output) }
91
- .not_to update_index(CitiesIndex)
92
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
93
- \\AResetting UsersIndex
94
- Imported UsersIndex in 1s, stats:\s
95
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
96
- Total: \\d+s\\Z
97
- OUTPUT
98
- end
99
-
100
- context 'when journal is missing' do
101
- let(:journal_exists) { false }
102
-
103
- specify do
104
- output = StringIO.new
105
- expect { described_class.reset(only: [CitiesIndex], output: output) }
106
- .to update_index(CitiesIndex)
107
- expect(output.string).to include(
108
- "############################################################\n" \
109
- "WARN: You are risking to lose some changes during the reset.\n " \
110
- "Please consider enabling journaling.\n " \
111
- 'See https://github.com/toptal/chewy#journaling'
112
- )
113
- end
114
- end
115
- end
116
-
117
- describe '.upgrade' do
118
- specify do
119
- output = StringIO.new
120
- expect { described_class.upgrade(output: output) }
121
- .to update_index(CitiesIndex)
122
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
123
- \\AResetting CitiesIndex
124
- Imported CitiesIndex in \\d+s, stats: index 3
125
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
126
- Resetting CountriesIndex
127
- Imported CountriesIndex in \\d+s, stats: index 2
128
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
129
- Resetting UsersIndex
130
- Imported UsersIndex in 1s, stats:\s
131
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
132
- Total: \\d+s\\Z
133
- OUTPUT
134
- end
135
-
136
- context do
137
- before do
138
- CitiesIndex.reset!
139
- CountriesIndex.reset!
140
- end
141
-
142
- specify do
143
- output = StringIO.new
144
- expect { described_class.upgrade(output: output) }
145
- .not_to update_index(CitiesIndex)
146
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
147
- \\ASkipping CitiesIndex, the specification didn't change
148
- Skipping CountriesIndex, the specification didn't change
149
- Resetting UsersIndex
150
- Imported UsersIndex in 1s, stats:\s
151
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
152
- Total: \\d+s\\Z
153
- OUTPUT
154
- end
155
-
156
- specify do
157
- output = StringIO.new
158
- expect { described_class.upgrade(except: [CitiesIndex, CountriesIndex], output: output) }
159
- .not_to update_index(CitiesIndex)
160
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
161
- \\AResetting UsersIndex
162
- Imported UsersIndex in 1s, stats:\s
163
- Imported Chewy::Stash::Specification in \\d+s, stats: index 1
164
- Total: \\d+s\\Z
165
- OUTPUT
166
- end
167
-
168
- context do
169
- before { UsersIndex.reset! }
170
-
171
- specify do
172
- output = StringIO.new
173
- expect { described_class.upgrade(except: %w[cities countries], output: output) }
174
- .not_to update_index(CitiesIndex)
175
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
176
- \\ANo index specification was changed
177
- Total: \\d+s\\Z
178
- OUTPUT
179
- end
180
- end
181
- end
182
- end
183
-
184
- describe '.update' do
185
- specify do
186
- output = StringIO.new
187
- expect { described_class.update(output: output) }
188
- .not_to update_index(CitiesIndex)
189
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
190
- \\ASkipping CitiesIndex, it does not exists \\(use rake chewy:reset\\[cities\\] to create and update it\\)
191
- Skipping CountriesIndex, it does not exists \\(use rake chewy:reset\\[countries\\] to create and update it\\)
192
- Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
193
- Total: \\d+s\\Z
194
- OUTPUT
195
- end
196
-
197
- context do
198
- before do
199
- CitiesIndex.reset!
200
- CountriesIndex.reset!
201
- end
202
-
203
- specify do
204
- output = StringIO.new
205
- expect { described_class.update(output: output) }
206
- .to update_index(CitiesIndex)
207
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
208
- \\AUpdating CitiesIndex
209
- Imported CitiesIndex in \\d+s, stats: index 3
210
- Updating CountriesIndex
211
- Imported CountriesIndex in \\d+s, stats: index 2
212
- Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
213
- Total: \\d+s\\Z
214
- OUTPUT
215
- end
216
-
217
- specify do
218
- output = StringIO.new
219
- expect { described_class.update(only: 'countries', output: output) }
220
- .not_to update_index(CitiesIndex)
221
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
222
- \\AUpdating CountriesIndex
223
- Imported CountriesIndex in \\d+s, stats: index 2
224
- Total: \\d+s\\Z
225
- OUTPUT
226
- end
227
-
228
- specify do
229
- output = StringIO.new
230
- expect { described_class.update(except: CountriesIndex, output: output) }
231
- .to update_index(CitiesIndex)
232
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
233
- \\AUpdating CitiesIndex
234
- Imported CitiesIndex in \\d+s, stats: index 3
235
- Skipping UsersIndex, it does not exists \\(use rake chewy:reset\\[users\\] to create and update it\\)
236
- Total: \\d+s\\Z
237
- OUTPUT
238
- end
239
- end
240
- end
241
-
242
- describe '.sync' do
243
- specify do
244
- output = StringIO.new
245
- expect { described_class.sync(output: output) }
246
- .to update_index(CitiesIndex)
247
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
248
- \\ASynchronizing CitiesIndex
249
- Imported CitiesIndex in \\d+s, stats: index 3
250
- Missing documents: \\[[^\\]]+\\]
251
- Took \\d+s
252
- Synchronizing CountriesIndex
253
- CountriesIndex doesn't support outdated synchronization
254
- Imported CountriesIndex in \\d+s, stats: index 2
255
- Missing documents: \\[[^\\]]+\\]
256
- Took \\d+s
257
- Synchronizing UsersIndex
258
- UsersIndex doesn't support outdated synchronization
259
- Skipping UsersIndex, up to date
260
- Took \\d+s
261
- Total: \\d+s\\Z
262
- OUTPUT
263
- end
264
-
265
- context do
266
- before do
267
- CitiesIndex.import(cities.first(2))
268
- CountriesIndex.import
269
-
270
- cities.first.update(name: 'Name5')
271
- end
272
-
273
- specify do
274
- output = StringIO.new
275
- expect { described_class.sync(output: output) }
276
- .to update_index(CitiesIndex)
277
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
278
- \\ASynchronizing CitiesIndex
279
- Imported CitiesIndex in \\d+s, stats: index 2
280
- Missing documents: \\["#{cities.last.id}"\\]
281
- Outdated documents: \\["#{cities.first.id}"\\]
282
- Took \\d+s
283
- Synchronizing CountriesIndex
284
- CountriesIndex doesn't support outdated synchronization
285
- Skipping CountriesIndex, up to date
286
- Took \\d+s
287
- Synchronizing UsersIndex
288
- UsersIndex doesn't support outdated synchronization
289
- Skipping UsersIndex, up to date
290
- Took \\d+s
291
- Total: \\d+s\\Z
292
- OUTPUT
293
- end
294
-
295
- specify do
296
- output = StringIO.new
297
- expect { described_class.sync(only: CitiesIndex, output: output) }
298
- .to update_index(CitiesIndex)
299
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
300
- \\ASynchronizing CitiesIndex
301
- Imported CitiesIndex in \\d+s, stats: index 2
302
- Missing documents: \\["#{cities.last.id}"\\]
303
- Outdated documents: \\["#{cities.first.id}"\\]
304
- Took \\d+s
305
- Total: \\d+s\\Z
306
- OUTPUT
307
- end
308
-
309
- specify do
310
- output = StringIO.new
311
- expect { described_class.sync(except: ['cities'], output: output) }
312
- .not_to update_index(CitiesIndex)
313
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
314
- \\ASynchronizing CountriesIndex
315
- CountriesIndex doesn't support outdated synchronization
316
- Skipping CountriesIndex, up to date
317
- Took \\d+s
318
- Synchronizing UsersIndex
319
- UsersIndex doesn't support outdated synchronization
320
- Skipping UsersIndex, up to date
321
- Took \\d+s
322
- Total: \\d+s\\Z
323
- OUTPUT
324
- end
325
- end
326
- end
327
-
328
- describe '.journal_apply' do
329
- specify { expect { described_class.journal_apply }.to raise_error ArgumentError }
330
- specify do
331
- output = StringIO.new
332
- described_class.journal_apply(time: Time.now, output: output)
333
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
334
- \\AApplying journal entries created after [+-:\\d\\s]+
335
- No journal entries were created after the specified time
336
- Total: \\d+s\\Z
337
- OUTPUT
338
- end
339
-
340
- context do
341
- before { journal }
342
-
343
- specify do
344
- output = StringIO.new
345
- expect { described_class.journal_apply(time: Time.now, output: output) }
346
- .to update_index(CitiesIndex)
347
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
348
- \\AApplying journal entries created after [+-:\\d\\s]+
349
- Applying journal to \\[CitiesIndex, CountriesIndex\\], 3 entries, stage 1
350
- Imported CitiesIndex in \\d+s, stats: index 2
351
- Imported CountriesIndex in \\d+s, stats: index 1
352
- Total: \\d+s\\Z
353
- OUTPUT
354
- end
355
-
356
- specify do
357
- output = StringIO.new
358
- expect { described_class.journal_apply(time: 3.minutes.since, output: output) }
359
- .not_to update_index(CitiesIndex)
360
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
361
- \\AApplying journal entries created after [+-:\\d\\s]+
362
- Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
363
- Imported CountriesIndex in \\d+s, stats: index 1
364
- Total: \\d+s\\Z
365
- OUTPUT
366
- end
367
-
368
- specify do
369
- output = StringIO.new
370
- expect { described_class.journal_apply(time: Time.now, only: CitiesIndex, output: output) }
371
- .to update_index(CitiesIndex)
372
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
373
- \\AApplying journal entries created after [+-:\\d\\s]+
374
- Applying journal to \\[CitiesIndex\\], 2 entries, stage 1
375
- Imported CitiesIndex in \\d+s, stats: index 2
376
- Total: \\d+s\\Z
377
- OUTPUT
378
- end
379
-
380
- specify do
381
- output = StringIO.new
382
- expect { described_class.journal_apply(time: Time.now, except: CitiesIndex, output: output) }
383
- .not_to update_index(CitiesIndex)
384
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
385
- \\AApplying journal entries created after [+-:\\d\\s]+
386
- Applying journal to \\[CountriesIndex\\], 1 entries, stage 1
387
- Imported CountriesIndex in \\d+s, stats: index 1
388
- Total: \\d+s\\Z
389
- OUTPUT
390
- end
391
- end
392
- end
393
-
394
- describe '.journal_clean' do
395
- before { journal }
396
-
397
- specify do
398
- output = StringIO.new
399
- described_class.journal_clean(output: output)
400
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
401
- \\ACleaned up 2 journal entries
402
- Total: \\d+s\\Z
403
- OUTPUT
404
- end
405
-
406
- specify do
407
- output = StringIO.new
408
- described_class.journal_clean(time: 3.minutes.since, output: output)
409
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
410
- \\ACleaning journal entries created before [+-:\\d\\s]+
411
- Cleaned up 1 journal entries
412
- Total: \\d+s\\Z
413
- OUTPUT
414
- end
415
-
416
- specify do
417
- output = StringIO.new
418
- described_class.journal_clean(only: CitiesIndex, output: output)
419
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
420
- \\ACleaned up 1 journal entries
421
- Total: \\d+s\\Z
422
- OUTPUT
423
- end
424
-
425
- specify do
426
- output = StringIO.new
427
- described_class.journal_clean(except: CitiesIndex, output: output)
428
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
429
- \\ACleaned up 1 journal entries
430
- Total: \\d+s\\Z
431
- OUTPUT
432
- end
433
-
434
- it 'executes asynchronously' do
435
- output = StringIO.new
436
- expect(Chewy.client).to receive(:delete_by_query).with(
437
- {
438
- body: {query: {match_all: {}}},
439
- index: ['chewy_journal'],
440
- refresh: false,
441
- requests_per_second: 10.0,
442
- scroll_size: 200,
443
- wait_for_completion: false
444
- }
445
- ).and_call_original
446
- described_class.journal_clean(
447
- output: output,
448
- delete_by_query_options: {
449
- wait_for_completion: false,
450
- requests_per_second: 10.0,
451
- scroll_size: 200
452
- }
453
- )
454
-
455
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
456
- \\ATask to cleanup the journal has been created, [^\\n]*
457
- Total: \\d+s\\Z
458
- OUTPUT
459
- end
460
-
461
- context 'execute "chewy:journal:clean" rake task' do
462
- subject(:task) { Rake.application['chewy:journal:clean'] }
463
- before do
464
- Rake::DefaultLoader.new.load('lib/tasks/chewy.rake')
465
- Rake::Task.define_task(:environment)
466
- end
467
- it 'does not raise error' do
468
- expect { task.invoke }.to_not raise_error
469
- end
470
- end
471
- end
472
-
473
- describe '.create_missing_indexes!' do
474
- before do
475
- [CountriesIndex, Chewy::Stash::Specification].map(&:create!)
476
-
477
- # To avoid flaky issues when previous specs were run
478
- expect(Chewy::Index).to receive(:descendants).and_return(
479
- [
480
- UsersIndex,
481
- CountriesIndex,
482
- CitiesIndex,
483
- Chewy::Stash::Specification,
484
- Chewy::Stash::Journal
485
- ]
486
- )
487
- end
488
-
489
- specify do
490
- output = StringIO.new
491
- described_class.create_missing_indexes!(output: output)
492
- expect(CitiesIndex.exists?).to be_truthy
493
- expect(UsersIndex.exists?).to be_truthy
494
- expect(Chewy::Stash::Journal.exists?).to be_falsey
495
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
496
- UsersIndex index successfully created
497
- CitiesIndex index successfully created
498
- Total: \\d+s\\Z
499
- OUTPUT
500
- end
501
-
502
- context 'when verbose' do
503
- specify do
504
- output = StringIO.new
505
- described_class.create_missing_indexes!(output: output, env: {'VERBOSE' => '1'})
506
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
507
- UsersIndex index successfully created
508
- CountriesIndex already exists, skipping
509
- CitiesIndex index successfully created
510
- Chewy::Stash::Specification already exists, skipping
511
- Total: \\d+s\\Z
512
- OUTPUT
513
- end
514
- end
515
-
516
- context 'when journaling is enabled' do
517
- before { Chewy.config.settings[:journal] = true }
518
- after { Chewy.config.settings.delete(:journal) }
519
- specify do
520
- described_class.create_missing_indexes!(output: StringIO.new)
521
- expect(Chewy::Stash::Journal.exists?).to be_truthy
522
- end
523
- end
524
- end
525
-
526
- describe '.journal_create' do
527
- specify do
528
- output = StringIO.new
529
- described_class.journal_create(output: output)
530
- expect(Chewy::Stash::Journal.exists?).to be_truthy
531
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
532
- Total: \\d+s\\Z
533
- OUTPUT
534
- end
535
- end
536
-
537
- describe '.reindex' do
538
- before do
539
- journal
540
- CitiesIndex.create!
541
- CountriesIndex.create!
542
- end
543
-
544
- let(:source_index) { 'cities' }
545
- let(:dest_index) { 'countries' }
546
-
547
- context 'with correct arguments' do
548
- specify do
549
- output = StringIO.new
550
- described_class.reindex(source: source_index, dest: dest_index, output: output)
551
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
552
- \\Source index is cities
553
- \\Destination index is countries
554
- cities index successfully reindexed with countries index data
555
- Total: \\d+s\\Z
556
- OUTPUT
557
- end
558
- end
559
-
560
- context 'with missing indexes' do
561
- context 'without dest index' do
562
- specify do
563
- output = StringIO.new
564
- expect { described_class.reindex(source: source_index, output: output) }
565
- .to raise_error ArgumentError
566
- end
567
- end
568
-
569
- context 'without source index' do
570
- specify do
571
- output = StringIO.new
572
- expect { described_class.reindex(dest: dest_index, output: output) }
573
- .to raise_error ArgumentError
574
- end
575
- end
576
- end
577
- end
578
-
579
- describe '.update_mapping' do
580
- before do
581
- journal
582
- CitiesIndex.create!
583
- end
584
-
585
- let(:index_name) { CitiesIndex.index_name }
586
- let(:nonexistent_index) { 'wrong_index' }
587
-
588
- context 'with existing index' do
589
- specify do
590
- output = StringIO.new
591
- described_class.update_mapping(name: index_name, output: output)
592
- expect(output.string).to match(Regexp.new(<<-OUTPUT, Regexp::MULTILINE))
593
- \\Index name is cities
594
- cities index successfully updated
595
- Total: \\d+s\\Z
596
- OUTPUT
597
- end
598
- end
599
-
600
- context 'with non-existent index name' do
601
- specify do
602
- output = StringIO.new
603
- expect { described_class.update_mapping(name: nonexistent_index, output: output) }
604
- .to raise_error NameError
605
- end
606
- end
607
- end
608
-
609
- describe '.delete_by_query_options_from_env' do
610
- subject(:options) { described_class.delete_by_query_options_from_env(env) }
611
- let(:env) do
612
- {
613
- 'WAIT_FOR_COMPLETION' => 'false',
614
- 'REQUESTS_PER_SECOND' => '10',
615
- 'SCROLL_SIZE' => '5000'
616
- }
617
- end
618
-
619
- it 'parses the options' do
620
- expect(options).to eq(
621
- wait_for_completion: false,
622
- requests_per_second: 10.0,
623
- scroll_size: 5000
624
- )
625
- end
626
-
627
- context 'with different boolean values' do
628
- it 'parses the option correctly' do
629
- %w[1 t true TRUE on ON].each do |v|
630
- expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
631
- .to eq(wait_for_completion: true)
632
- end
633
-
634
- %w[0 f false FALSE off OFF].each do |v|
635
- expect(described_class.delete_by_query_options_from_env({'WAIT_FOR_COMPLETION' => v}))
636
- .to eq(wait_for_completion: false)
637
- end
638
- end
639
- end
640
-
641
- context 'with other env' do
642
- let(:env) { {'SOME_ENV' => '123', 'REQUESTS_PER_SECOND' => '15'} }
643
-
644
- it 'parses only the options' do
645
- expect(options).to eq(requests_per_second: 15.0)
646
- end
647
- end
648
- end
649
-
650
- describe '.subscribed_task_stats' do
651
- specify do
652
- block_output = described_class.subscribed_task_stats(StringIO.new) { 'expected output' }
653
- expect(block_output).to eq('expected output')
654
- end
655
- end
656
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chewy::Repository do
4
- subject { described_class.send(:new) }
5
-
6
- specify { expect(subject.analyzers).to eq({}) }
7
- specify { expect(subject.tokenizers).to eq({}) }
8
- specify { expect(subject.filters).to eq({}) }
9
- specify { expect(subject.char_filters).to eq({}) }
10
-
11
- describe '#analyzer' do
12
- specify { expect(subject.analyzer(:name)).to be_nil }
13
-
14
- context do
15
- before { subject.analyzer(:name, option: :foo) }
16
- specify { expect(subject.analyzer(:name)).to eq(option: :foo) }
17
- specify { expect(subject.analyzers).to eq(name: {option: :foo}) }
18
- end
19
- end
20
-
21
- describe '#tokenizer' do
22
- specify { expect(subject.tokenizer(:name)).to be_nil }
23
-
24
- context do
25
- before { subject.tokenizer(:name, option: :foo) }
26
- specify { expect(subject.tokenizer(:name)).to eq(option: :foo) }
27
- specify { expect(subject.tokenizers).to eq(name: {option: :foo}) }
28
- end
29
- end
30
-
31
- describe '#filter' do
32
- specify { expect(subject.filter(:name)).to be_nil }
33
-
34
- context do
35
- before { subject.filter(:name, option: :foo) }
36
- specify { expect(subject.filter(:name)).to eq(option: :foo) }
37
- specify { expect(subject.filters).to eq(name: {option: :foo}) }
38
- end
39
- end
40
-
41
- describe '#char_filter' do
42
- specify { expect(subject.char_filter(:name)).to be_nil }
43
-
44
- context do
45
- before { subject.char_filter(:name, option: :foo) }
46
- specify { expect(subject.char_filter(:name)).to eq(option: :foo) }
47
- specify { expect(subject.char_filters).to eq(name: {option: :foo}) }
48
- end
49
- end
50
- end