chewy 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +58 -0
  3. data/.rubocop.yml +13 -8
  4. data/.rubocop_todo.yml +110 -22
  5. data/CHANGELOG.md +53 -0
  6. data/Gemfile +0 -7
  7. data/Guardfile +3 -1
  8. data/README.md +282 -245
  9. data/chewy.gemspec +3 -5
  10. data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
  11. data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
  12. data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
  13. data/lib/chewy.rb +21 -75
  14. data/lib/chewy/config.rb +40 -40
  15. data/lib/chewy/errors.rb +0 -12
  16. data/lib/chewy/fields/base.rb +11 -1
  17. data/lib/chewy/fields/root.rb +3 -4
  18. data/lib/chewy/index.rb +46 -87
  19. data/lib/chewy/index/actions.rb +51 -32
  20. data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
  21. data/lib/chewy/{type → index}/adapter/base.rb +2 -3
  22. data/lib/chewy/{type → index}/adapter/object.rb +27 -31
  23. data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
  24. data/lib/chewy/{type → index}/crutch.rb +5 -5
  25. data/lib/chewy/{type → index}/import.rb +36 -27
  26. data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
  27. data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
  28. data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
  29. data/lib/chewy/{type → index}/import/routine.rb +15 -14
  30. data/lib/chewy/{type → index}/mapping.rb +26 -31
  31. data/lib/chewy/{type → index}/observe.rb +9 -19
  32. data/lib/chewy/index/specification.rb +1 -0
  33. data/lib/chewy/{type → index}/syncer.rb +60 -57
  34. data/lib/chewy/{type → index}/witchcraft.rb +11 -7
  35. data/lib/chewy/{type → index}/wrapper.rb +2 -2
  36. data/lib/chewy/journal.rb +8 -8
  37. data/lib/chewy/minitest/helpers.rb +9 -13
  38. data/lib/chewy/minitest/search_index_receiver.rb +22 -26
  39. data/lib/chewy/railtie.rb +4 -2
  40. data/lib/chewy/rake_helper.rb +82 -107
  41. data/lib/chewy/rspec/update_index.rb +47 -43
  42. data/lib/chewy/search.rb +4 -17
  43. data/lib/chewy/search/loader.rb +18 -30
  44. data/lib/chewy/search/parameters.rb +4 -2
  45. data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
  46. data/lib/chewy/search/parameters/source.rb +5 -1
  47. data/lib/chewy/search/query_proxy.rb +9 -2
  48. data/lib/chewy/search/request.rb +82 -86
  49. data/lib/chewy/search/response.rb +4 -4
  50. data/lib/chewy/search/scoping.rb +6 -7
  51. data/lib/chewy/search/scrolling.rb +11 -11
  52. data/lib/chewy/stash.rb +14 -22
  53. data/lib/chewy/strategy.rb +3 -19
  54. data/lib/chewy/strategy/sidekiq.rb +1 -0
  55. data/lib/chewy/version.rb +1 -1
  56. data/lib/generators/chewy/install_generator.rb +1 -1
  57. data/lib/tasks/chewy.rake +10 -22
  58. data/migration_guide.md +14 -0
  59. data/spec/chewy/config_spec.rb +14 -39
  60. data/spec/chewy/fields/base_spec.rb +412 -148
  61. data/spec/chewy/fields/root_spec.rb +16 -24
  62. data/spec/chewy/fields/time_fields_spec.rb +5 -5
  63. data/spec/chewy/index/actions_spec.rb +270 -24
  64. data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
  65. data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
  66. data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
  67. data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
  68. data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
  69. data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
  70. data/spec/chewy/{type → index}/import_spec.rb +102 -98
  71. data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
  72. data/spec/chewy/index/observe_spec.rb +116 -0
  73. data/spec/chewy/index/settings_spec.rb +3 -1
  74. data/spec/chewy/index/specification_spec.rb +7 -17
  75. data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
  76. data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
  77. data/spec/chewy/index/wrapper_spec.rb +100 -0
  78. data/spec/chewy/index_spec.rb +59 -102
  79. data/spec/chewy/journal_spec.rb +9 -22
  80. data/spec/chewy/minitest/helpers_spec.rb +13 -15
  81. data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
  82. data/spec/chewy/multi_search_spec.rb +4 -5
  83. data/spec/chewy/rake_helper_spec.rb +145 -55
  84. data/spec/chewy/rspec/update_index_spec.rb +74 -71
  85. data/spec/chewy/search/loader_spec.rb +19 -37
  86. data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
  87. data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
  88. data/spec/chewy/search/parameters/indices_spec.rb +2 -8
  89. data/spec/chewy/search/parameters/order_spec.rb +1 -1
  90. data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
  91. data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
  92. data/spec/chewy/search/parameters/source_spec.rb +8 -2
  93. data/spec/chewy/search/parameters_spec.rb +12 -3
  94. data/spec/chewy/search/query_proxy_spec.rb +68 -17
  95. data/spec/chewy/search/request_spec.rb +222 -74
  96. data/spec/chewy/search/response_spec.rb +12 -12
  97. data/spec/chewy/search/scrolling_spec.rb +7 -9
  98. data/spec/chewy/search_spec.rb +32 -35
  99. data/spec/chewy/stash_spec.rb +9 -21
  100. data/spec/chewy/strategy/active_job_spec.rb +8 -8
  101. data/spec/chewy/strategy/atomic_spec.rb +9 -10
  102. data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
  103. data/spec/chewy/strategy_spec.rb +19 -15
  104. data/spec/chewy_spec.rb +14 -100
  105. data/spec/spec_helper.rb +2 -21
  106. data/spec/support/active_record.rb +15 -5
  107. metadata +44 -103
  108. data/.circleci/config.yml +0 -214
  109. data/Appraisals +0 -81
  110. data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
  111. data/gemfiles/sequel.4.45.gemfile +0 -11
  112. data/lib/chewy/search/pagination/will_paginate.rb +0 -43
  113. data/lib/chewy/strategy/resque.rb +0 -27
  114. data/lib/chewy/strategy/shoryuken.rb +0 -40
  115. data/lib/chewy/type.rb +0 -120
  116. data/lib/chewy/type/actions.rb +0 -43
  117. data/lib/chewy/type/adapter/mongoid.rb +0 -67
  118. data/lib/chewy/type/adapter/sequel.rb +0 -93
  119. data/lib/sequel/plugins/chewy_observe.rb +0 -63
  120. data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
  121. data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
  122. data/spec/chewy/strategy/resque_spec.rb +0 -46
  123. data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
  124. data/spec/chewy/type/actions_spec.rb +0 -50
  125. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
  126. data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
  127. data/spec/chewy/type/observe_spec.rb +0 -137
  128. data/spec/chewy/type/wrapper_spec.rb +0 -100
  129. data/spec/chewy/type_spec.rb +0 -55
  130. data/spec/support/mongoid.rb +0 -93
  131. data/spec/support/sequel.rb +0 -80
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chewy::Type::Adapter::ActiveRecord, :active_record do
3
+ describe Chewy::Index::Adapter::ActiveRecord, :active_record do
4
4
  before do
