chewy 7.1.0 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -8,16 +8,14 @@ describe Chewy::Search::Response, :orm do
8
8
  stub_model(:country)
9
9
 
10
10
  stub_index(:cities) do
11
- define_type City do
12
- field :name
13
- field :rating, type: 'integer'
14
- end
11
+ index_scope City
12
+ field :name
13
+ field :rating, type: 'integer'
15
14
  end
16
15
  stub_index(:countries) do
17
- define_type Country do
18
- field :name
19
- field :rating, type: 'integer'
20
- end
16
+ index_scope Country
17
+ field :name
18
+ field :rating, type: 'integer'
21
19
  end
22
20
  end
23
21
 
@@ -127,7 +125,9 @@ describe Chewy::Search::Response, :orm do
127
125
  specify { expect(subject.aggs).to eq({}) }
128
126
 
129
127
  context do
130
- let(:request) { Chewy::Search::Request.new(CitiesIndex, CountriesIndex).aggs(avg_rating: {avg: {field: :rating}}) }
128
+ let(:request) do
129
+ Chewy::Search::Request.new(CitiesIndex, CountriesIndex).aggs(avg_rating: {avg: {field: :rating}})
130
+ end
131
131
  specify { expect(subject.aggs).to eq('avg_rating' => {'value' => 1.5}) }
132
132
  end
133
133
  end
@@ -137,7 +137,7 @@ describe Chewy::Search::Response, :orm do
137
137
  specify { expect(subject.wrappers).to have(4).items }
138
138
  specify do
139
139
  expect(subject.wrappers.map(&:class).uniq)
140
- .to contain_exactly(CitiesIndex::City, CountriesIndex::Country)
140
+ .to contain_exactly(CitiesIndex, CountriesIndex)
141
141
  end
142
142
  specify { expect(subject.wrappers.map(&:_data)).to eq(subject.hits) }
143
143
 
@@ -166,7 +166,7 @@ describe Chewy::Search::Response, :orm do
166
166
  '_source' => {'id' => 2, 'rating' => 0}}
167
167
  ]}}
168
168
  end
169
- specify { expect(subject.wrappers.first).to be_a(CitiesIndex::City) }
169
+ specify { expect(subject.wrappers.first).to be_a(CitiesIndex) }
170
170
  specify { expect(subject.wrappers.first.id).to eq(2) }
171
171
  specify { expect(subject.wrappers.first.rating).to eq(0) }
172
172
  specify { expect(subject.wrappers.first._score).to eq(1.3) }
@@ -183,7 +183,7 @@ describe Chewy::Search::Response, :orm do
183
183
  '_explanation' => {foo: 'bar'}}
184
184
  ]}}
185
185
  end
186
- specify { expect(subject.wrappers.first).to be_a(CountriesIndex::Country) }
186
+ specify { expect(subject.wrappers.first).to be_a(CountriesIndex) }
187
187
  specify { expect(subject.wrappers.first.id).to eq('2') }
188
188
  specify { expect(subject.wrappers.first.rating).to be_nil }
189
189
  specify { expect(subject.wrappers.first._score).to eq(1.2) }
@@ -8,16 +8,14 @@ describe Chewy::Search::Scrolling, :orm do
8
8
  stub_model(:country)
9
9
 
10
10
  stub_index(:cities) do
11
- define_type City do
12
- field :name
13
- field :rating, type: 'integer'
14
- end
11
+ index_scope City
12
+ field :name
13
+ field :rating, type: 'integer'
15
14
  end
16
15
  stub_index(:countries) do
17
- define_type Country do
18
- field :name
19
- field :rating, type: 'integer'
20
- end
16
+ index_scope Country
17
+ field :name
18
+ field :rating, type: 'integer'
21
19
  end
22
20
  end
23
21
 
@@ -153,7 +151,7 @@ describe Chewy::Search::Scrolling, :orm do
153
151
  end
154
152
  specify do
155
153
  expect(request.scroll_wrappers(batch_size: 2).map(&:class).uniq)
156
- .to eq([CitiesIndex::City, CountriesIndex::Country])
154
+ .to eq([CitiesIndex, CountriesIndex])
157
155
  end
