chewy 5.0.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +214 -0
  3. data/Appraisals +1 -17
  4. data/CHANGELOG.md +40 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +61 -35
  8. data/chewy.gemspec +4 -4
  9. data/gemfiles/rails.5.2.activerecord.gemfile +4 -3
  10. data/gemfiles/{rails.5.0.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +4 -3
  11. data/gemfiles/{rails.5.0.mongoid.6.1.gemfile → rails.6.0.activerecord.gemfile} +4 -3
  12. data/gemfiles/{rails.5.1.activerecord.gemfile → rails.6.1.activerecord.gemfile} +6 -3
  13. data/gemfiles/ruby3.gemfile +10 -0
  14. data/lib/chewy/backports/duplicable.rb +1 -1
  15. data/lib/chewy/fields/base.rb +1 -1
  16. data/lib/chewy/fields/root.rb +2 -2
  17. data/lib/chewy/index/actions.rb +9 -3
  18. data/lib/chewy/query/loading.rb +1 -1
  19. data/lib/chewy/query/nodes/field.rb +1 -1
  20. data/lib/chewy/query.rb +5 -0
  21. data/lib/chewy/railtie.rb +1 -1
  22. data/lib/chewy/search/loader.rb +1 -1
  23. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  24. data/lib/chewy/search/parameters/indices.rb +123 -0
  25. data/lib/chewy/search/parameters.rb +24 -6
  26. data/lib/chewy/search/request.rb +76 -51
  27. data/lib/chewy/search/scrolling.rb +3 -5
  28. data/lib/chewy/search.rb +1 -5
  29. data/lib/chewy/strategy/active_job.rb +1 -1
  30. data/lib/chewy/strategy/sidekiq.rb +1 -1
  31. data/lib/chewy/type/adapter/active_record.rb +1 -1
  32. data/lib/chewy/type/adapter/mongoid.rb +1 -1
  33. data/lib/chewy/type/adapter/orm.rb +1 -1
  34. data/lib/chewy/type/adapter/sequel.rb +1 -1
  35. data/lib/chewy/type/import/bulk_request.rb +4 -2
  36. data/lib/chewy/type/import/journal_builder.rb +1 -1
  37. data/lib/chewy/type/import/routine.rb +1 -1
  38. data/lib/chewy/type/import.rb +3 -3
  39. data/lib/chewy/type/mapping.rb +4 -4
  40. data/lib/chewy/type/observe.rb +3 -3
  41. data/lib/chewy/type/witchcraft.rb +1 -1
  42. data/lib/chewy/type/wrapper.rb +1 -1
  43. data/lib/chewy/version.rb +1 -1
  44. data/lib/chewy.rb +1 -1
  45. data/spec/chewy/config_spec.rb +1 -1
  46. data/spec/chewy/fields/base_spec.rb +11 -9
  47. data/spec/chewy/index/actions_spec.rb +2 -2
  48. data/spec/chewy/journal_spec.rb +1 -1
  49. data/spec/chewy/search/parameters/indices_spec.rb +191 -0
  50. data/spec/chewy/search/parameters_spec.rb +20 -3
  51. data/spec/chewy/search/request_spec.rb +25 -9
  52. data/spec/chewy/search/response_spec.rb +8 -2
  53. data/spec/chewy/search_spec.rb +2 -2
  54. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  55. data/spec/chewy/strategy/shoryuken_spec.rb +6 -2
  56. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  57. data/spec/chewy/type/adapter/active_record_spec.rb +3 -3
  58. data/spec/chewy/type/import/bulk_builder_spec.rb +1 -1
  59. data/spec/chewy/type/observe_spec.rb +4 -4
  60. data/spec/spec_helper.rb +4 -1
  61. metadata +21 -22
  62. data/.travis.yml +0 -45
  63. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  64. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  65. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  66. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  67. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  68. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
@@ -10,7 +10,7 @@ module Chewy
10
10
 
11
11
  IMPORT_WORKER = lambda do |type, options, total, ids, index|
12
12
  ::Process.setproctitle("chewy [#{type}]: import data (#{index + 1}/#{total})")
13
- routine = Routine.new(type, options)
13
+ routine = Routine.new(type, **options)
14
14
  type.adapter.import(*ids, routine.options) do |action_objects|
15
15
  routine.process(**action_objects)
16
16
  end
@@ -19,7 +19,7 @@ module Chewy
19
19
 
20
20
  LEFTOVERS_WORKER = lambda do |type, options, total, body, index|
21
21
  ::Process.setproctitle("chewy [#{type}]: import leftovers (#{index + 1}/#{total})")
22
- routine = Routine.new(type, options)
22
+ routine = Routine.new(type, **options)
23
23
  routine.perform_bulk(body)
24
24
  routine.errors
25
25
  end
@@ -127,7 +127,7 @@ module Chewy
127
127
 
128
128
  def import_routine(*args)
129
129
  return if args.first.blank? && !args.first.nil?
130
- routine = Routine.new(self, args.extract_options!)
130
+ routine = Routine.new(self, **args.extract_options!)
131
131
  routine.create_indexes!
132
132
 
133
133
  if routine.parallel_options
@@ -35,8 +35,8 @@ module Chewy
35
35
  # end
36
36
  #
37
37
  def root(**options)
38
- self.root_object ||= Chewy::Fields::Root.new(type_name, Chewy.default_root_options.merge(options))
39
- root_object.update_options!(options)
38
+ self.root_object ||= Chewy::Fields::Root.new(type_name, **Chewy.default_root_options.merge(options))
39
+ root_object.update_options!(**options)
40
40
  yield if block_given?
41
41
  root_object
42
42
  end
@@ -126,9 +126,9 @@ module Chewy
126
126
  #
127
127
  def field(*args, **options, &block)
128
128
  if args.size > 1
129
- args.map { |name| field(name, options) }
129
+ args.map { |name| field(name, **options) }
130
130
  else
131
- expand_nested(Chewy::Fields::Base.new(args.first, options), &block)
131
+ expand_nested(Chewy::Fields::Base.new(args.first, **options), &block)
132
132
  end
133
133
  end
134
134
 
@@ -63,10 +63,10 @@ module Chewy
63
63
  update_proc = Observe.update_proc(type_name, *args, &block)
64
64
 
65
65
  if Chewy.use_after_commit_callbacks
66
- after_commit(callback_options, &update_proc)
66
+ after_commit(**callback_options, &update_proc)
67
67
  else
68
- after_save(callback_options, &update_proc)
69
- after_destroy(callback_options, &update_proc)
68
+ after_save(**callback_options, &update_proc)
69
+ after_destroy(**callback_options, &update_proc)
70
70
  end
71
71
  end
72
72
  end
@@ -58,7 +58,7 @@ module Chewy
58
58
  private
59
59
 
60
60
  def alicorn
61
- @alicorn ||= class_eval <<-RUBY, __FILE__, __LINE__ + 1
61
+ @alicorn ||= singleton_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
62
62
  -> (locals, object0, crutches) do
63
63
  #{composed_values(@type.root, 0)}
64
64
  end
@@ -41,7 +41,7 @@ module Chewy
41
41
 
42
42
  %w[_id _type _index].each do |name|
43
43
  define_method name do
44
- data[name]
44
+ _data[name]
45
45
  end
46
46
  end
47
47
 
data/lib/chewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '5.0.0'.freeze
2
+ VERSION = '5.2.0'.freeze
3
3
  end
data/lib/chewy.rb CHANGED
@@ -132,7 +132,7 @@ module Chewy
132
132
  def create_type(index, target, options = {}, &block)
133
133
  type = Class.new(Chewy::Type)
134
134
 
135
- adapter = adapters.find { |klass| klass.accepts?(target) }.new(target, options)
135
+ adapter = adapters.find { |klass| klass.accepts?(target) }.new(target, **options)
136
136
 
137
137
  index.const_set(adapter.name, type)
138
138
  type.send(:define_singleton_method, :index) { index }
@@ -141,7 +141,7 @@ describe Chewy::Config do
141
141
  context 'when Rails::VERSION constant is defined' do
142
142
  it 'looks for configuration in "config/chewy.yml"' do
143
143
  module Rails
144
- VERSION = '5.1.0'.freeze
144
+ VERSION = '5.1.1'.freeze
145
145
 
146
146
  def self.root
147
147
  Pathname.new(__dir__)
@@ -180,43 +180,45 @@ describe Chewy::Fields::Base do
180
180
  end
181
181
  end
182
182
 
183
+ # rubocop:disable Style/BracesAroundHashParameters
183
184
  specify do
184
- expect(EventsIndex::Event.root.compose(
185
- id: 1, category: {id: 2, licenses: {id: 3, name: 'Name'}}
186
- )).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
185
+ expect(EventsIndex::Event.root.compose({
186
+ id: 1, category: {id: 2, licenses: {id: 3, name: 'Name'}}
187
+ })).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name'}})
187
188
  end
188
189
 
189
190
  specify do
190
- expect(EventsIndex::Event.root.compose(id: 1, category: [
191
+ expect(EventsIndex::Event.root.compose({id: 1, category: [
191
192
  {id: 2, 'licenses' => {id: 3, name: 'Name1'}},
192
193
  {id: 4, licenses: nil}
193
- ])).to eq('id' => 1, 'category' => [
194
+ ]})).to eq('id' => 1, 'category' => [
194
195
  {'id' => 2, 'licenses' => {'id' => 3, 'name' => 'Name1'}},
195
196
  {'id' => 4, 'licenses' => nil.as_json}
196
197
  ])
197
198
  end
198
199
 
199
200
  specify do
200
- expect(EventsIndex::Event.root.compose('id' => 1, category: {id: 2, licenses: [
201
+ expect(EventsIndex::Event.root.compose({'id' => 1, category: {id: 2, licenses: [
201
202
  {id: 3, name: 'Name1'}, {id: 4, name: 'Name2'}
202
- ]})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
203
+ ]}})).to eq('id' => 1, 'category' => {'id' => 2, 'licenses' => [
203
204
  {'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
204
205
  ]})
205
206
  end
206
207
 
207
208
  specify do
208
- expect(EventsIndex::Event.root.compose(id: 1, category: [
209
+ expect(EventsIndex::Event.root.compose({id: 1, category: [
209
210
  {id: 2, licenses: [
210
211
  {id: 3, 'name' => 'Name1'}, {id: 4, name: 'Name2'}
211
212
  ]},
212
213
  {id: 5, licenses: []}
213
- ])).to eq('id' => 1, 'category' => [
214
+ ]})).to eq('id' => 1, 'category' => [
214
215
  {'id' => 2, 'licenses' => [
215
216
  {'id' => 3, 'name' => 'Name1'}, {'id' => 4, 'name' => 'Name2'}
216
217
  ]},
217
218
  {'id' => 5, 'licenses' => []}
218
219
  ])
219
220
  end
221
+ # rubocop:enable Style/BracesAroundHashParameters
220
222
 
221
223
  specify do
222
224
  expect(EventsIndex::Event.root.compose(
@@ -55,7 +55,7 @@ describe Chewy::Index::Actions do
55
55
  context do
56
56
  before { DummiesIndex.create }
57
57
  specify do
58
- expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies/)
58
+ expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
59
59
  end
60
60
  specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
61
61
  end
@@ -67,7 +67,7 @@ describe Chewy::Index::Actions do
67
67
  specify { expect(DummiesIndex.aliases).to eq([]) }
68
68
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
69
69
  specify do
70
- expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies_2013/)
70
+ expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
71
71
  end
72
72
  specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
73
73
 
@@ -54,7 +54,7 @@ describe Chewy::Journal do
54
54
  expect(Chewy::Stash::Journal.exists?).to eq true
55
55
 
56
56
  Timecop.freeze(update_time)
57
- cities.first.update_attributes!(name: 'Supername')
57
+ cities.first.update!(name: 'Supername')
58
58
 
59
59
  Timecop.freeze(destroy_time)
60
60
  countries.last.destroy
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chewy::Search::Parameters::Indices do
4
+ before do
5
+ stub_index(:first) do
6
+ define_type :one
7
+ define_type :two
8
+ end
9
+
10
+ stub_index(:second) do
11
+ define_type :three
12
+ end
13
+ end
14
+
15
+ subject { described_class.new(indices: FirstIndex, types: SecondIndex::Three) }
16
+
17
+ describe '#initialize' do
18
+ specify { expect(described_class.new.value).to eq(indices: [], types: []) }
19
+ specify { expect(described_class.new(nil).value).to eq(indices: [], types: []) }
20
+ specify { expect(described_class.new(foo: :whatever).value).to eq(indices: [], types: []) }
21
+ specify { expect(subject.value).to eq(indices: [FirstIndex], types: [SecondIndex::Three]) }
22
+ end
23
+
24
+ describe '#replace!' do
25
+ specify do
26
+ expect { subject.replace!(nil) }
27
+ .to change { subject.value }
28
+ .from(indices: [FirstIndex], types: [SecondIndex::Three])
29
+ .to(indices: [], types: [])
30
+ end
31
+
32
+ specify do
33
+ expect { subject.replace!(indices: SecondIndex, types: FirstIndex::One) }
34
+ .to change { subject.value }
35
+ .from(indices: [FirstIndex], types: [SecondIndex::Three])
36
+ .to(indices: [SecondIndex], types: [FirstIndex::One])
37
+ end
38
+ end
39
+
40
+ describe '#update!' do
41
+ specify do
42
+ expect { subject.update!(nil) }
43
+ .not_to change { subject.value }
44
+ end
45
+
46
+ specify do
47
+ expect { subject.update!(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three]) }
48
+ .to change { subject.value }
49
+ .from(indices: [FirstIndex], types: [SecondIndex::Three])
50
+ .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One])
51
+ end
52
+ end
53
+
54
+ describe '#merge!' do
55
+ specify do
56
+ expect { subject.merge!(described_class.new) }
57
+ .not_to change { subject.value }
58
+ end
59
+
60
+ specify do
61
+ expect { subject.merge!(described_class.new(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three])) }
62
+ .to change { subject.value }
63
+ .from(indices: [FirstIndex], types: [SecondIndex::Three])
64
+ .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One])
65
+ end
66
+ end
67
+
68
+ describe '#render' do
69
+ specify { expect(described_class.new.render).to eq({}) }
70
+ specify do
71
+ expect(described_class.new(
72
+ indices: FirstIndex
73
+ ).render).to eq(index: %w[first], type: %w[one two])
74
+ end
75
+ specify do
76
+ expect(described_class.new(
77
+ indices: :whatever
78
+ ).render).to eq(index: %w[whatever])
79
+ end
80
+ specify do
81
+ expect(described_class.new(
82
+ types: FirstIndex::One
83
+ ).render).to eq(index: %w[first], type: %w[one])
84
+ end
85
+ specify do
86
+ expect(described_class.new(
87
+ types: :whatever
88
+ ).render).to eq({})
89
+ end
90
+ specify do
91
+ expect(described_class.new(
92
+ indices: FirstIndex, types: SecondIndex::Three
93
+ ).render).to eq(index: %w[first second], type: %w[one three two])
94
+ end
95
+ specify do
96
+ expect(described_class.new(
97
+ indices: FirstIndex, types: :one
98
+ ).render).to eq(index: %w[first], type: %w[one])
99
+ end
100
+ specify do
101
+ expect(described_class.new(
102
+ indices: FirstIndex, types: :whatever
103
+ ).render).to eq(index: %w[first], type: %w[one two])
104
+ end
105
+ specify do
106
+ expect(described_class.new(
107
+ indices: FirstIndex, types: %i[one whatever]
108
+ ).render).to eq(index: %w[first], type: %w[one])
109
+ end
110
+ specify do
111
+ expect(described_class.new(
112
+ indices: :whatever, types: SecondIndex::Three
113
+ ).render).to eq(index: %w[second whatever], type: %w[three])
114
+ end
115
+ specify do
116
+ expect(described_class.new(
117
+ indices: :whatever, types: [SecondIndex::Three, :whatever]
118
+ ).render).to eq(index: %w[second whatever], type: %w[three whatever])
119
+ end
120
+ specify do
121
+ expect(described_class.new(
122
+ indices: [FirstIndex, :whatever], types: FirstIndex::One
123
+ ).render).to eq(index: %w[first whatever], type: %w[one])
124
+ end
125
+ specify do
126
+ expect(described_class.new(
127
+ indices: FirstIndex, types: [FirstIndex::One, :whatever]
128
+ ).render).to eq(index: %w[first], type: %w[one])
129
+ end
130
+ specify do
131
+ expect(described_class.new(
132
+ indices: FirstIndex, types: [SecondIndex::Three, :whatever]
133
+ ).render).to eq(index: %w[first second], type: %w[one three two])
134
+ end
135
+ specify do
136
+ expect(described_class.new(
137
+ indices: [FirstIndex, :whatever], types: [FirstIndex::One, :whatever]
138
+ ).render).to eq(index: %w[first whatever], type: %w[one whatever])
139
+ end
140
+ specify do
141
+ expect(described_class.new(
142
+ indices: [FirstIndex, :whatever], types: [SecondIndex::Three, FirstIndex::One]
143
+ ).render).to eq(index: %w[first second whatever], type: %w[one three])
144
+ end
145
+ end
146
+
147
+ describe '#==' do
148
+ specify { expect(described_class.new).to eq(described_class.new) }
149
+ specify do
150
+ expect(described_class.new(indices: SecondIndex, types: [SecondIndex::Three, :whatever]))
151
+ .to eq(described_class.new(indices: SecondIndex, types: :whatever))
152
+ end
153
+ specify do
154
+ expect(described_class.new(indices: :first, types: %w[one two]))
155
+ .to eq(described_class.new(indices: FirstIndex))
156
+ end
157
+ specify do
158
+ expect(described_class.new(indices: FirstIndex, types: SecondIndex::Three))
159
+ .not_to eq(described_class.new(indices: FirstIndex))
160
+ end
161
+ end
162
+
163
+ describe '#indices' do
164
+ specify do
165
+ expect(described_class.new(
166
+ indices: [FirstIndex, :whatever],
167
+ types: [SecondIndex::Three, :whatever]
168
+ ).indices).to contain_exactly(FirstIndex, SecondIndex)
169
+ end
170
+ end
171
+
172
+ describe '#types' do
173
+ specify do
174
+ expect(described_class.new(
175
+ indices: [FirstIndex, :whatever],
176
+ types: [SecondIndex::Three, :whatever]
177
+ ).types).to contain_exactly(
178
+ FirstIndex::One, FirstIndex::Two, SecondIndex::Three
179
+ )
180
+ end
181
+
182
+ specify do
183
+ expect(described_class.new(
184
+ indices: [FirstIndex, :whatever],
185
+ types: [FirstIndex::One, SecondIndex::Three, :whatever]
186
+ ).types).to contain_exactly(
187
+ FirstIndex::One, SecondIndex::Three
188
+ )
189
+ end
190
+ end
191
+ end
@@ -72,18 +72,20 @@ describe Chewy::Search::Parameters do
72
72
  describe '#merge!' do
73
73
  let(:first) { described_class.new(offset: 10, order: 'foo') }
74
74
  let(:second) { described_class.new(limit: 20, offset: 20, order: 'bar') }
75
+ let(:first_clone) { first.clone }
76
+ let(:second_clone) { second.clone }
75
77
 
76
78
  specify do
77
79
  expect { first.merge!(second) }.to change { first.clone }
78
80
  .to(described_class.new(limit: 20, offset: 20, order: %w[foo bar]))
79
81
  end
80
- specify { expect { first.merge!(second) }.not_to change { second.clone } }
82
+ specify { expect { first.merge!(second) }.not_to change { second_clone } }
81
83
 
82
84
  specify do
83
85
  expect { second.merge!(first) }.to change { second.clone }
84
86
  .to(described_class.new(limit: 20, offset: 10, order: %w[bar foo]))
85
87
  end
86
- specify { expect { second.merge!(first) }.not_to change { first.clone } }
88
+ specify { expect { second.merge!(first) }.not_to change { first_clone } }
87
89
 
88
90
  context 'spawns new storages for the merge' do
89
91
  let(:names) { %i[limit offset order] }
@@ -100,7 +102,22 @@ describe Chewy::Search::Parameters do
100
102
  subject { described_class.new(offset: 10, order: 'foo') }
101
103
 
102
104
  specify { expect(subject.render).to eq(body: {from: 10, sort: ['foo']}) }
103
- specify { expect(described_class.new.render).to eq({}) }
105
+ specify { expect(described_class.new.render).to eq(body: {}) }
106
+
107
+ context do
108
+ subject { described_class.new(request_cache: true) }
109
+ specify { expect(subject.render).to eq(body: {}, request_cache: true) }
110
+ end
111
+
112
+ context do
113
+ subject { described_class.new(search_type: 'query_then_fetch') }
114
+ specify { expect(subject.render).to eq(body: {}, search_type: 'query_then_fetch') }
115
+ end
116
+
117
+ context do
118
+ subject { described_class.new(allow_partial_search_results: true) }
119
+ specify { expect(subject.render).to eq(body: {}, allow_partial_search_results: true) }
120
+ end
104
121
 
105
122
  context do
106
123
  subject { described_class.new(query: {foo: 'bar'}, filter: {moo: 'baz'}) }
@@ -57,11 +57,11 @@ describe Chewy::Search::Request do
57
57
  describe '#inspect' do
58
58
  specify do
59
59
  expect(described_class.new(ProductsIndex).inspect)
60
- .to eq('<Chewy::Search::Request {:index=>["products"], :type=>["product", "city", "country"], :body=>{}}>')
60
+ .to eq('<Chewy::Search::Request {:index=>["products"], :type=>["city", "country", "product"], :body=>{}}>')
61
61
  end
62
62
  specify do
63
63
  expect(ProductsIndex.limit(10).inspect)
64
- .to eq('<ProductsIndex::Query {:index=>["products"], :type=>["product", "city", "country"], :body=>{:size=>10}}>')
64
+ .to eq('<ProductsIndex::Query {:index=>["products"], :type=>["city", "country", "product"], :body=>{:size=>10}}>')
65
65
  end
66
66
  end
67
67
 
@@ -151,13 +151,20 @@ describe Chewy::Search::Request do
151
151
  end
152
152
 
153
153
  describe '#request_cache' do
154
- specify { expect(subject.request_cache(true).render[:body]).to include(request_cache: true) }
155
- specify { expect(subject.request_cache(true).request_cache(false).render[:body]).to include(request_cache: false) }
156
- specify { expect(subject.request_cache(true).request_cache(nil).render[:body]).to be_blank }
154
+ specify { expect(subject.request_cache(true).render).to include(request_cache: true) }
155
+ specify { expect(subject.request_cache(true).request_cache(false).render).to include(request_cache: false) }
156
+ specify { expect(subject.request_cache(true).request_cache(nil).render[:request_cache]).to be_blank }
157
157
  specify { expect { subject.request_cache(true) }.not_to change { subject.render } }
158
158
  end
159
159
 
160
- %i[search_type preference timeout].each do |name|
160
+ describe '#search_type' do
161
+ specify { expect(subject.search_type('foo').render).to include(search_type: 'foo') }
162
+ specify { expect(subject.search_type('foo').search_type('bar').render).to include(search_type: 'bar') }
163
+ specify { expect(subject.search_type('foo').search_type(nil).render[:search_type]).to be_blank }
164
+ specify { expect { subject.search_type('foo') }.not_to change { subject.render } }
165
+ end
166
+
167
+ %i[preference timeout].each do |name|
161
168
  describe "##{name}" do
162
169
  specify { expect(subject.send(name, :foo).render[:body]).to include(name => 'foo') }
163
170
  specify { expect(subject.send(name, :foo).send(name, :bar).render[:body]).to include(name => 'bar') }
@@ -218,8 +225,17 @@ describe Chewy::Search::Request do
218
225
  specify { expect { subject.docvalue_fields(:foo) }.not_to change { subject.render } }
219
226
  end
220
227
 
228
+ describe '#indices' do
229
+ specify { expect(described_class.new(:products).render[:index]).to eq(%w[products]) }
230
+ specify { expect(subject.indices(:cities).render[:index]).to eq(%w[cities products]) }
231
+ specify { expect(subject.indices(CitiesIndex, :whatever).render[:index]).to eq(%w[cities products whatever]) }
232
+ specify { expect(subject.indices([CitiesIndex, :products]).render[:index]).to eq(%w[cities products]) }
233
+ specify { expect { subject.indices(:cities) }.not_to change { subject.render } }
234
+ end
235
+
221
236
  describe '#types' do
222
237
  specify { expect(subject.types(:product).render[:type]).to contain_exactly('product') }
238
+ specify { expect(described_class.new(ProductsIndex::City).types(ProductsIndex::Country).render[:type]).to match_array(%w[city country]) }
223
239
  specify { expect(subject.types(%i[product city]).types(nil).render[:type]).to match_array(%w[product city]) }
224
240
  specify { expect(subject.types(:product).types(:product, :city, :something).render[:type]).to match_array(%w[product city]) }
225
241
  specify { expect(subject.types(nil).render[:body]).to be_blank }
@@ -415,7 +431,7 @@ describe Chewy::Search::Request do
415
431
  expect(outer_payload).to eq(
416
432
  index: ProductsIndex,
417
433
  indexes: [ProductsIndex],
418
- request: {index: ['products'], type: %w[product city country], body: {query: {match: {name: 'name3'}}}},
434
+ request: {index: ['products'], type: %w[city country product], body: {query: {match: {name: 'name3'}}}},
419
435
  type: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country],
420
436
  types: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country]