5
5
  stub_model(:city)
6
6
  stub_model(:country)
@@ -381,11 +381,21 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
381
381
  context 'objects' do
382
382
  specify { expect(subject.import(cities + deleted) { |_data| true }).to eq(true) }
383
383
  specify { expect(subject.import(cities + deleted) { |_data| false }).to eq(false) }
384
- specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false) }
385
- specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false) }
386
- specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false) }
387
- specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(false) }
388
- specify { expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(false) }
384
+ specify do
385
+ expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[0].id])).to eq(false)
386
+ end
387
+ specify do
388
+ expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[1].id])).to eq(false)
389
+ end
390
+ specify do
391
+ expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[cities[2].id])).to eq(false)
392
+ end
393
+ specify do
394
+ expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[0].id])).to eq(false)
395
+ end
396
+ specify do
397
+ expect(subject.import(cities + deleted, batch_size: 1, &data_comparer.curry[deleted[1].id])).to eq(false)
398
+ end
389
399
  end
390
400
 
391
401
  context 'ids' do
@@ -427,7 +437,10 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
427
437
  subject { described_class.new(Country.joins(:cities)) }
428
438
 
429
439
  specify { expect(subject.import_fields(Country.where('rating < 2'))).to match([contain_exactly(1, 2)]) }
430
- specify { expect(subject.import_fields(Country.where('rating < 2'), fields: [:rating])).to match([contain_exactly([1, 0], [2, 1])]) }
440
+ specify do
441
+ expect(subject.import_fields(Country.where('rating < 2'), fields: [:rating]))
442
+ .to match([contain_exactly([1, 0], [2, 1])])
443
+ end
431
444
  end
