chewy 7.1.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +58 -0
- data/.rubocop.yml +13 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +53 -0
- data/Gemfile +0 -7
- data/Guardfile +3 -1
- data/README.md +282 -245
- data/chewy.gemspec +3 -5
- data/gemfiles/rails.5.2.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.0.activerecord.gemfile +8 -14
- data/gemfiles/rails.6.1.activerecord.gemfile +8 -14
- data/lib/chewy.rb +21 -75
- data/lib/chewy/config.rb +40 -40
- data/lib/chewy/errors.rb +0 -12
- data/lib/chewy/fields/base.rb +11 -1
- data/lib/chewy/fields/root.rb +3 -4
- data/lib/chewy/index.rb +46 -87
- data/lib/chewy/index/actions.rb +51 -32
- data/lib/chewy/{type → index}/adapter/active_record.rb +12 -3
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +11 -14
- data/lib/chewy/{type → index}/crutch.rb +5 -5
- data/lib/chewy/{type → index}/import.rb +36 -27
- data/lib/chewy/{type → index}/import/bulk_builder.rb +15 -13
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -6
- data/lib/chewy/{type → index}/import/journal_builder.rb +10 -10
- data/lib/chewy/{type → index}/import/routine.rb +15 -14
- data/lib/chewy/{type → index}/mapping.rb +26 -31
- data/lib/chewy/{type → index}/observe.rb +9 -19
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +60 -57
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/journal.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +9 -13
- data/lib/chewy/minitest/search_index_receiver.rb +22 -26
- data/lib/chewy/railtie.rb +4 -2
- data/lib/chewy/rake_helper.rb +82 -107
- data/lib/chewy/rspec/update_index.rb +47 -43
- data/lib/chewy/search.rb +4 -17
- data/lib/chewy/search/loader.rb +18 -30
- data/lib/chewy/search/parameters.rb +4 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +82 -86
- data/lib/chewy/search/response.rb +4 -4
- data/lib/chewy/search/scoping.rb +6 -7
- data/lib/chewy/search/scrolling.rb +11 -11
- data/lib/chewy/stash.rb +14 -22
- data/lib/chewy/strategy.rb +3 -19
- data/lib/chewy/strategy/sidekiq.rb +1 -0
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +10 -22
- data/migration_guide.md +14 -0
- data/spec/chewy/config_spec.rb +14 -39
- data/spec/chewy/fields/base_spec.rb +412 -148
- data/spec/chewy/fields/root_spec.rb +16 -24
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +270 -24
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +68 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/{type → index}/import/bulk_builder_spec.rb +23 -31
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -6
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -15
- data/spec/chewy/{type → index}/import/routine_spec.rb +16 -16
- data/spec/chewy/{type → index}/import_spec.rb +102 -98
- data/spec/chewy/{type → index}/mapping_spec.rb +46 -54
- data/spec/chewy/index/observe_spec.rb +116 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +7 -17
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +59 -102
- data/spec/chewy/journal_spec.rb +9 -22
- data/spec/chewy/minitest/helpers_spec.rb +13 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +22 -26
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +145 -55
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/search/loader_spec.rb +19 -37
- data/spec/chewy/search/pagination/kaminari_examples.rb +3 -5
- data/spec/chewy/search/pagination/kaminari_spec.rb +1 -1
- data/spec/chewy/search/parameters/indices_spec.rb +2 -8
- data/spec/chewy/search/parameters/order_spec.rb +1 -1
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters_spec.rb +12 -3
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +222 -74
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +7 -9
- data/spec/chewy/search_spec.rb +32 -35
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +8 -8
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/sidekiq_spec.rb +8 -8
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +14 -100
- data/spec/spec_helper.rb +2 -21
- data/spec/support/active_record.rb +15 -5
- metadata +44 -103
- data/.circleci/config.yml +0 -214
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type.rb +0 -120
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
# TODO: add more specs here later
|
4
|
-
describe Chewy::
|
4
|
+
describe Chewy::Index::Import::Routine do
|
5
5
|
before { Chewy.massacre }
|
6
6
|
before do
|
7
7
|
stub_index(:cities) do
|
8
|
-
|
9
|
-
|
10
|
-
field :object, type: 'object'
|
11
|
-
end
|
8
|
+
field :name
|
9
|
+
field :object, type: 'object'
|
12
10
|
end
|
13
11
|
CitiesIndex.create!
|
14
12
|
end
|
@@ -18,7 +16,7 @@ describe Chewy::Type::Import::Routine do
|
|
18
16
|
|
19
17
|
describe '#options' do
|
20
18
|
specify do
|
21
|
-
expect(described_class.new(CitiesIndex
|
19
|
+
expect(described_class.new(CitiesIndex).options).to eq(
|
22
20
|
journal: nil,
|
23
21
|
refresh: true,
|
24
22
|
update_failover: true,
|
@@ -29,7 +27,7 @@ describe Chewy::Type::Import::Routine do
|
|
29
27
|
|
30
28
|
specify do
|
31
29
|
expect(described_class.new(
|
32
|
-
CitiesIndex
|
30
|
+
CitiesIndex, batch_size: 100, bulk_size: 1.megabyte, refresh: false
|
33
31
|
).options).to eq(
|
34
32
|
journal: nil,
|
35
33
|
refresh: false,
|
@@ -43,7 +41,7 @@ describe Chewy::Type::Import::Routine do
|
|
43
41
|
context do
|
44
42
|
before { allow(Chewy).to receive_messages(configuration: Chewy.configuration.merge(journal: true)) }
|
45
43
|
specify do
|
46
|
-
expect(described_class.new(CitiesIndex
|
44
|
+
expect(described_class.new(CitiesIndex).options).to eq(
|
47
45
|
journal: true,
|
48
46
|
refresh: true,
|
49
47
|
update_failover: true,
|
@@ -55,24 +53,26 @@ describe Chewy::Type::Import::Routine do
|
|
55
53
|
|
56
54
|
specify do
|
57
55
|
expect(CitiesIndex.client).to receive(:bulk).with(hash_including(refresh: true))
|
58
|
-
described_class.new(CitiesIndex
|
56
|
+
described_class.new(CitiesIndex).process(index: index)
|
59
57
|
end
|
60
58
|
|
61
59
|
specify do
|
62
60
|
expect(CitiesIndex.client).to receive(:bulk).with(hash_including(refresh: false))
|
63
|
-
described_class.new(CitiesIndex
|
61
|
+
described_class.new(CitiesIndex, refresh: false).process(index: index)
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
67
65
|
describe '#parallel_options' do
|
68
|
-
specify { expect(described_class.new(CitiesIndex
|
69
|
-
specify { expect(described_class.new(CitiesIndex
|
70
|
-
specify { expect(described_class.new(CitiesIndex
|
71
|
-
specify
|
66
|
+
specify { expect(described_class.new(CitiesIndex).parallel_options).to be_nil }
|
67
|
+
specify { expect(described_class.new(CitiesIndex, parallel: true).parallel_options).to eq({}) }
|
68
|
+
specify { expect(described_class.new(CitiesIndex, parallel: 3).parallel_options).to eq(in_processes: 3) }
|
69
|
+
specify do
|
70
|
+
expect(described_class.new(CitiesIndex, parallel: {in_threads: 2}).parallel_options).to eq(in_threads: 2)
|
71
|
+
end
|
72
72
|
end
|
73
73
|
|
74
74
|
describe '#stats' do
|
75
|
-
subject { described_class.new(CitiesIndex
|
75
|
+
subject { described_class.new(CitiesIndex) }
|
76
76
|
|
77
77
|
specify { expect(subject.stats).to eq({}) }
|
78
78
|
specify do
|
@@ -92,7 +92,7 @@ describe Chewy::Type::Import::Routine do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
describe '#errors' do
|
95
|
-
subject { described_class.new(CitiesIndex
|
95
|
+
subject { described_class.new(CitiesIndex) }
|
96
96
|
let(:index) { [double(id: 1, name: 'Name', object: ''), double(id: 2, name: 'Name', object: {})] }
|
97
97
|
|
98
98
|
specify { expect(subject.errors).to eq([]) }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Chewy::
|
3
|
+
describe Chewy::Index::Import do
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
@@ -9,14 +9,13 @@ describe Chewy::Type::Import do
|
|
9
9
|
|
10
10
|
before do
|
11
11
|
stub_index(:cities) do
|
12
|
-
|
13
|
-
|
14
|
-
end
|
12
|
+
index_scope City
|
13
|
+
field :name
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
def imported_cities
|
19
|
-
CitiesIndex
|
18
|
+
CitiesIndex.all.map do |city|
|
20
19
|
city.attributes.except('_score', '_explanation')
|
21
20
|
end
|
22
21
|
end
|
@@ -37,13 +36,13 @@ describe Chewy::Type::Import do
|
|
37
36
|
specify 'lazy (default)' do
|
38
37
|
expect(CitiesIndex).to receive(:exists?).and_call_original
|
39
38
|
expect(CitiesIndex).to receive(:create!).and_call_original
|
40
|
-
CitiesIndex
|
39
|
+
CitiesIndex.import(dummy_city)
|
41
40
|
end
|
42
41
|
|
43
42
|
specify 'lazy without objects' do
|
44
43
|
expect(CitiesIndex).not_to receive(:exists?)
|
45
44
|
expect(CitiesIndex).not_to receive(:create!)
|
46
|
-
CitiesIndex
|
45
|
+
CitiesIndex.import([])
|
47
46
|
end
|
48
47
|
|
49
48
|
context 'skip' do
|
@@ -58,7 +57,7 @@ describe Chewy::Type::Import do
|
|
58
57
|
specify do
|
59
58
|
expect(CitiesIndex).not_to receive(:exists?)
|
60
59
|
expect(CitiesIndex).not_to receive(:create!)
|
61
|
-
CitiesIndex
|
60
|
+
CitiesIndex.import(dummy_city)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
@@ -69,35 +68,36 @@ describe Chewy::Type::Import do
|
|
69
68
|
specify { expect(import(dummy_cities)).to eq(true) }
|
70
69
|
specify { expect(import(dummy_cities.map(&:id))).to eq(true) }
|
71
70
|
|
72
|
-
specify { expect { import([]) }.not_to update_index(CitiesIndex
|
73
|
-
specify { expect { import }.to update_index(CitiesIndex
|
74
|
-
specify { expect { import dummy_cities }.to update_index(CitiesIndex
|
75
|
-
specify { expect { import dummy_cities.map(&:id) }.to update_index(CitiesIndex
|
71
|
+
specify { expect { import([]) }.not_to update_index(CitiesIndex) }
|
72
|
+
specify { expect { import }.to update_index(CitiesIndex).and_reindex(dummy_cities) }
|
73
|
+
specify { expect { import dummy_cities }.to update_index(CitiesIndex).and_reindex(dummy_cities) }
|
74
|
+
specify { expect { import dummy_cities.map(&:id) }.to update_index(CitiesIndex).and_reindex(dummy_cities) }
|
76
75
|
|
77
76
|
describe 'criteria-driven importing' do
|
78
77
|
let(:names) { %w[name0 name1] }
|
79
78
|
|
80
|
-
context 'mongoid', :mongoid do
|
81
|
-
specify { expect { import(City.where(:name.in => names)) }.to update_index(CitiesIndex::City).and_reindex(dummy_cities.first(2)) }
|
82
|
-
specify { expect { import(City.where(:name.in => names).map(&:id)) }.to update_index(CitiesIndex::City).and_reindex(dummy_cities.first(2)) }
|
83
|
-
end
|
84
|
-
|
85
79
|
context 'active record', :active_record do
|
86
|
-
specify
|
87
|
-
|
80
|
+
specify do
|
81
|
+
expect { import(City.where(name: names)) }
|
82
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities.first(2))
|
83
|
+
end
|
84
|
+
specify do
|
85
|
+
expect { import(City.where(name: names).map(&:id)) }
|
86
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities.first(2))
|
87
|
+
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
specify do
|
92
92
|
dummy_cities.first.destroy
|
93
93
|
expect { import dummy_cities }
|
94
|
-
.to update_index(CitiesIndex
|
94
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities.from(1)).and_delete(dummy_cities.first)
|
95
95
|
end
|
96
96
|
|
97
97
|
specify do
|
98
98
|
dummy_cities.first.destroy
|
99
99
|
expect { import dummy_cities.map(&:id) }
|
100
|
-
.to update_index(CitiesIndex
|
100
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities.from(1)).and_delete(dummy_cities.first)
|
101
101
|
end
|
102
102
|
|
103
103
|
specify do
|
@@ -120,7 +120,10 @@ describe Chewy::Type::Import do
|
|
120
120
|
context ':bulk_size' do
|
121
121
|
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}" * 20) } }
|
122
122
|
|
123
|
-
specify
|
123
|
+
specify do
|
124
|
+
expect { import(dummy_cities, bulk_size: 1.2.kilobyte) }
|
125
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities)
|
126
|
+
end
|
124
127
|
|
125
128
|
context do
|
126
129
|
before { expect(Chewy.client).to receive(:bulk).exactly(3).times.and_call_original }
|
@@ -132,36 +135,25 @@ describe Chewy::Type::Import do
|
|
132
135
|
before do
|
133
136
|
names = %w[name0 name1]
|
134
137
|
|
135
|
-
criteria =
|
136
|
-
when :mongoid
|
137
|
-
{:name.in => names}
|
138
|
-
else
|
139
|
-
{name: names}
|
140
|
-
end
|
138
|
+
criteria = {name: names}
|
141
139
|
|
142
140
|
stub_index(:cities) do
|
143
|
-
|
144
|
-
|
145
|
-
end
|
141
|
+
index_scope City.where(criteria)
|
142
|
+
field :name
|
146
143
|
end
|
147
144
|
end
|
148
145
|
|
149
|
-
specify { expect { import }.to update_index(CitiesIndex
|
150
|
-
|
151
|
-
context 'mongoid', :mongoid do
|
152
|
-
specify do
|
153
|
-
expect { import City.where(_id: dummy_cities.first.id) }.to update_index(CitiesIndex::City).and_reindex(dummy_cities.first).only
|
154
|
-
end
|
155
|
-
end
|
146
|
+
specify { expect { import }.to update_index(CitiesIndex).and_reindex(dummy_cities.first(2)) }
|
156
147
|
|
157
148
|
context 'active record', :active_record do
|
158
149
|
specify do
|
159
|
-
expect { import City.where(id: dummy_cities.first.id) }
|
150
|
+
expect { import City.where(id: dummy_cities.first.id) }
|
151
|
+
.to update_index(CitiesIndex).and_reindex(dummy_cities.first).only
|
160
152
|
end
|
161
153
|
|
162
154
|
specify do
|
163
|
-
allow(CitiesIndex
|
164
|
-
allow(CitiesIndex
|
155
|
+
allow(CitiesIndex).to receive(:import_linear).and_return(double(present?: false))
|
156
|
+
allow(CitiesIndex).to receive(:import_parallel).and_return(double(present?: false))
|
165
157
|
|
166
158
|
expects_no_query(except: /SELECT\s+1\s+AS\s+one\s+FROM/) do
|
167
159
|
import City.where(id: dummy_cities.first.id)
|
@@ -175,28 +167,27 @@ describe Chewy::Type::Import do
|
|
175
167
|
payload = subscribe_notification
|
176
168
|
dummy_cities.first.destroy
|
177
169
|
import dummy_cities
|
178
|
-
expect(payload).to eq(
|
170
|
+
expect(payload).to eq(index: CitiesIndex, import: {delete: 1, index: 2})
|
179
171
|
end
|
180
172
|
|
181
173
|
specify do
|
182
174
|
payload = subscribe_notification
|
183
175
|
dummy_cities.first.destroy
|
184
176
|
import dummy_cities, batch_size: 2
|
185
|
-
expect(payload).to eq(
|
177
|
+
expect(payload).to eq(index: CitiesIndex, import: {delete: 1, index: 2})
|
186
178
|
end
|
187
179
|
|
188
180
|
specify do
|
189
181
|
payload = subscribe_notification
|
190
182
|
import dummy_cities, batch_size: 2
|
191
|
-
expect(payload).to eq(
|
183
|
+
expect(payload).to eq(index: CitiesIndex, import: {index: 3})
|
192
184
|
end
|
193
185
|
|
194
186
|
context do
|
195
187
|
before do
|
196
188
|
stub_index(:cities) do
|
197
|
-
|
198
|
-
|
199
|
-
end
|
189
|
+
index_scope City
|
190
|
+
field :name, type: 'object'
|
200
191
|
end
|
201
192
|
end
|
202
193
|
|
@@ -210,7 +201,7 @@ describe Chewy::Type::Import do
|
|
210
201
|
specify do
|
211
202
|
payload = subscribe_notification
|
212
203
|
import dummy_cities, batch_size: 2
|
213
|
-
expect(payload).to eq(
|
204
|
+
expect(payload).to eq(index: CitiesIndex,
|
214
205
|
errors: {index: {mapper_parsing_exception => %w[1 2 3]}},
|
215
206
|
import: {index: 3})
|
216
207
|
end
|
@@ -218,7 +209,7 @@ describe Chewy::Type::Import do
|
|
218
209
|
end
|
219
210
|
|
220
211
|
context 'fields' do
|
221
|
-
before { CitiesIndex
|
212
|
+
before { CitiesIndex.import!(dummy_cities.first(2)) }
|
222
213
|
|
223
214
|
context do
|
224
215
|
before { expect(Chewy.client).to receive(:bulk).twice.and_call_original }
|
@@ -226,7 +217,7 @@ describe Chewy::Type::Import do
|
|
226
217
|
end
|
227
218
|
|
228
219
|
context do
|
229
|
-
before { CitiesIndex
|
220
|
+
before { CitiesIndex.import!(dummy_cities.last) }
|
230
221
|
before { expect(Chewy.client).to receive(:bulk).once.and_call_original }
|
231
222
|
specify { expect(import(dummy_cities, update_fields: [:name])).to eq(true) }
|
232
223
|
end
|
@@ -235,10 +226,8 @@ describe Chewy::Type::Import do
|
|
235
226
|
context 'fields integrational' do
|
236
227
|
before do
|
237
228
|
stub_index(:cities) do
|
238
|
-
|
239
|
-
|
240
|
-
field :object, type: 'object'
|
241
|
-
end
|
229
|
+
field :name
|
230
|
+
field :object, type: 'object'
|
242
231
|
end
|
243
232
|
end
|
244
233
|
|
@@ -266,9 +255,14 @@ describe Chewy::Type::Import do
|
|
266
255
|
import(objects, update_fields: %i[name])
|
267
256
|
|
268
257
|
expect(payload).to eq(
|
269
|
-
errors: {
|
258
|
+
errors: {
|
259
|
+
index: {{
|
260
|
+
'type' => 'mapper_parsing_exception',
|
261
|
+
'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
|
262
|
+
} => %w[2 4]}
|
263
|
+
},
|
270
264
|
import: {index: 6},
|
271
|
-
|
265
|
+
index: CitiesIndex
|
272
266
|
)
|
273
267
|
expect(imported_cities).to match_array([
|
274
268
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 11}},
|
@@ -284,9 +278,14 @@ describe Chewy::Type::Import do
|
|
284
278
|
import(objects, batch_size: 2, update_fields: %i[name])
|
285
279
|
|
286
280
|
expect(payload).to eq(
|
287
|
-
errors: {
|
281
|
+
errors: {
|
282
|
+
index: {{
|
283
|
+
'type' => 'mapper_parsing_exception',
|
284
|
+
'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
|
285
|
+
} => %w[2 4]}
|
286
|
+
},
|
288
287
|
import: {index: 6},
|
289
|
-
|
288
|
+
index: CitiesIndex
|
290
289
|
)
|
291
290
|
expect(imported_cities).to match_array([
|
292
291
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 11}},
|
@@ -296,7 +295,7 @@ describe Chewy::Type::Import do
|
|
296
295
|
end
|
297
296
|
|
298
297
|
context do
|
299
|
-
before { CitiesIndex
|
298
|
+
before { CitiesIndex.import!(objects[4]) }
|
300
299
|
|
301
300
|
specify do
|
302
301
|
payload = subscribe_notification
|
@@ -305,9 +304,14 @@ describe Chewy::Type::Import do
|
|
305
304
|
import(objects, batch_size: 2, update_fields: %i[name])
|
306
305
|
|
307
306
|
expect(payload).to eq(
|
308
|
-
errors: {
|
307
|
+
errors: {
|
308
|
+
index: {{
|
309
|
+
'type' => 'mapper_parsing_exception',
|
310
|
+
'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
|
311
|
+
} => %w[2 4]}
|
312
|
+
},
|
309
313
|
import: {index: 6},
|
310
|
-
|
314
|
+
index: CitiesIndex
|
311
315
|
)
|
312
316
|
expect(imported_cities).to match_array([
|
313
317
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 11}},
|
@@ -318,7 +322,7 @@ describe Chewy::Type::Import do
|
|
318
322
|
end
|
319
323
|
|
320
324
|
context do
|
321
|
-
before { CitiesIndex
|
325
|
+
before { CitiesIndex.import!(old_objects[1], old_objects[3], objects[4]) }
|
322
326
|
|
323
327
|
specify do
|
324
328
|
payload = subscribe_notification
|
@@ -328,7 +332,7 @@ describe Chewy::Type::Import do
|
|
328
332
|
|
329
333
|
expect(payload).to eq(
|
330
334
|
import: {index: 6},
|
331
|
-
|
335
|
+
index: CitiesIndex
|
332
336
|
)
|
333
337
|
expect(imported_cities).to match_array([
|
334
338
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 11}},
|
@@ -347,7 +351,7 @@ describe Chewy::Type::Import do
|
|
347
351
|
|
348
352
|
expect(payload).to eq(
|
349
353
|
import: {index: 6},
|
350
|
-
|
354
|
+
index: CitiesIndex
|
351
355
|
)
|
352
356
|
expect(imported_cities).to match_array([
|
353
357
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 11}},
|
@@ -379,7 +383,7 @@ describe Chewy::Type::Import do
|
|
379
383
|
end
|
380
384
|
|
381
385
|
context do
|
382
|
-
before { CitiesIndex
|
386
|
+
before { CitiesIndex.import!(old_objects) }
|
383
387
|
|
384
388
|
specify do
|
385
389
|
payload = subscribe_notification
|
@@ -389,7 +393,7 @@ describe Chewy::Type::Import do
|
|
389
393
|
|
390
394
|
expect(payload).to eq(
|
391
395
|
import: {index: 6},
|
392
|
-
|
396
|
+
index: CitiesIndex
|
393
397
|
)
|
394
398
|
expect(imported_cities).to match_array([
|
395
399
|
{'id' => '1', 'name' => 'Name11', 'object' => {'foo' => 1}},
|
@@ -403,7 +407,7 @@ describe Chewy::Type::Import do
|
|
403
407
|
end
|
404
408
|
|
405
409
|
context do
|
406
|
-
before { CitiesIndex
|
410
|
+
before { CitiesIndex.import!(old_objects) }
|
407
411
|
|
408
412
|
specify do
|
409
413
|
payload = subscribe_notification
|
@@ -412,9 +416,14 @@ describe Chewy::Type::Import do
|
|
412
416
|
import(objects, update_fields: %i[object])
|
413
417
|
|
414
418
|
expect(payload).to eq(
|
415
|
-
errors: {
|
419
|
+
errors: {
|
420
|
+
update: {{
|
421
|
+
'type' => 'mapper_parsing_exception',
|
422
|
+
'reason' => 'object mapping for [object] tried to parse field [object] as object, but found a concrete value'
|
423
|
+
} => %w[2 4]}
|
424
|
+
},
|
416
425
|
import: {index: 6},
|
417
|
-
|
426
|
+
index: CitiesIndex
|
418
427
|
)
|
419
428
|
expect(imported_cities).to match_array([
|
420
429
|
{'id' => '1', 'name' => 'Name1', 'object' => {'foo' => 11}},
|
@@ -432,9 +441,8 @@ describe Chewy::Type::Import do
|
|
432
441
|
context do
|
433
442
|
before do
|
434
443
|
stub_index(:cities) do
|
435
|
-
|
436
|
-
|
437
|
-
end
|
444
|
+
index_scope City
|
445
|
+
field :name, type: 'object'
|
438
446
|
end
|
439
447
|
end
|
440
448
|
|
@@ -446,9 +454,8 @@ describe Chewy::Type::Import do
|
|
446
454
|
context do
|
447
455
|
before do
|
448
456
|
stub_index(:cities) do
|
449
|
-
|
450
|
-
|
451
|
-
end
|
457
|
+
index_scope City
|
458
|
+
field :name, type: 'object', value: -> { name == 'name1' ? name : {name: name} }
|
452
459
|
end
|
453
460
|
end
|
454
461
|
|
@@ -460,19 +467,19 @@ describe Chewy::Type::Import do
|
|
460
467
|
|
461
468
|
context 'default_import_options are set' do
|
462
469
|
before do
|
463
|
-
CitiesIndex
|
470
|
+
CitiesIndex.default_import_options(batch_size: 500)
|
464
471
|
end
|
465
472
|
|
466
473
|
specify do
|
467
|
-
expect(CitiesIndex
|
468
|
-
CitiesIndex
|
474
|
+
expect(CitiesIndex.adapter).to receive(:import).with(any_args, hash_including(batch_size: 500))
|
475
|
+
CitiesIndex.import
|
469
476
|
end
|
470
477
|
end
|
471
478
|
end
|
472
479
|
|
473
480
|
describe '.import', :orm do
|
474
481
|
def import(*args)
|
475
|
-
CitiesIndex
|
482
|
+
CitiesIndex.import(*args)
|
476
483
|
end
|
477
484
|
|
478
485
|
it_behaves_like 'importing'
|
@@ -481,7 +488,7 @@ describe Chewy::Type::Import do
|
|
481
488
|
def import(*args)
|
482
489
|
options = args.extract_options!
|
483
490
|
options[:parallel] = 0
|
484
|
-
CitiesIndex
|
491
|
+
CitiesIndex.import(*args, options)
|
485
492
|
end
|
486
493
|
|
487
494
|
it_behaves_like 'importing'
|
@@ -489,54 +496,51 @@ describe Chewy::Type::Import do
|
|
489
496
|
end
|
490
497
|
|
491
498
|
describe '.import!', :orm do
|
492
|
-
specify { expect { CitiesIndex
|
499
|
+
specify { expect { CitiesIndex.import! }.not_to raise_error }
|
493
500
|
|
494
501
|
context do
|
495
502
|
before do
|
496
503
|
stub_index(:cities) do
|
497
|
-
|
498
|
-
|
499
|
-
end
|
504
|
+
index_scope City
|
505
|
+
field :name, type: 'object'
|
500
506
|
end
|
501
507
|
end
|
502
508
|
|
503
|
-
specify { expect { CitiesIndex
|
509
|
+
specify { expect { CitiesIndex.import!(dummy_cities) }.to raise_error Chewy::ImportFailed }
|
504
510
|
end
|
505
511
|
end
|
506
512
|
|
507
513
|
describe '.compose' do
|
508
514
|
before do
|
509
515
|
stub_index(:cities) do
|
510
|
-
|
511
|
-
|
512
|
-
collection.map { |o| [o.name, o.name + '42'] }.to_h
|
513
|
-
end
|
514
|
-
field :name, value: ->(o, c) { c.names[o.name] }
|
515
|
-
field :rating
|
516
|
+
crutch :names do |collection|
|
517
|
+
collection.map { |o| [o.name, "#{o.name}42"] }.to_h
|
516
518
|
end
|
519
|
+
field :name, value: ->(o, c) { c.names[o.name] }
|
520
|
+
field :rating
|
517
521
|
end
|
518
522
|
end
|
519
523
|
|
520
524
|
specify do
|
521
|
-
expect(CitiesIndex
|
525
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42)))
|
522
526
|
.to eq('name' => 'Name42', 'rating' => 42)
|
523
527
|
end
|
524
528
|
|
525
529
|
specify do
|
526
|
-
expect(CitiesIndex
|
530
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42), fields: %i[name]))
|
527
531
|
.to eq('name' => 'Name42')
|
528
532
|
end
|
529
533
|
|
530
534
|
context 'witchcraft' do
|
531
|
-
before { CitiesIndex
|
535
|
+
before { CitiesIndex.witchcraft! }
|
532
536
|
|
533
537
|
specify do
|
534
|
-
expect(CitiesIndex
|
538
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42)))
|
535
539
|
.to eq('name' => 'Name42', 'rating' => 42)
|
536
540
|
end
|
537
541
|
|
538
542
|
specify do
|
539
|
-
expect(CitiesIndex
|
543
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42), fields: %i[name]))
|
540
544
|
.to eq('name' => 'Name42')
|
541
545
|
end
|
542
546
|
end
|
@@ -545,12 +549,12 @@ describe Chewy::Type::Import do
|
|
545
549
|
let(:crutches) { double(names: {'Name' => 'Name43'}) }
|
546
550
|
|
547
551
|
specify do
|
548
|
-
expect(CitiesIndex
|
552
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42), crutches))
|
549
553
|
.to eq('name' => 'Name43', 'rating' => 42)
|
550
554
|
end
|
551
555
|
|
552
556
|
specify do
|
553
|
-
expect(CitiesIndex
|
557
|
+
expect(CitiesIndex.compose(double(name: 'Name', rating: 42), crutches, fields: %i[name]))
|
554
558
|
.to eq('name' => 'Name43')
|
555
559
|
end
|
556
560
|
end
|