421
437
  )
@@ -644,7 +660,7 @@ describe Chewy::Search::Request do
644
660
  expect(outer_payload).to eq(
645
661
  index: ProductsIndex,
646
662
  indexes: [ProductsIndex],
647
- request: {index: ['products'], type: %w[product city country], body: {query: {match: {name: 'name3'}}}, refresh: true},
663
+ request: {index: ['products'], type: %w[city country product], body: {query: {match: {name: 'name3'}}}, refresh: true},
648
664
  type: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country],
649
665
  types: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country]
650
666
  )
@@ -659,7 +675,7 @@ describe Chewy::Search::Request do
659
675
  expect(outer_payload).to eq(
660
676
  index: ProductsIndex,
661
677
  indexes: [ProductsIndex],
662
- request: {index: ['products'], type: %w[product city country], body: {query: {match: {name: 'name3'}}}, refresh: false},
678
+ request: {index: ['products'], type: %w[city country product], body: {query: {match: {name: 'name3'}}}, refresh: false},
663
679
  type: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country],
664
680
  types: [ProductsIndex::Product, ProductsIndex::City, ProductsIndex::Country]
665
681
  )
@@ -72,7 +72,10 @@ describe Chewy::Search::Response, :orm do
72
72
  Chewy::Search::Request.new(PlacesIndex)