432
445
  end
433
446
 
@@ -436,21 +449,36 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
436
449
  specify { expect(subject.import_fields(1, 2, fields: [:rating])).to match([contain_exactly([1, 0], [2, 1])]) }
437
450
 
438
451
  specify { expect(subject.import_fields(countries.first(2))).to match([contain_exactly(1, 2)]) }
439
- specify { expect(subject.import_fields(countries.first(2), fields: [:rating])).to match([contain_exactly([1, 0], [2, 1])]) }
452
+ specify do
453
+ expect(subject.import_fields(countries.first(2), fields: [:rating]))
454
+ .to match([contain_exactly([1, 0], [2, 1])])
455
+ end
440
456
  end
441
457
 
442
458
  context 'batch_size' do
443
459
  specify { expect(subject.import_fields(batch_size: 2)).to match([contain_exactly(1, 2), [3]]) }
444
- specify { expect(subject.import_fields(batch_size: 2, fields: [:rating])).to match([contain_exactly([1, 0], [2, 1]), [[3, 2]]]) }
460
+ specify do
461
+ expect(subject.import_fields(batch_size: 2, fields: [:rating]))
462
+ .to match([contain_exactly([1, 0], [2, 1]), [[3, 2]]])
463
+ end
445
464
 
446
- specify { expect(subject.import_fields(Country.where('rating < 2'), batch_size: 2)).to match([contain_exactly(1, 2)]) }
447
- specify { expect(subject.import_fields(Country.where('rating < 2'), batch_size: 2, fields: [:rating])).to match([contain_exactly([1, 0], [2, 1])]) }
465
+ specify do
466
+ expect(subject.import_fields(Country.where('rating < 2'), batch_size: 2))
467
+ .to match([contain_exactly(1, 2)])
468
+ end
469
+ specify do
470
+ expect(subject.import_fields(Country.where('rating < 2'), batch_size: 2, fields: [:rating]))
471
+ .to match([contain_exactly([1, 0], [2, 1])])
472
+ end
448
473
 
449
474
  specify { expect(subject.import_fields(1, 2, batch_size: 1)).to match([[1], [2]]) }
450
475
  specify { expect(subject.import_fields(1, 2, batch_size: 1, fields: [:rating])).to match([[[1, 0]], [[2, 1]]]) }
451
476
 
452
477
  specify { expect(subject.import_fields(countries.first(2), batch_size: 1)).to match([[1], [2]]) }
453
- specify { expect(subject.import_fields(countries.first(2), batch_size: 1, fields: [:rating])).to match([[[1, 0]], [[2, 1]]]) }
478
+ specify do
479
+ expect(subject.import_fields(countries.first(2), batch_size: 1, fields: [:rating]))
480
+ .to match([[[1, 0]], [[2, 1]]])
481
+ end
454
482
  end
455
483
 
456
484
  context 'typecast' do
@@ -481,31 +509,29 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
481
509
  let(:city_ids) { cities.map(&:id) }
482
510
  let(:deleted_ids) { deleted.map(&:id) }
483
511
 
484
- let(:type) { double(type_name: 'user') }
485
-
486
512
  subject { described_class.new(City) }
487
513
 
488
- specify { expect(subject.load(city_ids, _type: type)).to eq(cities) }
489
- specify { expect(subject.load(city_ids.reverse, _type: type)).to eq(cities.reverse) }
490
- specify { expect(subject.load(deleted_ids, _type: type)).to eq([nil, nil]) }
491
- specify { expect(subject.load(city_ids + deleted_ids, _type: type)).to eq([*cities, nil, nil]) }
514
+ specify { expect(subject.load(city_ids, _index: 'users')).to eq(cities) }
515
+ specify { expect(subject.load(city_ids.reverse, _index: 'users')).to eq(cities.reverse) }
516
+ specify { expect(subject.load(deleted_ids, _index: 'users')).to eq([nil, nil]) }
517
+ specify { expect(subject.load(city_ids + deleted_ids, _index: 'users')).to eq([*cities, nil, nil]) }
492
518
  specify do
493
- expect(subject.load(city_ids, _type: type, scope: -> { where(rating: 0) }))
519
+ expect(subject.load(city_ids, _index: 'users', scope: -> { where(rating: 0) }))
494
520
  .to eq(cities.first(2) + [nil])
