chewy 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +43 -11
  3. data/Appraisals +39 -12
  4. data/CHANGELOG.md +42 -0
  5. data/Gemfile +1 -1
  6. data/README.md +60 -7
  7. data/chewy.gemspec +12 -5
  8. data/gemfiles/{rails.4.0.mongoid.gemfile → rails.4.0.mongoid.4.0.0.gemfile} +1 -1
  9. data/gemfiles/{rails.4.0.mongoid.kaminari.gemfile → rails.4.0.mongoid.4.0.0.kaminari.gemfile} +1 -1
  10. data/gemfiles/{rails.4.0.mongoid.will_paginate.gemfile → rails.4.0.mongoid.4.0.0.will_paginate.gemfile} +1 -1
  11. data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +15 -0
  12. data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +14 -0
  13. data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +14 -0
  14. data/gemfiles/{rails.4.1.mongoid.gemfile → rails.4.1.mongoid.4.0.0.gemfile} +1 -1
  15. data/gemfiles/{rails.4.1.mongoid.kaminari.gemfile → rails.4.1.mongoid.4.0.0.kaminari.gemfile} +1 -1
  16. data/gemfiles/{rails.4.1.mongoid.will_paginate.gemfile → rails.4.1.mongoid.4.0.0.will_paginate.gemfile} +1 -1
  17. data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +15 -0
  18. data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +14 -0
  19. data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +14 -0
  20. data/gemfiles/{rails.4.2.mongoid.gemfile → rails.4.2.mongoid.4.0.0.gemfile} +1 -1
  21. data/gemfiles/{rails.4.2.mongoid.kaminari.gemfile → rails.4.2.mongoid.4.0.0.kaminari.gemfile} +1 -1
  22. data/gemfiles/{rails.4.2.mongoid.will_paginate.gemfile → rails.4.2.mongoid.4.0.0.will_paginate.gemfile} +1 -1
  23. data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +15 -0
  24. data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +14 -0
  25. data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +14 -0
  26. data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +16 -0
  27. data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +16 -0
  28. data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +15 -0
  29. data/gemfiles/{sequel.4.28.gemfile → sequel.4.31.gemfile} +1 -1
  30. data/lib/chewy.rb +7 -1
  31. data/lib/chewy/errors.rb +6 -0
  32. data/lib/chewy/fields/base.rb +12 -8
  33. data/lib/chewy/fields/root.rb +1 -1
  34. data/lib/chewy/index.rb +17 -8
  35. data/lib/chewy/index/actions.rb +4 -4
  36. data/lib/chewy/query.rb +8 -13
  37. data/lib/chewy/query/compose.rb +2 -2
  38. data/lib/chewy/query/criteria.rb +2 -2
  39. data/lib/chewy/query/loading.rb +1 -1
  40. data/lib/chewy/query/nodes/bool.rb +1 -1
  41. data/lib/chewy/query/nodes/regexp.rb +2 -2
  42. data/lib/chewy/railtie.rb +15 -3
  43. data/lib/chewy/rake_helper.rb +5 -2
  44. data/lib/chewy/rspec/update_index.rb +17 -6
  45. data/lib/chewy/strategy.rb +7 -3
  46. data/lib/chewy/strategy/active_job.rb +2 -2
  47. data/lib/chewy/strategy/resque.rb +2 -2
  48. data/lib/chewy/strategy/sidekiq.rb +2 -2
  49. data/lib/chewy/type.rb +14 -0
  50. data/lib/chewy/type/adapter/active_record.rb +11 -1
  51. data/lib/chewy/type/adapter/orm.rb +13 -11
  52. data/lib/chewy/type/adapter/sequel.rb +10 -12
  53. data/lib/chewy/type/import.rb +53 -22
  54. data/lib/chewy/type/witchcraft.rb +208 -0
  55. data/lib/chewy/type/wrapper.rb +25 -7
  56. data/lib/chewy/version.rb +1 -1
  57. data/lib/tasks/chewy.rake +22 -14
  58. data/spec/chewy/fields/base_spec.rb +6 -2
  59. data/spec/chewy/fields/time_fields_spec.rb +4 -4
  60. data/spec/chewy/index/actions_spec.rb +32 -18
  61. data/spec/chewy/index_spec.rb +19 -0
  62. data/spec/chewy/query/pagination_spec.rb +1 -1
  63. data/spec/chewy/query_spec.rb +77 -21
  64. data/spec/chewy/rspec/update_index_spec.rb +75 -62
  65. data/spec/chewy/runtime_spec.rb +1 -1
  66. data/spec/chewy/strategy/active_job_spec.rb +6 -1
  67. data/spec/chewy/strategy/atomic_spec.rb +5 -5
  68. data/spec/chewy/strategy/resque_spec.rb +7 -2
  69. data/spec/chewy/strategy/sidekiq_spec.rb +6 -1
  70. data/spec/chewy/strategy_spec.rb +13 -1
  71. data/spec/chewy/type/actions_spec.rb +4 -1
  72. data/spec/chewy/type/import_spec.rb +71 -2
  73. data/spec/chewy/type/observe_spec.rb +9 -9
  74. data/spec/chewy/type/witchcraft_spec.rb +154 -0
  75. data/spec/chewy/type/wrapper_spec.rb +30 -5
  76. data/spec/chewy/type_spec.rb +10 -0
  77. data/spec/chewy_spec.rb +29 -5
  78. data/spec/spec_helper.rb +2 -0
  79. data/spec/support/class_helpers.rb +15 -0
  80. data/spec/support/mongoid.rb +5 -0
  81. metadata +64 -21