158
156
  end
159
157
 
@@ -4,47 +4,34 @@ describe Chewy::Search do
4
4
  before { Chewy.massacre }
5
5
 
6
6
  before do
7
- stub_index(:products) do
8
- define_type :product
9
- end
7
+ stub_index(:products)
10
8
  end
11
9
 
12
- let(:product) { ProductsIndex::Product }
13
-
14
10
  describe '.all' do
15
11
  specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
16
- specify { expect(product.all).to be_a(Chewy::Search::Request) }
17
12
 
18
13
  context do
19
14
  before { allow(Chewy).to receive_messages(search_class: Chewy::Search::Request) }
20
15
 
21
16
  specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
22
- specify { expect(product.all).to be_a(Chewy::Search::Request) }
23
17
  end
24
18
  end
25
19
 
26
20
  describe '.search_string' do
27
21
  specify do
28
- expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).twice
22
+ expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).once
29
23
  ProductsIndex.search_string('hello')
30
- product.search_string('hello')
31
24
  end
32
25
 
33
26
  specify do
34
- expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).twice
27
+ expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).once
35
28
  ProductsIndex.search_string('hello', explain: true)
36
- product.search_string('hello', explain: true)
37
29
  end
38
30
 
39
31
  specify do
40
- expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products']))
32
+ expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'])).once
41
33
  ProductsIndex.search_string('hello')
42
34
  end
43
-
44
- specify do
45
- expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products']))
46
- product.search_string('hello')
47
- end
48
35
  end
49
36
 
50
37
  context 'named scopes' do
@@ -61,10 +48,9 @@ describe Chewy::Search do
61
48
  filter { match name: "Name#{index}" }
62
49
  end
63
50
 
64
- define_type City do
65
- field :name, type: 'keyword'
66
- field :rating, type: :integer
67
- end
51
+ index_scope City
52
+ field :name, type: 'keyword'
53
+ field :rating, type: :integer
68
54
  end
69
55
 
70
56
  stub_index(:countries) do
@@ -76,10 +62,9 @@ describe Chewy::Search do
76
62
  filter { match name: "Name#{index}" }
77
63
  end
78
64
 
79
- define_type Country do
80
- field :name, type: 'keyword'
81
- field :rating, type: :integer
82
- end
65
+ index_scope Country
66
+ field :name, type: 'keyword'
67
+ field :rating, type: :integer
83
68
  end
84
69
  end
85
70
 
@@ -92,30 +77,42 @@ describe Chewy::Search do
92
77
  end
93
78
 
94
79
  specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:rating)).to eq([1, 1]) }
95
- specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:class)).to match_array([CitiesIndex::City, CountriesIndex::Country]) }
80
+ specify do
81
+ expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:class))
82
+ .to match_array([CitiesIndex, CountriesIndex])
83
+ end
96
84
  specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:rating)).to eq([1]) }
97
- specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:class)).to eq([CitiesIndex::City]) }
85
+ specify do
86
+ expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:class))
87
+ .to eq([CitiesIndex])
88
+ end
98
89
  specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:rating)).to eq([2, 1]) }
99
- specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:class)).to eq([CitiesIndex::City, CountriesIndex::Country]) }
90
+ specify do
91
+ expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:class))
92
+ .to eq([CitiesIndex, CountriesIndex])
93
+ end
100
94
  specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:rating)).to eq([1, 1]) }
101
- specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:class)).to match_array([CitiesIndex::City, CountriesIndex::Country]) }
95
+ specify do
96
+ expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:class))
97
+ .to match_array([CitiesIndex, CountriesIndex])
98
+ end
102
99
 
103
100
  specify { expect(CitiesIndex.by_rating(2).map(&:rating)).to eq([2]) }
104
- specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex::City]) }
101
+ specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex]) }
105
102
  specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:rating)).to eq([2]) }
106
- specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex::City]) }
103
+ specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex]) }
107
104
  specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
108
105
  specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
109
106
  specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
110
107
  specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
111
108
  specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:rating)).to eq([2]) }
112
- specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex::City]) }
109
+ specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex]) }
113
110
 