495
521
  end
496
522
  specify do
497
- expect(subject.load(city_ids,
498
- _type: type, scope: -> { where(rating: 0) }, user: {scope: -> { where(rating: 1) }}))
499
- .to eq([nil, nil] + cities.last(1))
523
+ expect(
524
+ subject.load(city_ids, _index: 'users', scope: -> { where(rating: 0) }, users: {scope: -> { where(rating: 1) }})
525
+ ).to eq([nil, nil] + cities.last(1))
500
526
  end
501
527
  specify do
502
- expect(subject.load(city_ids, _type: type, scope: City.where(rating: 1)))
528
+ expect(subject.load(city_ids, _index: 'users', scope: City.where(rating: 1)))
503
529
  .to eq([nil, nil] + cities.last(1))
504
530
  end
505
531
  specify do
506
- expect(subject.load(city_ids,
507
- _type: type, scope: City.where(rating: 1), user: {scope: -> { where(rating: 0) }}))
508
- .to eq(cities.first(2) + [nil])
532
+ expect(
533
+ subject.load(city_ids, _index: 'users', scope: City.where(rating: 1), users: {scope: -> { where(rating: 0) }})
534
+ ).to eq(cities.first(2) + [nil])
509
535
  end
510
536
  end
511
537
 
@@ -516,31 +542,33 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
516
542
  let(:city_ids) { cities.map(&:rating) }
517
543
  let(:deleted_ids) { deleted.map(&:rating) }
518
544
 
519
- let(:type) { double(type_name: 'user') }
520
-
521
545
  subject { described_class.new(City) }
522
546
 
523
- specify { expect(subject.load(city_ids, _type: type)).to eq(cities) }
524
- specify { expect(subject.load(city_ids.reverse, _type: type)).to eq(cities.reverse) }
525
- specify { expect(subject.load(deleted_ids, _type: type)).to eq([nil, nil]) }
526
- specify { expect(subject.load(city_ids + deleted_ids, _type: type)).to eq([*cities, nil, nil]) }
547
+ specify { expect(subject.load(city_ids, _index: 'users')).to eq(cities) }
548
+ specify { expect(subject.load(city_ids.reverse, _index: 'users')).to eq(cities.reverse) }
549
+ specify { expect(subject.load(deleted_ids, _index: 'users')).to eq([nil, nil]) }
550
+ specify { expect(subject.load(city_ids + deleted_ids, _index: 'users')).to eq([*cities, nil, nil]) }
527
551
  specify do
528
- expect(subject.load(city_ids, _type: type, scope: -> { where(country_id: 0) }))
552
+ expect(subject.load(city_ids, _index: 'users', scope: -> { where(country_id: 0) }))
529
553
  .to eq(cities.first(2) + [nil])
530
554
  end
531
555
  specify do
532
- expect(subject.load(city_ids,
533
- _type: type, scope: -> { where(country_id: 0) }, user: {scope: -> { where(country_id: 1) }}))
534
- .to eq([nil, nil] + cities.last(1))
556
+ expect(
557
+ subject.load(
558
+ city_ids, _index: 'users', scope: -> { where(country_id: 0) }, users: {scope: -> { where(country_id: 1) }}
559
+ )
560
+ ).to eq([nil, nil] + cities.last(1))
535
561
  end
536
562
  specify do
537
- expect(subject.load(city_ids, _type: type, scope: City.where(country_id: 1)))
563
+ expect(subject.load(city_ids, _index: 'users', scope: City.where(country_id: 1)))
538
564
  .to eq([nil, nil] + cities.last(1))
539
565
  end
540
566
  specify do
541
- expect(subject.load(city_ids,
542
- _type: type, scope: City.where(country_id: 1), user: {scope: -> { where(country_id: 0) }}))
543
- .to eq(cities.first(2) + [nil])
567
+ expect(
568
+ subject.load(
569
+ city_ids, _index: 'users', scope: City.where(country_id: 1), users: {scope: -> { where(country_id: 0) }}
570
+ )
571
+ ).to eq(cities.first(2) + [nil])
544
572
  end
545
573
  end
546
574
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chewy::Type::Adapter::Object do
3
+ describe Chewy::Index::Adapter::Object do
4
4
  before { stub_class(:product) }
5
5
  subject { described_class.new(:product) }
6
6
 
@@ -104,7 +104,13 @@ describe Chewy::Type::Adapter::Object do
104
104
  end