@@ -68,6 +68,11 @@ describe Chewy::Index do
68
68
  end
69
69
  end
70
70
 
71
+ describe '.default_prefix' do
72
+ before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
73
+ specify { expect(Class.new(Chewy::Index).default_prefix).to eq('testing') }
74
+ end
75
+
71
76
  describe '.define_type' do
72
77
  specify { expect(DummiesIndex.type_hash['dummy']).to eq(DummiesIndex::Dummy) }
73
78
 
@@ -108,6 +113,20 @@ describe Chewy::Index do
108
113
  }.to raise_error(NameError)
109
114
  end
110
115
  end
116
+
117
+ context 'type methods should be deprecated and can\'t redefine existion ones' do
118
+ before do
119
+ stub_index(:places) do
120
+ def self.city
121
+ end
122
+ define_type :city
123
+ define_type :country
124
+ end
125
+ end
126
+
127
+ specify { expect(PlacesIndex.city).to be_nil }
128
+ specify { expect(PlacesIndex.country).to be < Chewy::Type }
129
+ end
111
130
  end
112
131
 
113
132
  describe '.type_hash' do
@@ -24,7 +24,7 @@ describe Chewy::Query::Pagination do
24
24
  describe '#total_count' do
25
25
  specify { expect(search.total_count).to eq(10) }
26
26
  specify { expect(search.limit(5).total_count).to eq(10) }
27
- specify { expect(search.filter(numeric_range: {age: {gt: 20}}).limit(3).total_count).to eq(8) }
27
+ specify { expect(search.filter(range: {age: {gt: 20}}).limit(3).total_count).to eq(8) }
28
28
  end
29
29
 
30
30
  describe '#load' do
@@ -33,7 +33,8 @@ describe Chewy::Query do
33
33
  specify { expect(subject.first._data).to be_a Hash }
34
34
  specify { expect(subject.limit(6).count).to eq(6) }
35
35
  specify { expect(subject.offset(6).count).to eq(3) }
36
- specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name).to eq('<em>Name3</em>') }
36
+ specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name).to eq('Name3') }
37
+ specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first.name_highlight).to eq('<em>Name3</em>') }
37
38
  specify { expect(subject.query(match: {name: 'name3'}).highlight(fields: {name: {}}).first._data['_source']['name']).to eq('Name3') }