73
73
  .query(script: {script: {inline: 'sleep(100); true', lang: 'groovy'}})
74
74
  end
75
- specify { expect(subject.took).to be > 100 }
75
+ specify do
76
+ pending
77
+ expect(subject.took).to be > 100
78
+ end
76
79
  end
77
80
  end
78
81
 
@@ -84,7 +87,10 @@ describe Chewy::Search::Response, :orm do
84
87
  Chewy::Search::Request.new(PlacesIndex)
85
88
  .query(script: {script: {inline: 'sleep(100); true', lang: 'groovy'}}).timeout('10ms')
86
89
  end
87
- specify { expect(subject.timed_out?).to eq(true) }
90
+ specify do
91
+ pending
92
+ expect(subject.timed_out?).to eq(true)
93
+ end
88
94
  end
89
95
  end
90
96
 
@@ -71,12 +71,12 @@ describe Chewy::Search do
71
71
  filter { match name: "Name#{index}" }
72
72
  end
73
73
 
74
- field :name, KEYWORD_FIELD
74
+ field :name, **KEYWORD_FIELD
75
75
  field :rating, type: :integer
76
76
  end
77
77
 
78
78
  define_type Country do
79
- field :name, KEYWORD_FIELD
79
+ field :name, **KEYWORD_FIELD
80
80
  field :rating, type: :integer