114
111
  specify { expect(CountriesIndex.by_rating(3).map(&:rating)).to eq([3]) }
115
- specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex::Country]) }
112
+ specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex]) }
116
113
  specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:rating)).to eq([3]) }
117
- specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex::Country]) }
114
+ specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex]) }
118
115
  specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:rating)).to eq([3]) }
119
- specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex::Country]) }
116
+ specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex]) }
120
117
  end
121
118
  end
@@ -10,12 +10,10 @@ describe Chewy::Stash::Journal, :orm do
10
10
  before do
11
11
  stub_model(:city)
12
12
  stub_index(:cities) do
13
- define_type City
13
+ index_scope City
14
14
  end
15
- stub_index(:countries) do
16
- define_type :country
17
- end
18
- stub_index(:users) { define_type :user }
15
+ stub_index(:countries)
16
+ stub_index(:users)
19
17
  stub_index(:borogoves)
20
18
  end
21
19
 
@@ -28,7 +26,7 @@ describe Chewy::Stash::Journal, :orm do
28
26
  CountriesIndex.import!([id: 2, name: 'Country'], journal: true)
29
27
  end
30
28
  Timecop.travel(Time.now + 2.minutes) do
31
- UsersIndex::User.import!([id: 3, name: 'User'], journal: true)
29
+ UsersIndex.import!([id: 3, name: 'User'], journal: true)
32
30
  end
33
31
  end
34
32
 
@@ -72,26 +70,16 @@ describe Chewy::Stash::Journal, :orm do
72
70
  specify { expect(fetch_deleted_number(described_class.clean(only: UsersIndex))).to eq(1) }
73
71
  specify { expect(fetch_deleted_number(described_class.clean(only: [CitiesIndex, UsersIndex]))).to eq(2) }
74
72
 
75
- specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CountriesIndex))).to eq(0) }
73
+ specify do
74
+ expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CountriesIndex))).to eq(0)
75
+ end
76
76
  specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CitiesIndex))).to eq(1) }
77
77
  end
78
78
 
79
79
  describe '.for' do
80
80
  specify { expect(described_class.for(UsersIndex).map(&:index_name)).to eq(['users']) }
81
- specify { expect(described_class.for(CitiesIndex, CountriesIndex).map(&:type_name)).to contain_exactly('city', 'country') }
82
- specify { expect(described_class.for(CitiesIndex, UsersIndex).map(&:index_name)).to contain_exactly('cities', 'users') }
83
- end
84
-
85
- describe '#type' do
86
- let(:index_name) { 'users' }
87
- let(:type_name) { 'city' }
88
- subject { described_class::Journal.new('index_name' => index_name, 'type_name' => type_name).type }
89
-
90
- specify { expect { subject }.to raise_error(Chewy::UnderivableType) }
91
-
92
- context do
93
- let(:index_name) { 'cities' }
94
- it { is_expected.to eq(CitiesIndex::City) }
81
+ specify do
82
+ expect(described_class.for(CitiesIndex, UsersIndex).map(&:index_name)).to contain_exactly('cities', 'users')
95
83
  end
96
84
  end
97
85
  end
@@ -19,11 +19,11 @@ if defined?(::ActiveJob)
19
19
 
20
20
  before do
21
21
  stub_model(:city) do
22
- update_index('cities#city') { self }
22
+ update_index('cities') { self }
23
23
  end
24
24
 
25
25
  stub_index(:cities) do
26
- define_type City
26
+ index_scope City
27
27
  end
28
28
  end
29
29
 
@@ -32,7 +32,7 @@ if defined?(::ActiveJob)
32
32
 
33
33
  specify do
34
34
  expect { [city, other_city].map(&:save!) }
35
- .not_to update_index(CitiesIndex::City, strategy: :active_job)
35
+ .not_to update_index(CitiesIndex, strategy: :active_job)
36
36
  end
37
37
 
38
38
  specify do
@@ -55,19 +55,19 @@ if defined?(::ActiveJob)
55
55
  specify do
56
56
  ::ActiveJob::Base.queue_adapter = :inline