38
39
  specify { expect(subject.types(:product).count).to eq(3) }
39
40
  specify { expect(subject.types(:product, :country).count).to eq(6) }
@@ -174,10 +175,27 @@ describe Chewy::Query do
174
175
  end
175
176
 
176
177
  describe '#facets' do
177
- specify { expect(subject.facets(term: {field: 'hello'})).to be_a described_class }
178
- specify { expect(subject.facets(term: {field: 'hello'})).not_to eq(subject) }
179
- specify { expect(subject.facets(term: {field: 'hello'}).criteria.facets).to include(term: {field: 'hello'}) }
180
- specify { expect { subject.facets(term: {field: 'hello'}) }.not_to change { subject.criteria.facets } }
178
+ specify do
179
+ skip_on_version_lt('2.0')
180
+ expect { subject.facets }.to raise_error(Chewy::RemovedFeature).with_message('removed in elasticsearch 2.0')
181
+ end
182
+
183
+ specify do
184
+ skip_on_version_gte('2.0')
185
+ expect(subject.facets(term: {field: 'hello'})).to be_a described_class
186
+ end
187
+ specify do
188
+ skip_on_version_gte('2.0')
189
+ expect(subject.facets(term: {field: 'hello'})).not_to eq(subject)
190
+ end
191
+ specify do
192
+ skip_on_version_gte('2.0')
193
+ expect(subject.facets(term: {field: 'hello'}).criteria.facets).to include(term: {field: 'hello'})
194
+ end
195
+ specify do
196
+ skip_on_version_gte('2.0')
197
+ expect { subject.facets(term: {field: 'hello'}) }.not_to change { subject.criteria.facets }
198
+ end
181
199
 
182
200
  context 'results', :orm do
183
201
  before { stub_model(:city) }
@@ -193,17 +211,23 @@ describe Chewy::Query do
193
211
 
194
212
  before { CitiesIndex::City.import! cities }
195
213
 
196
- specify { expect(CitiesIndex.facets).to eq({}) }
197
- specify { expect(CitiesIndex.facets(ratings: {terms: {field: 'rating'}}).facets).to eq({
198
- 'ratings' => {
199
- '_type' => 'terms', 'missing' => 0, 'total' => 10, 'other' => 0,
200
- 'terms' => [
201
- {'term' => 0, 'count' => 4},
202
- {'term' => 2, 'count' => 3},
203
- {'term' => 1, 'count' => 3}
204
- ]
205
- }
206
- }) }
214
+ specify do
215
+ skip_on_version_gte('2.0')
216
+ expect(CitiesIndex.facets).to eq({})
217
+ end
218
+ specify do
219
+ skip_on_version_gte('2.0')
220
+ expect(CitiesIndex.facets(ratings: {terms: {field: 'rating'}}).facets).to eq({
221
+ 'ratings' => {
222
+ '_type' => 'terms', 'missing' => 0, 'total' => 10, 'other' => 0,
223
+ 'terms' => [
224
+ {'term' => 0, 'count' => 4},
225
+ {'term' => 2, 'count' => 3},
226
+ {'term' => 1, 'count' => 3}
227
+ ]
228
+ }
229
+ })
230
+ end
207
231
  end
208
232
  end
209
233
 
@@ -357,11 +381,42 @@ describe Chewy::Query do
357
381
  ProductsIndex::Country.import!(countries.map { |h| double(h) })
358
382
  end
359
383
 