105
105
 
106
106
  context 'error handling' do
107
- let(:products) { Array.new(3) { |i| double.tap { |product| allow(product).to receive_messages(rating: i.next) } } }
107
+ let(:products) do
108
+ Array.new(3) do |i|
109
+ double.tap do |product|
110
+ allow(product).to receive_messages(rating: i.next)
111
+ end
112
+ end
113
+ end
108
114
  let(:deleted) { Array.new(2) { |i| double(destroyed?: true, rating: i + 4) } }
109
115
  subject { described_class.new('product') }
110
116
 
@@ -135,13 +141,18 @@ describe Chewy::Type::Adapter::Object do
135
141
  context do
136
142
  subject { described_class.new(-> { objects }) }
137
143
  specify { expect(subject.import_fields(batch_size: 2)).to match([[1, 2], [3]]) }
138
- specify { expect(subject.import_fields(fields: [:name], batch_size: 2)).to match([[[1, 'Name0'], [2, 'Name1']], [[3, 'Name2']]]) }
144
+ specify do
145
+ expect(subject.import_fields(fields: [:name], batch_size: 2))
146
+ .to match([[[1, 'Name0'], [2, 'Name1']], [[3, 'Name2']]])
147
+ end
139
148
  end
140
149
 
141
150
  context do
142
151
  subject { described_class.new(-> { objects }) }
143
152
  specify { expect(subject.import_fields(objects.first(2))).to match([[1, 2]]) }
144
- specify { expect(subject.import_fields(objects.first(2), fields: [:name])).to match([[[1, 'Name0'], [2, 'Name1']]]) }
153
+ specify do
154
+ expect(subject.import_fields(objects.first(2), fields: [:name])).to match([[[1, 'Name0'], [2, 'Name1']]])
155
+ end
145
156
  end
146
157
 
147
158
  context do
@@ -178,7 +189,9 @@ describe Chewy::Type::Adapter::Object do
178
189
  context do
179
190
  subject { described_class.new(Product) }
180
191
  specify { expect(subject.import_fields(objects.first(2))).to match([[1, 2]]) }
181
- specify { expect(subject.import_fields(objects.first(2), fields: [:name])).to match([[[1, 'Name0'], [2, 'Name1']]]) }
192
+ specify do
193
+ expect(subject.import_fields(objects.first(2), fields: [:name])).to match([[[1, 'Name0'], [2, 'Name1']]])
194
+ end
182
195
  end
183
196
 
184
197
  context 'batch_size' do
@@ -196,7 +209,9 @@ describe Chewy::Type::Adapter::Object do
196
209
  specify { expect(subject.import_references).to match([objects]) }
197
210
  specify { expect(subject.import_references(batch_size: 2)).to match([objects.first(2), objects.last(1)]) }
198
211
  specify { expect(subject.import_references(objects.first(2))).to match([objects.first(2)]) }
199
- specify { expect(subject.import_references(objects.first(2), batch_size: 1)).to match([objects.first(1), [objects[1]]]) }
212
+ specify do
213
+ expect(subject.import_references(objects.first(2), batch_size: 1)).to match([objects.first(1), [objects[1]]])
214
+ end
200
215
  end
201
216
 
202
217
  describe '#load' do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chewy::Type::Import::BulkBuilder do
3
+ describe Chewy::Index::Import::BulkBuilder do
4
4
  before { Chewy.massacre }
5
5
 
6
- subject { described_class.new(type, index: index, delete: delete, fields: fields) }
7
- let(:type) { CitiesIndex::City }
8
- let(:index) { [] }
6
+ subject { described_class.new(index, to_index: to_index, delete: delete, fields: fields) }
7
+ let(:index) { CitiesIndex }
8
+ let(:to_index) { [] }
9
9
  let(:delete) { [] }
10
10
  let(:fields) { [] }
11
11
 
@@ -14,9 +14,8 @@ describe Chewy::Type::Import::BulkBuilder do
14
14
  before do
15
15
  stub_model(:city)
16
16
  stub_index(:cities) do
17
- define_type City do
18
- field :name, :rating
19
- end
17
+ index_scope City
18
+ field :name, :rating
20
19
  end
21
20
  end
22
21
  let(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "City#{i + 17}", rating: 42) } }
@@ -24,7 +23,7 @@ describe Chewy::Type::Import::BulkBuilder do
24
23
  specify { expect(subject.bulk_body).to eq([]) }