57
57
  expect { [city, other_city].map(&:save!) }
58
- .to update_index(CitiesIndex::City, strategy: :active_job)
58
+ .to update_index(CitiesIndex, strategy: :active_job)
59
59
  .and_reindex(city, other_city).only
60
60
  end
61
61
 
62
62
  specify do
63
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
64
- Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
63
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
64
+ Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
65
65
  end
66
66
 
67
67
  specify do
68
68
  allow(Chewy).to receive(:disable_refresh_async).and_return(true)
69
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
70
- Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
69
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
70
+ Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
71
71
  end
72
72
  end
73
73
  end
@@ -5,11 +5,11 @@ describe Chewy::Strategy::Atomic, :orm do
5
5
 
6
6
  before do
7
7
  stub_model(:country) do
8
- update_index('countries#country') { self }
8
+ update_index('countries') { self }
9
9
  end
10
10
 
11
11
  stub_index(:countries) do
12
- define_type Country
12
+ index_scope Country
13
13
  end
14
14
  end
15
15
 
@@ -18,35 +18,34 @@ describe Chewy::Strategy::Atomic, :orm do
18
18
 
19
19
  specify do
20
20
  expect { [country, other_country].map(&:save!) }
21
- .to update_index(CountriesIndex::Country, strategy: :atomic)
21
+ .to update_index(CountriesIndex, strategy: :atomic)
22
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
- .to update_index(CountriesIndex::Country, strategy: :atomic)
27
+ .to update_index(CountriesIndex, strategy: :atomic)
28
28
  .and_delete(country, other_country).only
29
29
  end
30
30
 
31
31
  context do
32
32
  before do
33
33
  stub_index(:countries) do
34
- define_type Country do
35
- root id: -> { country_code } do
36
- end
34
+ index_scope Country
35
+ root id: -> { country_code } do
37
36
  end
38
37
  end
39
38
  end
40
39
 
41
40
  specify do
42
41
  expect { [country, other_country].map(&:save!) }
43
- .to update_index(CountriesIndex::Country, strategy: :atomic)
42
+ .to update_index(CountriesIndex, strategy: :atomic)
44
43
  .and_reindex('HL', 'WD').only
45
44
  end
46
45
 
47
46
  specify do
48
47
  expect { [country, other_country].map(&:destroy) }
49
- .to update_index(CountriesIndex::Country, strategy: :atomic)
48
+ .to update_index(CountriesIndex, strategy: :atomic)
50
49
  .and_delete('HL', 'WD').only
51
50
  end
52
51
 
@@ -55,7 +54,7 @@ describe Chewy::Strategy::Atomic, :orm do
55
54
  country.save!
56
55
  other_country.destroy
57
56
  end
58
- .to update_index(CountriesIndex::Country, strategy: :atomic)
57
+ .to update_index(CountriesIndex, strategy: :atomic)
59
58
  .and_reindex('HL').and_delete('WD').only
60
59
  end
61
60
  end
@@ -13,11 +13,11 @@ if defined?(::Sidekiq)
13
13
  before { ::Sidekiq::Worker.clear_all }
14
14
  before do
15
15
  stub_model(:city) do
16
- update_index('cities#city') { self }
16
+ update_index('cities') { self }
17
17
  end
18
18
 
19
19
  stub_index(:cities) do
20
- define_type City
20
+ index_scope City
21
21
  end
22
22
  end
23
23
 
@@ -26,27 +26,27 @@ if defined?(::Sidekiq)
26
26
 
27
27
  specify do
28
28
  expect { [city, other_city].map(&:save!) }
29
- .not_to update_index(CitiesIndex::City, strategy: :sidekiq)
29
+ .not_to update_index(CitiesIndex, strategy: :sidekiq)
30
30
  end
31
31
 
32
32
  specify do
33
33
  expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
34
34
  ::Sidekiq::Testing.inline! do
35
35
  expect { [city, other_city].map(&:save!) }
36
- .to update_index(CitiesIndex::City, strategy: :sidekiq)
36
+ .to update_index(CitiesIndex, strategy: :sidekiq)
37
37
  .and_reindex(city, other_city).only
38
38
  end
39
39
  end
40
40
 
41
41
  specify do