360
- specify { expect { subject.query(match: {name: 'name3'}).delete_all }.to change { ProductsIndex.total }.from(9).to(8) }
361
- specify { expect { subject.filter { age == [10, 20] }.delete_all }.to change { ProductsIndex.total_count }.from(9).to(7) }
362
- specify { expect { subject.types(:product).delete_all }.to change { ProductsIndex::Product.total_entries }.from(3).to(0) }
363
- specify { expect { ProductsIndex.delete_all }.to change { ProductsIndex.total }.from(9).to(0) }
364
- specify { expect { ProductsIndex::City.delete_all }.to change { ProductsIndex.total }.from(9).to(6) }
384
+ specify do
385
+ skip_on_plugin_missing_from_version('delete-by-query', '2.0')
386
+ expect {
387
+ subject.query(match: {name: 'name3'}).delete_all
388
+ Chewy.client.indices.refresh(index: 'products') }.to change { ProductsIndex.total }.from(9).to(8)
389
+ end
390
+ specify do
391
+ skip_on_plugin_missing_from_version('delete-by-query', '2.0')
392
+ expect {
393
+ subject.filter { age == [10, 20] }.delete_all
394
+ Chewy.client.indices.refresh(index: 'products') }.to change { ProductsIndex.total_count }.from(9).to(7)
395
+ end
396
+ specify do
397
+ skip_on_plugin_missing_from_version('delete-by-query', '2.0')
398
+ expect {
399
+ subject.types(:product).delete_all
400
+ Chewy.client.indices.refresh(index: 'products') }.to change { ProductsIndex::Product.total_entries }.from(3).to(0)
401
+ end
402
+ specify do
403
+ skip_on_plugin_missing_from_version('delete-by-query', '2.0')
404
+ expect {
405
+ ProductsIndex.delete_all
406
+ Chewy.client.indices.refresh(index: 'products') }.to change { ProductsIndex.total }.from(9).to(0)
407
+ end
408
+ specify do
409
+ skip_on_plugin_missing_from_version('delete-by-query', '2.0')
410
+ expect {
411
+ ProductsIndex::City.delete_all
412
+ Chewy.client.indices.refresh(index: 'products') }.to change { ProductsIndex.total }.from(9).to(6)
413
+ end
414
+
415
+ specify do
416
+ skip_on_version_lt('2.0')
417
+ expect(Chewy.client.nodes).to receive(:info).and_return({"nodes" => {"a" => {"plugins" => {"name" => "hello"}}}})
418
+ expect { ProductsIndex.delete_all }.to raise_error(Chewy::PluginMissing).with_message("install delete-by-query plugin")
419
+ end
365
420
  end
366
421
 
367
422
  describe '#find' do
@@ -447,6 +502,7 @@ describe Chewy::Query do
447
502
  specify { expect(subject.order(:field).criteria.sort).to eq([:field]) }
448
503
  specify { expect(subject.order([:field1, :field2]).criteria.sort).to eq([:field1, :field2]) }
449
504
  specify { expect(subject.order(field: :asc).criteria.sort).to eq([{field: :asc}]) }
505
+ specify { expect(subject.order({field1: :asc, field2: :desc}).criteria.sort).to eq([{field1: :asc}, {field2: :desc}]) }
450
506
  specify { expect(subject.order({field1: {order: :asc}, field2: :desc}).order([:field3], :field4).criteria.sort).to eq([{field1: {order: :asc}}, {field2: :desc}, :field3, :field4]) }
451
507
  end
452
508
 
@@ -11,17 +11,17 @@ describe :update_index do
11
11
  end
12
12
  end
13
13
 
14
- specify { expect { }.not_to update_index(DummiesIndex.dummy) }
15
- specify { expect { DummiesIndex.dummy.bulk body: [] }.not_to update_index(DummiesIndex.dummy) }
14
+ specify { expect { }.not_to update_index(DummiesIndex::Dummy) }
15
+ specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex::Dummy) }
16
16
 
17
- specify { expect { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex.dummy) }
17
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex::Dummy) }
18
18
  .to fail_with(/Expected index .* not to be updated, but it was with/) }
19
19
 
20
20
  context do
21
21
  let(:expectation) do