81
81
  end
82
82
  end
@@ -2,7 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  if defined?(::ActiveJob)
4
4
  describe Chewy::Strategy::ActiveJob do
5
- around { |example| Chewy.strategy(:bypass) { example.run } }
5
+ around do |example|
6
+ active_job_settings = Chewy.settings[:active_job]
7
+ Chewy.settings[:active_job] = {queue: 'low'}
8
+ Chewy.strategy(:bypass) { example.run }
9
+ Chewy.settings[:active_job] = active_job_settings
10
+ end
6
11
  before(:all) do
7
12
  ::ActiveJob::Base.logger = Chewy.logger
8
13
  end
@@ -36,7 +41,15 @@ if defined?(::ActiveJob)
36
41
  end
37
42
  enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
38
43
  expect(enqueued_job[:job]).to eq(Chewy::Strategy::ActiveJob::Worker)
39
- expect(enqueued_job[:queue]).to eq('chewy')
44
+ expect(enqueued_job[:queue]).to eq('low')
45
+ end
46
+
47
+ specify do
48
+ Chewy.strategy(:active_job) do
49
+ [city, other_city].map(&:save!)
50
+ end
51
+ enqueued_job = ::ActiveJob::Base.queue_adapter.enqueued_jobs.first
52
+ expect(enqueued_job[:queue]).to eq('low')
40
53
  end