25
24
 
26
25
  context do
27
- let(:index) { cities }
26
+ let(:to_index) { cities }
28
27
  specify do
29
28
  expect(subject.bulk_body).to eq([
30
29
  {index: {_id: 1, data: {'name' => 'City17', 'rating' => 42}}},
@@ -44,7 +43,7 @@ describe Chewy::Type::Import::BulkBuilder do
44
43
  end
45
44
 
46
45
  context do
47
- let(:index) { cities.first(2) }
46
+ let(:to_index) { cities.first(2) }
48
47
  let(:delete) { [cities.last] }
49
48
  specify do
50
49
  expect(subject.bulk_body).to eq([
@@ -74,10 +73,9 @@ describe Chewy::Type::Import::BulkBuilder do
74
73
 
75
74
  before do
76
75
  stub_index(:cities) do
77
- define_type City do
78
- root id: -> { name } do
79
- field :rating
80
- end
76
+ index_scope City
77
+ root id: -> { name } do
78
+ field :rating
81
79
  end
82
80
  end
83
81
  end
@@ -90,7 +88,7 @@ describe Chewy::Type::Import::BulkBuilder do
90
88
  end
91
89
 
92
90
  context 'indexing' do
93
- let(:index) { [london] }
91
+ let(:to_index) { [london] }
94
92
 
95
93
  specify do
96
94
  expect(subject.bulk_body).to eq([
@@ -113,17 +111,15 @@ describe Chewy::Type::Import::BulkBuilder do
113
111
  context 'crutches' do
114
112
  before do
115
113
  stub_index(:cities) do
116
- define_type :city do
117
- crutch :names do |collection|
118
- collection.map { |item| [item.id, "Name#{item.id}"] }.to_h
119
- end
120
-
121
- field :name, value: ->(o, c) { c.names[o.id] }
114
+ crutch :names do |collection|
115
+ collection.map { |item| [item.id, "Name#{item.id}"] }.to_h
122
116
  end
117
+
118
+ field :name, value: ->(o, c) { c.names[o.id] }
123
119
  end
124
120
  end
125
121
 
126
- let(:index) { [double(id: 42)] }
122
+ let(:to_index) { [double(id: 42)] }
127
123
 
128
124
  specify do
129
125
  expect(subject.bulk_body).to eq([
@@ -132,7 +128,7 @@ describe Chewy::Type::Import::BulkBuilder do
132
128
  end
133
129
 
134
130
  context 'witchcraft' do
135
- before { CitiesIndex::City.witchcraft! }
131
+ before { CitiesIndex.witchcraft! }
136
132
  specify do
137
133
  expect(subject.bulk_body).to eq([
138
134
  {index: {_id: 42, data: {'name' => 'Name42'}}}
@@ -144,13 +140,11 @@ describe Chewy::Type::Import::BulkBuilder do
144
140
  context 'empty ids' do
145
141
  before do
146
142
  stub_index(:cities) do
147
- define_type :city do
148
- field :name
149
- end
143
+ field :name
150
144
  end
151
145
  end
152
146
 
153
- let(:index) { [{id: 1, name: 'Name0'}, double(id: '', name: 'Name1'), double(name: 'Name2')] }
147
+ let(:to_index) { [{id: 1, name: 'Name0'}, double(id: '', name: 'Name1'), double(name: 'Name2')] }
154
148
  let(:delete) { [double(id: '', name: 'Name3'), {name: 'Name4'}, '', 2] }
155
149
 
156
150
  specify do
@@ -180,15 +174,13 @@ describe Chewy::Type::Import::BulkBuilder do
180
174
  describe '#index_objects_by_id' do
181
175
  before do
182
176
  stub_index(:cities) do
183
- define_type :city do
184
- field :name
185
- end
177
+ field :name
186
178
  end
187
179
  end
188
180
 
189
- let(:index) { [double(id: 1), double(id: 2), double(id: ''), double] }
181
+ let(:to_index) { [double(id: 1), double(id: 2), double(id: ''), double] }
190
182
  let(:delete) { [double(id: 3)] }
191
183
 
192
- specify { expect(subject.index_objects_by_id).to eq('1' => index.first, '2' => index.second) }
184
+ specify { expect(subject.index_objects_by_id).to eq('1' => to_index.first, '2' => to_index.second) }
193
185
  end
194
186
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chewy::Type::Import::BulkRequest do
3
+ describe Chewy::Index::Import::BulkRequest do
4
4
  before { Chewy.massacre }
5
5
 
6
- subject { described_class.new(type, suffix: suffix, bulk_size: bulk_size, **bulk_options) }
6
+ subject { described_class.new(index, suffix: suffix, bulk_size: bulk_size, **bulk_options) }
7
7
  let(:suffix) {}
8
8
  let(:bulk_size) {}
9
9
  let(:bulk_options) { {} }
10
- let(:type) { PlacesIndex::City }
10
+ let(:index) { PlacesIndex }
11
11
 
12
12
  describe '#initialize' do
13
13
  specify { expect { described_class.new(nil, bulk_size: 100) }.to raise_error(ArgumentError) }
@@ -18,9 +18,8 @@ describe Chewy::Type::Import::BulkRequest do
18
18
  before do
19
19
  stub_model(:city)
20
20
  stub_index(:places) do
21
- define_type City do
22
- field :name
23
- end
21
+ index_scope City
22
+ field :name
24
23
  end
25
24
  end
26
25
 
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Chewy::Type::Import::JournalBuilder, :orm do
3
+ describe Chewy::Index::Import::JournalBuilder, :orm do
4
4
  before do
5
5
  stub_model(:country)
6
- stub_index 'namespace/cities' do
7
- define_type :city
8
- end
6
+ stub_index 'namespace/cities'
9
7
  stub_index 'namespace/countries' do
10
- define_type Country
8
+ index_scope Country
11
9
  end
12
10
  Timecop.freeze(time)
13
11
  end
@@ -15,23 +13,22 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
15
13
 
16
14
  let(:time) { Time.parse('2017-07-14 12:00Z') }
17
15
 
18
- let(:type) { Namespace::CitiesIndex::City }
19
- let(:index) { [] }
16
+ let(:index) { Namespace::CitiesIndex }
17
+ let(:to_index) { [] }
20
18
  let(:delete) { [] }
21
- subject { described_class.new(type, index: index, delete: delete) }
19
+ subject { described_class.new(index, to_index: to_index, delete: delete) }
22
20
 
23
21
  describe '#bulk_body' do
24
22
  specify { expect(subject.bulk_body).to eq([]) }
25
23
 
26
24
  context do
27
- let(:index) { [{id: 1, name: 'City'}] }
25
+ let(:to_index) { [{id: 1, name: 'City'}] }
28
26
  specify do
29
27
  expect(subject.bulk_body).to eq([{
30
28
  index: {
31
29
  _index: 'chewy_journal',
32
30
  data: {
33
31
  'index_name' => 'namespace/cities',
34
- 'type_name' => 'city',
35
32
  'action' => 'index',
36
33
  'references' => [Base64.encode64('{"id":1,"name":"City"}')],
37
34
  'created_at' => time.as_json
@@ -49,7 +46,6 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
49
46
  _index: 'chewy_journal',
50
47
  data: {
51
48
  'index_name' => 'namespace/cities',
52
- 'type_name' => 'city',
53
49
  'action' => 'delete',
54
50
  'references' => [Base64.encode64('{"id":1,"name":"City"}')],
55
51
  'created_at' => time.as_json
@@ -60,8 +56,8 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
60
56
  end
61
57
 
62
58
  context do
63
- let(:type) { Namespace::CountriesIndex::Country }
64
- let(:index) { [Country.new(id: 1, name: 'City')] }
59
+ let(:index) { Namespace::CountriesIndex }
60
+ let(:to_index) { [Country.new(id: 1, name: 'City')] }
65
61
  let(:delete) { [Country.new(id: 2, name: 'City')] }
66
62
  specify do
67
63
  expect(subject.bulk_body).to eq([{
@@ -69,7 +65,6 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
69
65
  _index: 'chewy_journal',
70
66
  data: {
71
67
  'index_name' => 'namespace/countries',
72
- 'type_name' => 'country',
73
68
  'action' => 'index',
74
69
  'references' => [Base64.encode64('1')],
75
70
  'created_at' => time.as_json
@@ -80,7 +75,6 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
80
75
  _index: 'chewy_journal',
81
76
  data: {
82
77
  'index_name' => 'namespace/countries',
83
- 'type_name' => 'country',
84
78
  'action' => 'delete',
85
79
  'references' => [Base64.encode64('2')],
86
80
  'created_at' => time.as_json