22
22
  expect { expect {
23
- DummiesIndex.dummy.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
24
- }.not_to update_index(DummiesIndex.dummy) }
23
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
24
+ }.not_to update_index(DummiesIndex::Dummy) }
25
25
  end
26
26
 
27
27
  specify { expectation.to fail_matching 'document id `42` (2 times)' }
@@ -29,49 +29,62 @@ describe :update_index do
29
29
  end
30
30
 
31
31
  context '#only' do
32
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
33
- .to update_index(DummiesIndex.dummy).and_reindex(41, 42).only }
34
- specify { expect { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
35
- .to update_index(DummiesIndex.dummy).and_reindex(41).only }
32
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
33
+ .to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only }
34
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
35
+ .to update_index(DummiesIndex::Dummy).and_reindex(41).only }
36
36
  .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also' }
37
- specify { expect { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
38
- .to update_index(DummiesIndex.dummy).and_reindex(41, times: 2).only }
37
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
38
+ .to update_index(DummiesIndex::Dummy).and_reindex(41, times: 2).only }
39
39
  .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also' }
40
40
 
41
- specify { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
42
- .to update_index(DummiesIndex.dummy).and_delete(41, 42).only }
43
- specify { expect { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
44
- .to update_index(DummiesIndex.dummy).and_delete(41).only }
41
+ specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
42
+ .to update_index(DummiesIndex::Dummy).and_delete(41, 42).only }
43
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
44
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only }
45
45
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also' }
46
- specify { expect { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
47
- .to update_index(DummiesIndex.dummy).and_delete(41, times: 2).only }
46
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
47
+ .to update_index(DummiesIndex::Dummy).and_delete(41, times: 2).only }
48
48
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also' }
49
+
50
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
51
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).only }
52
+ .to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also' }
53
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}, index: {_id: 43, data: {}}}, {delete: {_id: 41}}] }
54
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).only }
55
+ .to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also' }
56
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
57
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only }
58
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also' }
59
+ specify { expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}, delete: {_id: 43}}] }
60
+ .to update_index(DummiesIndex::Dummy).and_delete(41).only }
61
+ .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also' }
49
62
  end
50
63
 
51
64
  context '#and_reindex' do
52
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex.dummy) }
53
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}] }
54
- .to update_index(DummiesIndex.dummy).and_reindex(42) }
55
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
56
- .to update_index(DummiesIndex.dummy).and_reindex(double(id: 42)) }
57
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
58
- .to update_index(DummiesIndex.dummy).and_reindex(double(id: 42), double(id: 43)) }
59
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
60
- .to update_index(DummiesIndex.dummy).and_reindex([double(id: 42), 43]) }
65
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex::Dummy) }
66
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}] }
67
+ .to update_index(DummiesIndex::Dummy).and_reindex(42) }
68
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
69
+ .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42)) }
70
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
71
+ .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42), double(id: 43)) }
72
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
73
+ .to update_index(DummiesIndex::Dummy).and_reindex([double(id: 42), 43]) }
61
74
 
62
75
  specify do
63
76
  expect {
64
77
  expect {
65
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
66
- }.to update_index(DummiesIndex.dummy).and_reindex([44, 43])
78
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
79
+ }.to update_index(DummiesIndex::Dummy).and_reindex([44, 43])
67
80
  }.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
68
81
  end
69
82
 
70
83
  context do
71
84
  let(:expectation) do
72
85
  expect { expect {
73
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
74
- }.to update_index(DummiesIndex.dummy).and_reindex(44, double(id: 47)) }
86
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
87
+ }.to update_index(DummiesIndex::Dummy).and_reindex(44, double(id: 47)) }
75
88
  end
76
89
 
77
90
  specify { expectation.to fail_matching('Expected document with id `44` to be reindexed, but it was not') }
@@ -80,22 +93,22 @@ describe :update_index do
80
93
 
81
94
  context ':times' do
82
95
  specify { expect {
83
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
84
- DummiesIndex.dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
85
- }.to update_index(DummiesIndex.dummy).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) }
96
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
97
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
98
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) }
86
99
 