41
54
 
42
55
  specify do
@@ -4,7 +4,12 @@ if defined?(::Shoryuken)
4
4
  require 'aws-sdk-sqs'
5
5
 
6
6
  describe Chewy::Strategy::Shoryuken do
7
- around { |example| Chewy.strategy(:bypass) { example.run } }
7
+ around do |example|
8
+ shoryuken_settings = Chewy.settings[:shoryuken]
9
+ Chewy.settings[:shoryuken] = {queue: 'low'}
10
+ Chewy.strategy(:bypass) { example.run }
11
+ Chewy.settings[:shoryuken] = shoryuken_settings
12
+ end
8
13
  before { ::Shoryuken.groups.clear }
9
14
  before do
10
15
  stub_model(:city) do
@@ -31,7 +36,6 @@ if defined?(::Shoryuken)
31
36
  end
32
37
 
33
38
  specify do
34
- Chewy.settings[:shoryuken] = {queue: 'low'}
35
39
  expect(Chewy::Strategy::Shoryuken::Worker).to receive(:perform_async)
36
40
  .with(hash_including(type: 'CitiesIndex::City', ids: [city.id, other_city.id]), hash_including(queue: 'low'))
37
41
  Chewy.strategy(:shoryuken) do
@@ -4,7 +4,12 @@ if defined?(::Sidekiq)
4
4
  require 'sidekiq/testing'
