chewy 0.10.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +25 -25
- data/.travis.yml +21 -29
- data/Appraisals +27 -9
- data/CHANGELOG.md +36 -0
- data/Gemfile +3 -1
- data/README.md +73 -23
- data/chewy.gemspec +6 -8
- data/gemfiles/rails.4.0.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.1.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.4.2.mongoid.5.2.gemfile} +2 -1
- data/gemfiles/rails.5.0.activerecord.gemfile +2 -1
- data/gemfiles/{rails.5.0.mongoid.6.0.gemfile → rails.5.0.mongoid.6.1.gemfile} +3 -2
- data/gemfiles/rails.5.1.activerecord.gemfile +2 -1
- data/gemfiles/{rails.5.1.mongoid.6.1.gemfile → rails.5.1.mongoid.6.3.gemfile} +3 -2
- data/gemfiles/rails.5.2.activerecord.gemfile +16 -0
- data/gemfiles/sequel.4.45.gemfile +2 -2
- data/lib/chewy.rb +1 -0
- data/lib/chewy/config.rb +8 -19
- data/lib/chewy/fields/base.rb +15 -3
- data/lib/chewy/fields/root.rb +13 -9
- data/lib/chewy/index.rb +1 -1
- data/lib/chewy/index/actions.rb +14 -12
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +12 -10
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/query.rb +135 -96
- data/lib/chewy/query/filters.rb +20 -3
- data/lib/chewy/query/loading.rb +0 -1
- data/lib/chewy/railtie.rb +2 -4
- data/lib/chewy/rake_helper.rb +5 -5
- data/lib/chewy/rspec/update_index.rb +3 -5
- data/lib/chewy/search.rb +2 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
- data/lib/chewy/stash.rb +30 -21
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/type.rb +2 -2
- data/lib/chewy/type/adapter/base.rb +9 -9
- data/lib/chewy/type/adapter/mongoid.rb +1 -3
- data/lib/chewy/type/adapter/sequel.rb +4 -6
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +3 -2
- data/lib/chewy/type/import/bulk_builder.rb +1 -1
- data/lib/chewy/type/import/journal_builder.rb +3 -3
- data/lib/chewy/type/import/routine.rb +2 -2
- data/lib/chewy/type/mapping.rb +40 -34
- data/lib/chewy/type/observe.rb +13 -9
- data/lib/chewy/type/syncer.rb +2 -2
- data/lib/chewy/type/witchcraft.rb +2 -2
- data/lib/chewy/type/wrapper.rb +2 -2
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/spec/chewy/config_spec.rb +16 -0
- data/spec/chewy/fields/base_spec.rb +61 -65
- data/spec/chewy/fields/root_spec.rb +13 -13
- data/spec/chewy/index/actions_spec.rb +37 -5
- data/spec/chewy/index/specification_spec.rb +25 -16
- data/spec/chewy/index_spec.rb +61 -8
- data/spec/chewy/journal_spec.rb +11 -11
- data/spec/chewy/query/filters_spec.rb +1 -1
- data/spec/chewy/query/nodes/not_spec.rb +1 -0
- data/spec/chewy/query_spec.rb +3 -2
- data/spec/chewy/rake_helper_spec.rb +46 -33
- data/spec/chewy/search_spec.rb +20 -10
- data/spec/chewy/stash_spec.rb +1 -1
- data/spec/chewy/strategy/shoryuken_spec.rb +2 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +8 -8
- data/spec/chewy/type/import_spec.rb +6 -0
- data/spec/chewy/type/mapping_spec.rb +48 -17
- data/spec/spec_helper.rb +8 -0
- metadata +26 -25
@@ -63,7 +63,7 @@ describe Chewy::Fields::Base do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'implicit values' do
|
66
|
-
let(:field) { described_class.new(:name, type: '
|
66
|
+
let(:field) { described_class.new(:name, type: 'integer') }
|
67
67
|
before do
|
68
68
|
field.children.push(described_class.new(:name))
|
69
69
|
field.children.push(described_class.new(:untouched))
|
@@ -87,8 +87,8 @@ describe Chewy::Fields::Base do
|
|
87
87
|
|
88
88
|
describe '#mappings_hash' do
|
89
89
|
let(:field) { described_class.new(:name, type: :object) }
|
90
|
-
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "
|
91
|
-
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "
|
90
|
+
let(:fields1) { Array.new(2) { |i| described_class.new("name#{i + 1}", type: "integer#{i + 1}") } }
|
91
|
+
let(:fields2) { Array.new(2) { |i| described_class.new("name#{i + 3}", type: "integer#{i + 3}") } }
|
92
92
|
before do
|
93
93
|
fields1.each { |m| field.children.push(m) }
|
94
94
|
fields2.each { |m| fields1[0].children.push(m) }
|
@@ -96,28 +96,30 @@ describe Chewy::Fields::Base do
|
|
96
96
|
|
97
97
|
specify do
|
98
98
|
expect(field.mappings_hash).to eq(name: {type: :object, properties: {
|
99
|
-
name1: {type: '
|
100
|
-
name3: {type: '
|
101
|
-
}}, name2: {type: '
|
99
|
+
name1: {type: 'integer1', fields: {
|
100
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
101
|
+
}}, name2: {type: 'integer2'}
|
102
102
|
}})
|
103
103
|
end
|
104
104
|
|
105
105
|
context do
|
106
|
-
let(:field) { described_class.new(:name, type: :
|
107
|
-
let(:fields1)
|
106
|
+
let(:field) { described_class.new(:name, type: :integer) }
|
107
|
+
let(:fields1) do
|
108
|
+
[described_class.new(:name1), described_class.new(:name2, type: 'integer')]
|
109
|
+
end
|
108
110
|
|
109
111
|
specify do
|
110
|
-
expect(field.mappings_hash).to eq(name: {type: :
|
112
|
+
expect(field.mappings_hash).to eq(name: {type: :integer, fields: {
|
111
113
|
name1: {type: 'object', properties: {
|
112
|
-
name3: {type: '
|
113
|
-
}}, name2: {type: '
|
114
|
+
name3: {type: 'integer3'}, name4: {type: 'integer4'}
|
115
|
+
}}, name2: {type: 'integer'}
|
114
116
|
}})
|
115
117
|
end
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
119
121
|
context 'integration' do
|
120
|
-
context '
|
122
|
+
context 'default field type' do
|
121
123
|
before do
|
122
124
|
stub_index(:events) do
|
123
125
|
define_type :event do
|
@@ -126,26 +128,33 @@ describe Chewy::Fields::Base do
|
|
126
128
|
field :id
|
127
129
|
field :licenses do
|
128
130
|
field :id
|
129
|
-
field :
|
131
|
+
field :created_at, type: 'time'
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
138
|
+
around do |example|
|
139
|
+
previous_type = Chewy.default_field_type
|
140
|
+
Chewy.default_field_type = 'integer'
|
141
|
+
example.run
|
142
|
+
Chewy.default_field_type = previous_type
|
143
|
+
end
|
144
|
+
|
136
145
|
specify do
|
137
146
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
138
147
|
properties: {
|
139
|
-
id: {type: '
|
148
|
+
id: {type: 'integer'},
|
140
149
|
category: {
|
141
150
|
type: 'object',
|
142
151
|
properties: {
|
143
|
-
id: {type: '
|
152
|
+
id: {type: 'integer'},
|
144
153
|
licenses: {
|
145
154
|
type: 'object',
|
146
155
|
properties: {
|
147
|
-
id: {type: '
|
148
|
-
|
156
|
+
id: {type: 'integer'},
|
157
|
+
created_at: {type: 'time'}
|
149
158
|
}
|
150
159
|
}
|
151
160
|
}
|
@@ -153,45 +162,32 @@ describe Chewy::Fields::Base do
|
|
153
162
|
}
|
154
163
|
})
|
155
164
|
end
|
165
|
+
end
|
156
166
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
type: 'object',
|
171
|
-
properties: {
|
172
|
-
id: {type: 'text'},
|
173
|
-
licenses: {
|
174
|
-
type: 'object',
|
175
|
-
properties: {
|
176
|
-
id: {type: 'text'},
|
177
|
-
name: {type: 'text'}
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
})
|
167
|
+
context 'objects, hashes and arrays' do
|
168
|
+
before do
|
169
|
+
stub_index(:events) do
|
170
|
+
define_type :event do
|
171
|
+
field :id
|
172
|
+
field :category do
|
173
|
+
field :id
|
174
|
+
field :licenses do
|
175
|
+
field :id
|
176
|
+
field :name
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
184
180
|
end
|
185
181
|
end
|
186
182
|
|
187
183
|
specify do
|
188
|
-
expect(EventsIndex::Event.
|
184
|
+
expect(EventsIndex::Event.root.compose(
|
189
185
|
id: 1, category: {id: 2, licenses: {id: 3, name: 'Name'}}
|
190
186
|
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
191
187
|
end
|
192
188
|
|
193
189
|
specify do
|
194
|
-
expect(EventsIndex::Event.
|
190
|
+
expect(EventsIndex::Event.root.compose(id: 1, category: [
|
195
191
|
{id: 2, 'licenses' => {id: 3, name: 'Name1'}},
|
196
192
|
{id: 4, licenses: nil}
|
197
193
|
])).to eq('id' => 1, 'category' => [
|
@@ -201,7 +197,7 @@ describe Chewy::Fields::Base do
|
|
201
197
|
end
|
202
198
|
|
203
199
|
specify do
|
204
|
-
expect(EventsIndex::Event.
|
200
|
+
expect(EventsIndex::Event.root.compose('id' => 1, category: {id: 2, licenses: [
|
205
201
|
{id: 3, name: 'Name1'}, {id: 4, name: 'Name2'}
|
206
202
|
]})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
207
203
|
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
@@ -209,7 +205,7 @@ describe Chewy::Fields::Base do
|
|
209
205
|
end
|
210
206
|
|
211
207
|
specify do
|
212
|
-
expect(EventsIndex::Event.
|
208
|
+
expect(EventsIndex::Event.root.compose(id: 1, category: [
|
213
209
|
{id: 2, licenses: [
|
214
210
|
{id: 3, 'name' => 'Name1'}, {id: 4, name: 'Name2'}
|
215
211
|
]},
|
@@ -223,13 +219,13 @@ describe Chewy::Fields::Base do
|
|
223
219
|
end
|
224
220
|
|
225
221
|
specify do
|
226
|
-
expect(EventsIndex::Event.
|
222
|
+
expect(EventsIndex::Event.root.compose(
|
227
223
|
double(id: 1, category: double(id: 2, licenses: double(id: 3, name: 'Name')))
|
228
224
|
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
229
225
|
end
|
230
226
|
|
231
227
|
specify do
|
232
|
-
expect(EventsIndex::Event.
|
228
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
233
229
|
double(id: 2, licenses: double(id: 3, name: 'Name1')),
|
234
230
|
double(id: 4, licenses: nil)
|
235
231
|
]))).to eq('id' => 1, 'category' => [
|
@@ -239,7 +235,7 @@ describe Chewy::Fields::Base do
|
|
239
235
|
end
|
240
236
|
|
241
237
|
specify do
|
242
|
-
expect(EventsIndex::Event.
|
238
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: double(id: 2, licenses: [
|
243
239
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
244
240
|
])))).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
|
245
241
|
{'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
|
@@ -247,7 +243,7 @@ describe Chewy::Fields::Base do
|
|
247
243
|
end
|
248
244
|
|
249
245
|
specify do
|
250
|
-
expect(EventsIndex::Event.
|
246
|
+
expect(EventsIndex::Event.root.compose(double(id: 1, category: [
|
251
247
|
double(id: 2, licenses: [
|
252
248
|
double(id: 3, name: 'Name1'), double(id: 4, name: 'Name2')
|
253
249
|
]),
|
@@ -265,11 +261,11 @@ describe Chewy::Fields::Base do
|
|
265
261
|
before do
|
266
262
|
stub_index(:events) do
|
267
263
|
define_type :event do
|
268
|
-
field :id
|
264
|
+
field :id, type: 'integer'
|
269
265
|
field :category, value: -> { categories } do
|
270
|
-
field :id
|
266
|
+
field :id, type: 'integer'
|
271
267
|
field :licenses, value: -> { license } do
|
272
|
-
field :id
|
268
|
+
field :id, type: 'integer'
|
273
269
|
field :name
|
274
270
|
end
|
275
271
|
end
|
@@ -278,7 +274,7 @@ describe Chewy::Fields::Base do
|
|
278
274
|
end
|
279
275
|
|
280
276
|
specify do
|
281
|
-
expect(EventsIndex::Event.
|
277
|
+
expect(EventsIndex::Event.root.compose(
|
282
278
|
double(id: 1, categories: double(id: 2, license: double(id: 3, name: 'Name')))
|
283
279
|
)).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
|
284
280
|
end
|
@@ -288,8 +284,8 @@ describe Chewy::Fields::Base do
|
|
288
284
|
before do
|
289
285
|
stub_index(:events) do
|
290
286
|
define_type :event do
|
291
|
-
field :id
|
292
|
-
field :name, type: '
|
287
|
+
field :id, type: 'integer'
|
288
|
+
field :name, type: 'integer' do
|
293
289
|
field :raw, analyzer: 'my_own'
|
294
290
|
end
|
295
291
|
field :category, type: 'object'
|
@@ -300,11 +296,11 @@ describe Chewy::Fields::Base do
|
|
300
296
|
specify do
|
301
297
|
expect(EventsIndex::Event.mappings_hash).to eq(event: {
|
302
298
|
properties: {
|
303
|
-
id: {type: '
|
299
|
+
id: {type: 'integer'},
|
304
300
|
name: {
|
305
|
-
type: '
|
301
|
+
type: 'integer',
|
306
302
|
fields: {
|
307
|
-
raw: {analyzer: 'my_own', type:
|
303
|
+
raw: {analyzer: 'my_own', type: Chewy.default_field_type}
|
308
304
|
}
|
309
305
|
},
|
310
306
|
category: {type: 'object'}
|
@@ -313,7 +309,7 @@ describe Chewy::Fields::Base do
|
|
313
309
|
end
|
314
310
|
|
315
311
|
specify do
|
316
|
-
expect(EventsIndex::Event.
|
312
|
+
expect(EventsIndex::Event.root.compose(
|
317
313
|
double(id: 1, name: 'Jonny', category: double(id: 2, as_json: {'name' => 'Borogoves'}))
|
318
314
|
)).to eq(
|
319
315
|
'id' => 1,
|
@@ -323,7 +319,7 @@ describe Chewy::Fields::Base do
|
|
323
319
|
end
|
324
320
|
|
325
321
|
specify do
|
326
|
-
expect(EventsIndex::Event.
|
322
|
+
expect(EventsIndex::Event.root.compose(
|
327
323
|
double(id: 1, name: 'Jonny', category: [
|
328
324
|
double(id: 2, as_json: {'name' => 'Borogoves1'}),
|
329
325
|
double(id: 3, as_json: {'name' => 'Borogoves2'})
|
@@ -388,7 +384,7 @@ describe Chewy::Fields::Base do
|
|
388
384
|
end
|
389
385
|
|
390
386
|
specify do
|
391
|
-
expect(CountriesIndex::Country.
|
387
|
+
expect(CountriesIndex::Country.root.compose(country_with_cities)).to eq('id' => 1, 'cities' => [
|
392
388
|
{'id' => 1, 'name' => 'City1'}, {'id' => 2, 'name' => 'City2'}
|
393
389
|
])
|
394
390
|
end
|
@@ -407,7 +403,7 @@ describe Chewy::Fields::Base do
|
|
407
403
|
end
|
408
404
|
|
409
405
|
specify do
|
410
|
-
expect(CitiesIndex::City.
|
406
|
+
expect(CitiesIndex::City.root.compose(
|
411
407
|
City.create!(id: 1, country: Country.create!(id: 1, name: 'Country'))
|
412
408
|
)).to eq('id' => 1, 'country' => {'id' => 1, 'name' => 'Country'})
|
413
409
|
end
|
@@ -5,7 +5,7 @@ describe Chewy::Fields::Root do
|
|
5
5
|
|
6
6
|
describe '#dynamic_template' do
|
7
7
|
specify do
|
8
|
-
field.dynamic_template 'hello', type: '
|
8
|
+
field.dynamic_template 'hello', type: 'keyword'
|
9
9
|
field.dynamic_template 'hello*', :integer
|
10
10
|
field.dynamic_template 'hello.*'
|
11
11
|
field.dynamic_template(/hello/)
|
@@ -14,7 +14,7 @@ describe Chewy::Fields::Root do
|
|
14
14
|
field.dynamic_template(/hello\..*/)
|
15
15
|
|
16
16
|
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
17
|
-
{template_1: {mapping: {type: '
|
17
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}},
|
18
18
|
{template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
|
19
19
|
{template_3: {mapping: {}, path_match: 'hello.*'}},
|
20
20
|
{template_4: {mapping: {}, match: 'hello', match_pattern: 'regexp'}},
|
@@ -32,10 +32,10 @@ describe Chewy::Fields::Root do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
specify do
|
35
|
-
field.dynamic_template 'hello', type: '
|
35
|
+
field.dynamic_template 'hello', type: 'keyword'
|
36
36
|
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
37
37
|
{template_42: {mapping: {}, match: ''}},
|
38
|
-
{template_1: {mapping: {type: '
|
38
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}}
|
39
39
|
]})
|
40
40
|
end
|
41
41
|
end
|
@@ -53,11 +53,11 @@ describe Chewy::Fields::Root do
|
|
53
53
|
let(:city) { City.new(name: 'London', rating: 100) }
|
54
54
|
|
55
55
|
specify do
|
56
|
-
expect(PlacesIndex::City.
|
56
|
+
expect(PlacesIndex::City.root.compose(city))
|
57
57
|
.to match(hash_including('name' => 'London', 'rating' => 100))
|
58
58
|
end
|
59
59
|
specify do
|
60
|
-
expect(PlacesIndex::City.
|
60
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
61
61
|
.to eq('name' => 'London')
|
62
62
|
end
|
63
63
|
end
|
@@ -74,11 +74,11 @@ describe Chewy::Fields::Root do
|
|
74
74
|
let(:city) { double(name: 'London', rating: 100) }
|
75
75
|
|
76
76
|
specify do
|
77
|
-
expect(PlacesIndex::City.
|
77
|
+
expect(PlacesIndex::City.root.compose(city))
|
78
78
|
.to eq('name' => 'London', 'rating' => 100)
|
79
79
|
end
|
80
80
|
specify do
|
81
|
-
expect(PlacesIndex::City.
|
81
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
82
82
|
.to eq('name' => 'London')
|
83
83
|
end
|
84
84
|
end
|
@@ -95,12 +95,12 @@ describe Chewy::Fields::Root do
|
|
95
95
|
let(:city) { double(name: 'London', rating: 100) }
|
96
96
|
|
97
97
|
specify do
|
98
|
-
expect(PlacesIndex::City.
|
98
|
+
expect(PlacesIndex::City.root.compose(city))
|
99
99
|
.to eq('name' => 'LondonModified', 'rating' => 101)
|
100
100
|
end
|
101
101
|
|
102
102
|
specify do
|
103
|
-
expect(PlacesIndex::City.
|
103
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
104
104
|
.to eq('name' => 'LondonModified')
|
105
105
|
end
|
106
106
|
end
|
@@ -120,12 +120,12 @@ describe Chewy::Fields::Root do
|
|
120
120
|
let(:city) { double(name: 'London', rating: 100) }
|
121
121
|
|
122
122
|
specify do
|
123
|
-
expect(PlacesIndex::City.
|
123
|
+
expect(PlacesIndex::City.root.compose(city))
|
124
124
|
.to eq('name' => 'LondonModifiedModified', 'rating' => 101)
|
125
125
|
end
|
126
126
|
|
127
127
|
specify do
|
128
|
-
expect(PlacesIndex::City.
|
128
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
129
129
|
.to eq('name' => 'LondonModifiedModified')
|
130
130
|
end
|
131
131
|
end
|
@@ -141,7 +141,7 @@ describe Chewy::Fields::Root do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
specify do
|
144
|
-
expect(PlacesIndex::City.
|
144
|
+
expect(PlacesIndex::City.root.child_hash).to match(
|
145
145
|
name: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :name)),
|
146
146
|
rating: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :rating))
|
147
147
|
)
|
@@ -429,6 +429,12 @@ describe Chewy::Index::Actions do
|
|
429
429
|
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
430
430
|
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
431
431
|
end
|
432
|
+
|
433
|
+
specify 'uses empty index settings if not defined' do
|
434
|
+
allow(Chewy).to receive(:wait_for_status).and_return(nil)
|
435
|
+
allow(CitiesIndex).to receive(:settings_hash).and_return({})
|
436
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
437
|
+
end
|
432
438
|
end
|
433
439
|
end
|
434
440
|
|
@@ -478,7 +484,7 @@ describe Chewy::Index::Actions do
|
|
478
484
|
end
|
479
485
|
end
|
480
486
|
|
481
|
-
|
487
|
+
xcontext 'applying journal' do
|
482
488
|
before do
|
483
489
|
stub_index(:cities) do
|
484
490
|
define_type City do
|
@@ -494,23 +500,49 @@ describe Chewy::Index::Actions do
|
|
494
500
|
|
495
501
|
let(:parallel_update) do
|
496
502
|
Thread.new do
|
503
|
+
p 'start parallel'
|
497
504
|
sleep(1.5)
|
498
505
|
cities.first.update(name: 'NewName1', rating: 0)
|
499
506
|
cities.last.update(name: 'NewName3', rating: 0)
|
500
507
|
CitiesIndex::City.import!([cities.first, cities.last], journal: true)
|
508
|
+
p 'end parallel'
|
501
509
|
end
|
502
510
|
end
|
503
511
|
|
504
512
|
specify 'with journal application' do
|
505
|
-
|
506
|
-
|
513
|
+
cities
|
514
|
+
p 'cities created1'
|
515
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
516
|
+
[
|
517
|
+
parallel_update,
|
518
|
+
Thread.new do
|
519
|
+
p 'start reset1'
|
520
|
+
CitiesIndex.reset!('suffix')
|
521
|
+
p 'end reset1'
|
522
|
+
end
|
523
|
+
].map(&:join)
|
524
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
525
|
+
p 'expect1'
|
507
526
|
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
|
527
|
+
p 'end expect1'
|
508
528
|
end
|
509
529
|
|
510
530
|
specify 'without journal application' do
|
511
|
-
|
512
|
-
|
531
|
+
cities
|
532
|
+
p 'cities created2'
|
533
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
534
|
+
[
|
535
|
+
parallel_update,
|
536
|
+
Thread.new do
|
537
|
+
p 'start reset2'
|
538
|
+
CitiesIndex.reset!('suffix', apply_journal: false)
|
539
|
+
p 'end reset2'
|
540
|
+
end
|
541
|
+
].map(&:join)
|
542
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
543
|
+
p 'expect2'
|
513
544
|
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
|
545
|
+
p 'end expect2'
|
514
546
|
end
|
515
547
|
end
|
516
548
|
|