87
100
  specify { expect {
88
101
  expect {
89
- DummiesIndex.dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
90
- }.to update_index(DummiesIndex.dummy).and_reindex(42, times: 3)
102
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
103
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3)
91
104
  }.to fail_matching('Expected document with id `42` to be reindexed, but it was not') }
92
105
 
93
106
  context do
94
107
  let(:expectation) do
95
108
  expect { expect {
96
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
97
- DummiesIndex.dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
98
- }.to update_index(DummiesIndex.dummy).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) }
109
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
110
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
111
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) }
99
112
  end
100
113
 
101
114
  specify { expectation.to fail_matching 'Expected document with id `44` to be reindexed' }
@@ -107,17 +120,17 @@ describe :update_index do
107
120
 
108
121
  context ':with' do
109
122
  specify { expect {
110
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
111
- }.to update_index(DummiesIndex.dummy).and_reindex(42, with: {a: 2}) }
123
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
124
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 2}) }
112
125
 
113
126
  specify { expect {
114
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
115
- }.to update_index(DummiesIndex.dummy).and_reindex(42, with: {a: '1', b: 2}) }
127
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
128
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: '1', b: 2}) }
116
129
 
117
130
  specify { expect {
118
131
  expect {
119
- DummiesIndex.dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
120
- }.to update_index(DummiesIndex.dummy).and_reindex(42, with: {a: 1})
132
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
133
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 1})
121
134
  }.to fail_matching('Expected document with id `42` to be reindexed, but it was not') }
122
135
 
123
136
  [
@@ -128,8 +141,8 @@ describe :update_index do
128
141
  [{a: 1, b: 1}, {a: 1}]
129
142
  ].each do |(data, with)|
130
143
  specify { expect {
131
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: data}}]
132
- }.to update_index(DummiesIndex.dummy).and_reindex(42, with: with) }
144
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
145
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with) }
133
146
  end
134
147
 
135
148
  [
@@ -141,16 +154,16 @@ describe :update_index do
141
154
  ].each do |(data, with)|
142
155
  specify { expect {
143
156
  expect {
144
- DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: data}}]
145
- }.to update_index(DummiesIndex.dummy).and_reindex(42, with: with)
157
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
158
+ }.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with)
146
159
  }.to fail_matching('Expected document with id `42` to be reindexed') }
147
160
  end
148
161
 
149
162
  context do
150
163
  let(:expectation) do
151
164
  expect { expect {
152
- DummiesIndex.dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
153
- }.to update_index(DummiesIndex.dummy).and_reindex(43, times: 2, with: {a: 2}) }
165
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
166
+ }.to update_index(DummiesIndex::Dummy).and_reindex(43, times: 2, with: {a: 2}) }
154
167
  end
155
168
 
156
169
  specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed' }
@@ -161,19 +174,19 @@ describe :update_index do
161
174
  end
162
175
 
163
176
  context '#and_delete' do
164
- specify { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
165
- .to update_index(DummiesIndex.dummy).and_reindex(42).and_delete(double(id: 43)) }
166
- specify { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
167
- .to update_index(DummiesIndex.dummy).and_delete(42).and_delete(double(id: 43)) }
168
- specify { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
169
- .to update_index(DummiesIndex.dummy).and_delete(42, double(id: 43)) }
170
- specify { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
171
- .to update_index(DummiesIndex.dummy).and_delete([43, double(id: 42)]) }
177
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
178
+ .to update_index(DummiesIndex::Dummy).and_reindex(42).and_delete(double(id: 43)) }
179
+ specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
180
+ .to update_index(DummiesIndex::Dummy).and_delete(42).and_delete(double(id: 43)) }
181
+ specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
182
+ .to update_index(DummiesIndex::Dummy).and_delete(42, double(id: 43)) }
183
+ specify { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
184
+ .to update_index(DummiesIndex::Dummy).and_delete([43, double(id: 42)]) }
172
185
 