42
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
43
- Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
42
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
43
+ Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
44
44
  end
45
45
 
46
46
  specify do
47
47
  allow(Chewy).to receive(:disable_refresh_async).and_return(true)
48
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
49
- Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex::City', [city.id, other_city.id], suffix: '201601')
48
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
49
+ Chewy::Strategy::Sidekiq::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
50
50
  end
51
51
  end
52
52
  end
@@ -14,7 +14,10 @@ describe Chewy::Strategy do
14
14
  end
15
15
 
16
16
  describe '#push' do
17
- specify { expect { strategy.push(:unexistant) }.to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`") }
17
+ specify do
18
+ expect { strategy.push(:unexistant) }
19
+ .to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`")
20
+ end
18
21
 
19
22
  specify do
20
23
  expect { strategy.push(:atomic) }
@@ -35,7 +38,10 @@ describe Chewy::Strategy do
35
38
  end
36
39
 
37
40
  describe '#wrap' do
38
- specify { expect { strategy.wrap(:unexistant) {} }.to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`") }
41
+ specify do
42
+ expect { strategy.wrap(:unexistant) {} }
43
+ .to raise_error(RuntimeError).with_message("Can't find update strategy `unexistant`")
44
+ end
39
45
 
40
46
  specify do
41
47
  expect do
@@ -49,11 +55,11 @@ describe Chewy::Strategy do
49
55
  context 'nesting', :orm do
50
56
  before do
51
57
  stub_model(:city) do
52
- update_index('cities#city') { self }
58
+ update_index('cities') { self }
53
59
  end
54
60
 
55
61
  stub_index(:cities) do
56
- define_type City
62
+ index_scope City
57
63
  end
58
64
  end
59
65
 
@@ -64,12 +70,12 @@ describe Chewy::Strategy do
64
70
  around { |example| Chewy.strategy(:bypass) { example.run } }
65
71
 
66
72
  specify do
67
- expect(CitiesIndex::City).not_to receive(:import!)
73
+ expect(CitiesIndex).not_to receive(:import!)
68
74
  [city, other_city].map(&:save!)
69
75
  end
70
76
 
71
77
  specify do
72
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id]).once
78
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id]).once
73
79
  Chewy.strategy(:atomic) { [city, other_city].map(&:save!) }
74
80
  end
75
81
  end
@@ -78,41 +84,39 @@ describe Chewy::Strategy do
78
84
  around { |example| Chewy.strategy(:urgent) { example.run } }
79
85
 
80
86
  specify do
81
- expect(CitiesIndex::City).to receive(:import!).at_least(2).times
87
+ expect(CitiesIndex).to receive(:import!).at_least(2).times
82
88
  [city, other_city].map(&:save!)
83
89
  end
84
90
 
85
91
  specify do
86
- expect(CitiesIndex::City).to receive(:import!).with([city.id, other_city.id]).once
92
+ expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id]).once
87
93
  Chewy.strategy(:atomic) { [city, other_city].map(&:save!) }
88
94
  end
89
95
 
90
96
  context 'hash passed to urgent' do
91
97
  before do
92
- stub_index(:cities) do
93
- define_type :city
94
- end
98
+ stub_index(:cities)
95
99
 
96
100
  stub_model(:city) do
97
- update_index('cities#city') { {name: name} }
101
+ update_index('cities') { {name: name} }
98
102
  end
99
103
  end
100
104
 
101
105
  specify do
102
106
  [city, other_city].map(&:save!)
103
- expect(CitiesIndex::City.total_count).to eq(4)
107
+ expect(CitiesIndex.total_count).to eq(4)
104
108
  end
105
109
 
106
110
  context do
107
111
  before do
108
112
  stub_model(:city) do
109
- update_index('cities#city') { {id: id.to_s, name: name} }
113
+ update_index('cities') { {id: id.to_s, name: name} }
110
114
  end
111
115
  end
112
116
 
113
117
  specify do
114
118
  [city, other_city].map(&:save!)
115
- expect(CitiesIndex::City.total_count).to eq(2)
119
+ expect(CitiesIndex.total_count).to eq(2)
116
120
  end
117
121
  end
118
122
  end