5
5
 
6
6
  describe Chewy::Strategy::Sidekiq do
7
- around { |example| Chewy.strategy(:bypass) { example.run } }
7
+ around do |example|
8
+ sidekiq_settings = Chewy.settings[:sidekiq]
9
+ Chewy.settings[:sidekiq] = {queue: 'low'}
10
+ Chewy.strategy(:bypass) { example.run }
11
+ Chewy.settings[:sidekiq] = sidekiq_settings
12
+ end
8
13
  before { ::Sidekiq::Worker.clear_all }
9
14
  before do
10
15
  stub_model(:city) do
@@ -25,7 +30,6 @@ if defined?(::Sidekiq)
25
30
  end
26
31
 
27
32
  specify do
28
- Chewy.settings[:sidekiq] = {queue: 'low'}
29
33
  expect(::Sidekiq::Client).to receive(:push).with(hash_including('queue' => 'low')).and_call_original
30
34
  ::Sidekiq::Testing.inline! do
31
35
  expect { [city, other_city].map(&:save!) }
@@ -454,9 +454,9 @@ describe Chewy::Type::Adapter::ActiveRecord, :active_record do
454
454
  specify do
455
455
  expect(subject.import_fields(fields: [:updated_at], typecast: false))
456
456
  .to match([contain_exactly(
457
- [1, match(/#{Time.now.strftime('%Y-%m-%d')}/)],
458
- [2, match(/#{Time.now.strftime('%Y-%m-%d')}/)],
459
- [3, match(/#{Time.now.strftime('%Y-%m-%d')}/)]
457
+ [1, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)],
458
+ [2, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)],
459
+ [3, match(/#{Time.now.utc.strftime('%Y-%m-%d')}/)]
460
460
  )])
461
461
  end
462
462
  end
@@ -117,7 +117,7 @@ describe Chewy::Type::Import::BulkBuilder do
117
117
  context 'updating parent' do
118
118
  before do
119
119
  PlacesIndex::City.import(city)
120
- city.update_attributes(country_id: another_country.id)
120
+ city.update(country_id: another_country.id)
121
121
  end
122
122
  let(:index) { [city] }
123
123