173
186
  context do
174
187
  let(:expectation) do
175
- expect { expect { DummiesIndex.dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
176
- .to update_index(DummiesIndex.dummy).and_reindex(43).and_delete(double(id: 42)) }
188
+ expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
189
+ .to update_index(DummiesIndex::Dummy).and_reindex(43).and_delete(double(id: 42)) }
177
190
  end
178
191
 
179
192
  specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed, but it was not' }
@@ -182,8 +195,8 @@ describe :update_index do
182
195
 
183
196
  context do
184
197
  let(:expectation) do
185
- expect { expect { DummiesIndex.dummy.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
186
- .to update_index(DummiesIndex.dummy).and_delete(44, times: 2).and_delete(double(id: 42), times: 3) }
198
+ expect { expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
199
+ .to update_index(DummiesIndex::Dummy).and_delete(44, times: 2).and_delete(double(id: 42), times: 3) }
187
200
  end
188
201
 
189
202
  specify { expectation.to fail_matching 'Expected document with id `44` to be deleted, but it was not' }
@@ -4,6 +4,6 @@ describe Chewy::Runtime do
4
4
  describe '.version' do
5
5
  specify { expect(described_class.version).to be_a(described_class::Version) }
6
6
  specify { expect(described_class.version).to be >= '1.0' }
7
- specify { expect(described_class.version).to be < '1.8' }
7
+ specify { expect(described_class.version).to be < '2.2' }
8
8
  end
9
9
  end
@@ -43,7 +43,12 @@ if defined?(::ActiveJob)
43
43
  ::ActiveJob::Base.queue_adapter = :inline
44
44
  expect { [city, other_city].map(&:save!) }
45
45
  .to update_index(CitiesIndex::City, strategy: :active_job)
46
- .and_reindex(city, other_city)
46
+ .and_reindex(city, other_city).only
47
+ end
48
+
49
+ specify do
50
+ expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], {suffix: '201601'})
51
+ Chewy::Strategy::ActiveJob::Worker.new.perform("CitiesIndex::City", [city.id, other_city.id], suffix: '201601')
47
52
  end
48
53
  end
49
54
  end
@@ -19,13 +19,13 @@ describe Chewy::Strategy::Atomic, :orm do
19
19
  specify do
20
20
  expect { [country, other_country].map(&:save!) }
21
21
  .to update_index(CountriesIndex::Country, strategy: :atomic)
22
- .and_reindex(country, other_country)
22
+ .and_reindex(country, other_country).only
23
23
  end
24
24
 
25
25
  specify do
26
26
  expect { [country, other_country].map(&:destroy) }
27
27
  .to update_index(CountriesIndex::Country, strategy: :atomic)
28
- .and_delete(country, other_country)
28
+ .and_delete(country, other_country).only
29
29
  end
30
30
 
31
31
  context do
@@ -41,19 +41,19 @@ describe Chewy::Strategy::Atomic, :orm do
41
41
  specify do
42
42
  expect { [country, other_country].map(&:save!) }
43
43
  .to update_index(CountriesIndex::Country, strategy: :atomic)
44
- .and_reindex('HL', 'WD')
44
+ .and_reindex('HL', 'WD').only
45
45
  end
46
46
 
47
47
  specify do
48
48
  expect { [country, other_country].map(&:destroy) }
49
49
  .to update_index(CountriesIndex::Country, strategy: :atomic)
50
- .and_delete('HL', 'WD')
50
+ .and_delete('HL', 'WD').only
51
51
  end
52
52
 
53
53
  specify do
54
54
  expect { country.save!; other_country.destroy }
55
55
  .to update_index(CountriesIndex::Country, strategy: :atomic)
56
- .and_reindex('HL').and_delete('WD')
56
+ .and_reindex('HL').and_delete('WD').only
57
57
  end
58
58
  end
59
59
  end