chewy 0.10.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +240 -0
  3. data/.rubocop.yml +25 -25
  4. data/Appraisals +12 -10
  5. data/CHANGELOG.md +252 -263
  6. data/Gemfile +5 -1
  7. data/LICENSE.txt +1 -1
  8. data/README.md +142 -78
  9. data/chewy.gemspec +10 -12
  10. data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
  11. data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
  12. data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
  13. data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
  14. data/gemfiles/sequel.4.45.gemfile +2 -2
  15. data/lib/chewy.rb +2 -1
  16. data/lib/chewy/backports/duplicable.rb +1 -1
  17. data/lib/chewy/config.rb +10 -39
  18. data/lib/chewy/fields/base.rb +40 -28
  19. data/lib/chewy/fields/root.rb +18 -11
  20. data/lib/chewy/index.rb +3 -1
  21. data/lib/chewy/index/actions.rb +27 -15
  22. data/lib/chewy/index/settings.rb +2 -0
  23. data/lib/chewy/index/specification.rb +12 -10
  24. data/lib/chewy/minitest/helpers.rb +6 -6
  25. data/lib/chewy/minitest/search_index_receiver.rb +17 -17
  26. data/lib/chewy/multi_search.rb +62 -0
  27. data/lib/chewy/railtie.rb +4 -4
  28. data/lib/chewy/rake_helper.rb +5 -5
  29. data/lib/chewy/rspec/update_index.rb +3 -5
  30. data/lib/chewy/search.rb +4 -11
  31. data/lib/chewy/search/loader.rb +1 -1
  32. data/lib/chewy/search/pagination/will_paginate.rb +4 -2
  33. data/lib/chewy/search/parameters.rb +24 -6
  34. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  35. data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
  36. data/lib/chewy/search/parameters/indices.rb +123 -0
  37. data/lib/chewy/search/parameters/none.rb +1 -3
  38. data/lib/chewy/search/request.rb +100 -74
  39. data/lib/chewy/search/scrolling.rb +7 -6
  40. data/lib/chewy/stash.rb +30 -21
  41. data/lib/chewy/strategy/active_job.rb +1 -1
  42. data/lib/chewy/strategy/atomic.rb +1 -1
  43. data/lib/chewy/strategy/sidekiq.rb +1 -1
  44. data/lib/chewy/type.rb +5 -2
  45. data/lib/chewy/type/adapter/active_record.rb +1 -1
  46. data/lib/chewy/type/adapter/base.rb +9 -9
  47. data/lib/chewy/type/adapter/mongoid.rb +2 -4
  48. data/lib/chewy/type/adapter/orm.rb +7 -4
  49. data/lib/chewy/type/adapter/sequel.rb +5 -7
  50. data/lib/chewy/type/crutch.rb +1 -1
  51. data/lib/chewy/type/import.rb +13 -11
  52. data/lib/chewy/type/import/bulk_builder.rb +1 -1
  53. data/lib/chewy/type/import/bulk_request.rb +4 -2
  54. data/lib/chewy/type/import/journal_builder.rb +3 -3
  55. data/lib/chewy/type/import/routine.rb +3 -3
  56. data/lib/chewy/type/mapping.rb +42 -36
  57. data/lib/chewy/type/observe.rb +16 -12
  58. data/lib/chewy/type/syncer.rb +15 -14
  59. data/lib/chewy/type/witchcraft.rb +11 -7
  60. data/lib/chewy/type/wrapper.rb +14 -4
  61. data/lib/chewy/version.rb +1 -1
  62. data/lib/sequel/plugins/chewy_observe.rb +4 -19
  63. data/migration_guide.md +18 -0
  64. data/spec/chewy/config_spec.rb +16 -21
  65. data/spec/chewy/fields/base_spec.rb +70 -70
  66. data/spec/chewy/fields/root_spec.rb +56 -9
  67. data/spec/chewy/index/actions_spec.rb +63 -7
  68. data/spec/chewy/index/specification_spec.rb +25 -16
  69. data/spec/chewy/index_spec.rb +75 -45
  70. data/spec/chewy/journal_spec.rb +33 -29
  71. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  72. data/spec/chewy/multi_search_spec.rb +85 -0
  73. data/spec/chewy/rake_helper_spec.rb +123 -95
  74. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  75. data/spec/chewy/runtime_spec.rb +2 -2
  76. data/spec/chewy/search/pagination/kaminari_spec.rb +7 -3
  77. data/spec/chewy/search/pagination/will_paginate_spec.rb +9 -3
  78. data/spec/chewy/search/parameters/indices_spec.rb +190 -0
  79. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  80. data/spec/chewy/search/parameters_spec.rb +21 -4
  81. data/spec/chewy/search/request_spec.rb +101 -70
  82. data/spec/chewy/search/response_spec.rb +27 -17
  83. data/spec/chewy/search/scrolling_spec.rb +25 -16
  84. data/spec/chewy/search_spec.rb +49 -35
  85. data/spec/chewy/stash_spec.rb +15 -13
  86. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  87. data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
  88. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  89. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  90. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  91. data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
  92. data/spec/chewy/type/import_spec.rb +6 -0
  93. data/spec/chewy/type/mapping_spec.rb +51 -18
  94. data/spec/chewy/type/observe_spec.rb +4 -4
  95. data/spec/chewy/type/witchcraft_spec.rb +31 -0
  96. data/spec/chewy/type/wrapper_spec.rb +3 -1
  97. data/spec/chewy_spec.rb +0 -7
  98. data/spec/spec_helper.rb +5 -1
  99. data/spec/support/active_record.rb +20 -0
  100. metadata +46 -116
  101. data/.travis.yml +0 -53
  102. data/LEGACY_DSL.md +0 -497
  103. data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
  104. data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
  105. data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
  106. data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
  107. data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
  108. data/lib/chewy/query.rb +0 -1098
  109. data/lib/chewy/query/compose.rb +0 -68
  110. data/lib/chewy/query/criteria.rb +0 -191
  111. data/lib/chewy/query/filters.rb +0 -227
  112. data/lib/chewy/query/loading.rb +0 -111
  113. data/lib/chewy/query/nodes/and.rb +0 -25
  114. data/lib/chewy/query/nodes/base.rb +0 -17
  115. data/lib/chewy/query/nodes/bool.rb +0 -34
  116. data/lib/chewy/query/nodes/equal.rb +0 -34
  117. data/lib/chewy/query/nodes/exists.rb +0 -20
  118. data/lib/chewy/query/nodes/expr.rb +0 -28
  119. data/lib/chewy/query/nodes/field.rb +0 -110
  120. data/lib/chewy/query/nodes/has_child.rb +0 -15
  121. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  122. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  123. data/lib/chewy/query/nodes/match_all.rb +0 -11
  124. data/lib/chewy/query/nodes/missing.rb +0 -20
  125. data/lib/chewy/query/nodes/not.rb +0 -25
  126. data/lib/chewy/query/nodes/or.rb +0 -25
  127. data/lib/chewy/query/nodes/prefix.rb +0 -19
  128. data/lib/chewy/query/nodes/query.rb +0 -20
  129. data/lib/chewy/query/nodes/range.rb +0 -63
  130. data/lib/chewy/query/nodes/raw.rb +0 -15
  131. data/lib/chewy/query/nodes/regexp.rb +0 -35
  132. data/lib/chewy/query/nodes/script.rb +0 -20
  133. data/lib/chewy/query/pagination.rb +0 -25
  134. data/spec/chewy/query/criteria_spec.rb +0 -700
  135. data/spec/chewy/query/filters_spec.rb +0 -201
  136. data/spec/chewy/query/loading_spec.rb +0 -124
  137. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  138. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  139. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  140. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  141. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  142. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  143. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  144. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  145. data/spec/chewy/query/nodes/not_spec.rb +0 -13
  146. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  147. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  148. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  149. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  150. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  151. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  152. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  153. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  154. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  155. data/spec/chewy/query/pagination_spec.rb +0 -39
  156. data/spec/chewy/query_spec.rb +0 -636
  157. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
@@ -3,8 +3,10 @@ require 'spec_helper'
3
3
  describe Chewy::Type::Import::JournalBuilder, :orm do
4
4
  before do
5
5
  stub_model(:country)
6
- stub_index 'namespace/places' do
6
+ stub_index 'namespace/cities' do
7
7
  define_type :city
8
+ end
9
+ stub_index 'namespace/countries' do
8
10
  define_type Country
9
11
  end
10
12
  Timecop.freeze(time)
@@ -13,7 +15,7 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
13
15
 
14
16
  let(:time) { Time.parse('2017-07-14 12:00Z') }
15
17
 
16
- let(:type) { Namespace::PlacesIndex::City }
18
+ let(:type) { Namespace::CitiesIndex::City }
17
19
  let(:index) { [] }
18
20
  let(:delete) { [] }
19
21
  subject { described_class.new(type, index: index, delete: delete) }
@@ -26,13 +28,13 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
26
28
  specify do
27
29
  expect(subject.bulk_body).to eq([{
28
30
  index: {
29
- _index: 'chewy_stash',
31
+ _index: 'chewy_journal',
30
32
  _type: 'journal',
31
33
  data: {
32
- 'index_name' => 'namespace/places',
34
+ 'index_name' => 'namespace/cities',
33
35
  'type_name' => 'city',
34
36
  'action' => 'index',
35
- 'references' => ['{"id":1,"name":"City"}'],
37
+ 'references' => [Base64.encode64('{"id":1,"name":"City"}')],
36
38
  'created_at' => time.as_json
37
39
  }
38
40
  }
@@ -45,13 +47,13 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
45
47
  specify do
46
48
  expect(subject.bulk_body).to eq([{
47
49
  index: {
48
- _index: 'chewy_stash',
50
+ _index: 'chewy_journal',
49
51
  _type: 'journal',
50
52
  data: {
51
- 'index_name' => 'namespace/places',
53
+ 'index_name' => 'namespace/cities',
52
54
  'type_name' => 'city',
53
55
  'action' => 'delete',
54
- 'references' => ['{"id":1,"name":"City"}'],
56
+ 'references' => [Base64.encode64('{"id":1,"name":"City"}')],
55
57
  'created_at' => time.as_json
56
58
  }
57
59
  }
@@ -60,31 +62,31 @@ describe Chewy::Type::Import::JournalBuilder, :orm do
60
62
  end
61
63
 
62
64
  context do
63
- let(:type) { Namespace::PlacesIndex::Country }
65
+ let(:type) { Namespace::CountriesIndex::Country }
64
66
  let(:index) { [Country.new(id: 1, name: 'City')] }
65
67
  let(:delete) { [Country.new(id: 2, name: 'City')] }
66
68
  specify do
67
69
  expect(subject.bulk_body).to eq([{
68
70
  index: {
69
- _index: 'chewy_stash',
71
+ _index: 'chewy_journal',
70
72
  _type: 'journal',
71
73
  data: {
72
- 'index_name' => 'namespace/places',
74
+ 'index_name' => 'namespace/countries',
73
75
  'type_name' => 'country',
74
76
  'action' => 'index',
75
- 'references' => ['1'],
77
+ 'references' => [Base64.encode64('1')],
76
78
  'created_at' => time.as_json
77
79
  }
78
80
  }
79
81
  }, {
80
82
  index: {
81
- _index: 'chewy_stash',
83
+ _index: 'chewy_journal',
82
84
  _type: 'journal',
83
85
  data: {
84
- 'index_name' => 'namespace/places',
86
+ 'index_name' => 'namespace/countries',
85
87
  'type_name' => 'country',
86
88
  'action' => 'delete',
87
- 'references' => ['2'],
89
+ 'references' => [Base64.encode64('2')],
88
90
  'created_at' => time.as_json
89
91
  }
90
92
  }
@@ -40,6 +40,12 @@ describe Chewy::Type::Import do
40
40
  CitiesIndex::City.import(dummy_city)
41
41
  end
42
42
 
43
+ specify 'lazy without objects' do
44
+ expect(CitiesIndex).not_to receive(:exists?)
45
+ expect(CitiesIndex).not_to receive(:create!)
46
+ CitiesIndex::City.import([])
47
+ end
48
+
43
49
  context 'skip' do
44
50
  before do
45
51
  # To avoid flaky issues when previous specs were run
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Chewy::Type::Mapping do
4
4
  let(:product) { ProductsIndex::Product }
5
- let(:review) { ProductsIndex::Review }
5
+ let(:review) { ReviewsIndex::Review }
6
6
 
7
7
  before do
8
8
  stub_index(:products) do
9
9
  define_type :product do
10
10
  root do
11
11
  field :name, 'surname'
12
- field :title, type: 'string' do
12
+ field :title, type: 'text' do
13
13
  field :subfield1
14
14
  end
15
15
  field 'price', type: 'float' do
@@ -20,6 +20,8 @@ describe Chewy::Type::Mapping do
20
20
  end
21
21
  end
22
22
  end
23
+ end
24
+ stub_index(:reviews) do
23
25
  define_type :review do
24
26
  field :title, :body
25
27
  field :comments do
@@ -37,17 +39,17 @@ describe Chewy::Type::Mapping do
37
39
  before do
38
40
  stub_index(:products) do
39
41
  define_type :product do
40
- field :title, type: 'string' do
42
+ field :title, type: 'text' do
41
43
  field :subfield1
42
44
  end
43
45
  end
44
46
  end
45
47
  end
46
48
 
47
- specify { expect(product.root_object.children.map(&:name)).to eq([:title]) }
48
- specify { expect(product.root_object.children.map(&:parent)).to eq([product.root_object]) }
49
- specify { expect(product.root_object.children[0].children.map(&:name)).to eq([:subfield1]) }
50
- specify { expect(product.root_object.children[0].children.map(&:parent)).to eq([product.root_object.children[0]]) }
49
+ specify { expect(product.root.children.map(&:name)).to eq([:title]) }
50
+ specify { expect(product.root.children.map(&:parent)).to eq([product.root]) }
51
+ specify { expect(product.root.children[0].children.map(&:name)).to eq([:subfield1]) }
52
+ specify { expect(product.root.children[0].children.map(&:parent)).to eq([product.root.children[0]]) }
51
53
 
52
54
  context 'default root options are set' do
53
55
  around do |example|
@@ -67,22 +69,53 @@ describe Chewy::Type::Mapping do
67
69
  end
68
70
 
69
71
  describe '.field' do
70
- specify { expect(product.root_object.children.map(&:name)).to eq(%i[name surname title price]) }
71
- specify { expect(product.root_object.children.map(&:parent)).to eq([product.root_object] * 4) }
72
+ specify { expect(product.root.children.map(&:name)).to eq(%i[name surname title price]) }
73
+ specify { expect(product.root.children.map(&:parent)).to eq([product.root] * 4) }
72
74
 
73
- specify { expect(product.root_object.children[0].children.map(&:name)).to eq([]) }
74
- specify { expect(product.root_object.children[1].children.map(&:name)).to eq([]) }
75
+ specify { expect(product.root.children[0].children.map(&:name)).to eq([]) }
76
+ specify { expect(product.root.children[1].children.map(&:name)).to eq([]) }
75
77
 
76
- specify { expect(product.root_object.children[2].children.map(&:name)).to eq([:subfield1]) }
77
- specify { expect(product.root_object.children[2].children.map(&:parent)).to eq([product.root_object.children[2]]) }
78
+ specify { expect(product.root.children[2].children.map(&:name)).to eq([:subfield1]) }
79
+ specify { expect(product.root.children[2].children.map(&:parent)).to eq([product.root.children[2]]) }
78
80
 
79
- specify { expect(product.root_object.children[3].children.map(&:name)).to eq([:subfield2]) }
80
- specify { expect(product.root_object.children[3].children.map(&:parent)).to eq([product.root_object.children[3]]) }
81
+ specify { expect(product.root.children[3].children.map(&:name)).to eq([:subfield2]) }
82
+ specify { expect(product.root.children[3].children.map(&:parent)).to eq([product.root.children[3]]) }
81
83
  end
82
84
 
83
85
  describe '.mappings_hash' do
84
- specify { expect(Class.new(Chewy::Type).mappings_hash).to eq({}) }
85
- specify { expect(product.mappings_hash).to eq(product.root_object.mappings_hash) }
86
+ specify { expect(product.mappings_hash).to eq(product.root.mappings_hash) }
87
+
88
+ context 'root merging' do
89
+ context do
90
+ before do
91
+ stub_index(:products) do
92
+ define_type :product do
93
+ root _parent: 'project', other_option: 'nothing' do
94
+ field :name do
95
+ field :last_name # will be redefined in the following root flock
96
+ end
97
+ end
98
+ root _parent: 'something_else'
99
+ root other_option: 'option_value' do
100
+ field :identifier
101
+ field :name, type: 'integer'
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ specify do
108
+ expect(product.mappings_hash).to eq(product: {
109
+ properties: {
110
+ name: {type: 'integer'},
111
+ identifier: {type: Chewy.default_field_type}
112
+ },
113
+ other_option: 'option_value',
114
+ _parent: {type: 'something_else'}
115
+ })
116
+ end
117
+ end
118
+ end
86
119
 
87
120
  context 'parent-child relationship' do
88
121
  context do
@@ -110,7 +143,7 @@ describe Chewy::Type::Mapping do
110
143
  end
111
144
  end
112
145
 
113
- specify { expect(product.mappings_hash[:product][:_parent]).to eq(type: 'project') }
146
+ specify { expect(product.mappings_hash[:product][:_parent]).to eq('type' => 'project') }
114
147
  end
115
148
  end
116
149
  end
@@ -75,11 +75,11 @@ describe Chewy::Type::Observe do
75
75
  specify { expect { city.save! }.to update_index('cities#city').and_reindex(city).only }
76
76
  specify { expect { city.save! }.to update_index('countries#country').and_reindex(country1).only }
77
77
 
78
- specify { expect { city.update_attributes!(country: nil) }.to update_index('cities#city').and_reindex(city).only }
79
- specify { expect { city.update_attributes!(country: nil) }.to update_index('countries#country').and_reindex(country1).only }
78
+ specify { expect { city.update!(country: nil) }.to update_index('cities#city').and_reindex(city).only }
79
+ specify { expect { city.update!(country: nil) }.to update_index('countries#country').and_reindex(country1).only }
80
80
 
81
- specify { expect { city.update_attributes!(country: country2) }.to update_index('cities#city').and_reindex(city).only }
82
- specify { expect { city.update_attributes!(country: country2) }.to update_index('countries#country').and_reindex(country1, country2).only }
81
+ specify { expect { city.update!(country: country2) }.to update_index('cities#city').and_reindex(city).only }
82
+ specify { expect { city.update!(country: country2) }.to update_index('countries#country').and_reindex(country1, country2).only }
83
83
  end
84
84
 
85
85
  context do
@@ -181,6 +181,21 @@ describe Chewy::Type::Witchcraft do
181
181
  ]}.as_json)
182
182
  end
183
183
  end
184
+
185
+ context do
186
+ mapping do
187
+ field :not_present do
188
+ field :nothing
189
+ end
190
+ end
191
+
192
+ let(:object) do
193
+ double(not_present: nil)
194
+ end
195
+ specify do
196
+ expect(type.cauldron.brew(object)).to eq({not_present: nil}.as_json)
197
+ end
198
+ end
184
199
  end
185
200
 
186
201
  context 'dynamic fields' do
@@ -212,5 +227,21 @@ describe Chewy::Type::Witchcraft do
212
227
  specify { expect(type.cauldron.brew(object)).to eq(attributes.as_json) }
213
228
  end
214
229
  end
230
+
231
+ context 'symbol value' do
232
+ mapping do
233
+ field :name, value: :last_name
234
+ end
235
+
236
+ context do
237
+ let(:object) { double(last_name: 'Name') }
238
+ specify { expect(type.cauldron.brew(object)).to eq({name: 'Name'}.as_json) }
239
+ end
240
+
241
+ context do
242
+ let(:object) { {'last_name' => 'Name'} }
243
+ specify { expect(type.cauldron.brew(object)).to eq({name: 'Name'}.as_json) }
244
+ end
245
+ end
215
246
  end
216
247
  end
@@ -63,9 +63,11 @@ describe Chewy::Type::Wrapper do
63
63
 
64
64
  it do
65
65
  is_expected.to respond_to(:name_highlight)
66
+ .and respond_to(:name_highlights)
66
67
  .and have_attributes(
67
68
  name: 'Martin',
68
- name_highlight: '<b>Mar</b>tin'
69
+ name_highlight: '<b>Mar</b>tin',
70
+ name_highlights: ['<b>Mar</b>tin']
69
71
  )
70
72
  end
71
73
  end
data/spec/chewy_spec.rb CHANGED
@@ -15,21 +15,18 @@ describe Chewy do
15
15
 
16
16
  stub_index('namespace/autocomplete') do
17
17
  define_type :developer
18
- define_type :company
19
18
  end
20
19
  end
21
20
 
22
21
  specify { expect { described_class.derive_type('some#developers') }.to raise_error(Chewy::UnderivableType, /SomeIndex/) }
23
22
  specify { expect { described_class.derive_type('borogoves#developers') }.to raise_error(Chewy::UnderivableType, /Borogoves/) }
24
23
  specify { expect { described_class.derive_type('developers#borogoves') }.to raise_error(Chewy::UnderivableType, /DevelopersIndex.*borogoves/) }
25
- specify { expect { described_class.derive_type('namespace/autocomplete') }.to raise_error(Chewy::UnderivableType, %r{AutocompleteIndex.*namespace/autocomplete#type_name}) }
26
24
 
27
25
  specify { expect(described_class.derive_type(DevelopersIndex::Developer)).to eq(DevelopersIndex::Developer) }
28
26
  specify { expect(described_class.derive_type('developers_index')).to eq(DevelopersIndex::Developer) }
29
27
  specify { expect(described_class.derive_type('developers')).to eq(DevelopersIndex::Developer) }
30
28
  specify { expect(described_class.derive_type('developers#developer')).to eq(DevelopersIndex::Developer) }
31
29
  specify { expect(described_class.derive_type('namespace/autocomplete#developer')).to eq(Namespace::AutocompleteIndex::Developer) }
32
- specify { expect(described_class.derive_type('namespace/autocomplete#company')).to eq(Namespace::AutocompleteIndex::Company) }
33
30
  end
34
31
 
35
32
  describe '.derive_types' do
@@ -42,7 +39,6 @@ describe Chewy do
42
39
 
43
40
  stub_index('namespace/autocomplete') do
44
41
  define_type :developer
45
- define_type :company
46
42
  end
47
43
  end
48
44
 
@@ -58,7 +54,6 @@ describe Chewy do
58
54
  specify { expect(described_class.derive_types('developers#developer')).to eq([DevelopersIndex::Developer]) }
59
55
  specify { expect(described_class.derive_types('namespace/autocomplete')).to match_array(Namespace::AutocompleteIndex.types) }
60
56
  specify { expect(described_class.derive_types('namespace/autocomplete#developer')).to eq([Namespace::AutocompleteIndex::Developer]) }
61
- specify { expect(described_class.derive_types('namespace/autocomplete#company')).to eq([Namespace::AutocompleteIndex::Company]) }
62
57
  end
63
58
 
64
59
  describe '.create_type' do
@@ -130,7 +125,6 @@ describe Chewy do
130
125
  stub_index(:admins).create!
131
126
  allow(Chewy).to receive_messages(configuration: Chewy.configuration.merge(prefix: 'prefix2'))
132
127
  stub_index(:developers).create!
133
- stub_index(:companies).create!
134
128
 
135
129
  Chewy.massacre
136
130
 
@@ -139,7 +133,6 @@ describe Chewy do
139
133
 
140
134
  specify { expect(AdminsIndex.exists?).to eq(true) }
141
135
  specify { expect(DevelopersIndex.exists?).to eq(false) }
142
- specify { expect(CompaniesIndex.exists?).to eq(false) }
143
136
  end
144
137
 
145
138
  describe '.client' do
data/spec/spec_helper.rb CHANGED
@@ -21,14 +21,18 @@ require 'support/class_helpers'
21
21
 
22
22
  require 'chewy/rspec'
23
23
 
24
+ host = ENV['ES_HOST'] || 'localhost'
25
+ port = ENV['ES_PORT'] || 9250
26
+
24
27
  Chewy.settings = {
25
- host: 'localhost:9250',
28
+ host: "#{host}:#{port}",
26
29
  wait_for_status: 'green',
27
30
  index: {
28
31
  number_of_shards: 1,
29
32
  number_of_replicas: 0
30
33
  }
31
34
  }
35
+
32
36
  # Chewy.transport_logger = Logger.new(STDERR)
33
37
 
34
38
  RSpec.configure do |config|
@@ -29,6 +29,26 @@ module ActiveRecordClassHelpers
29
29
  :active_record
30
30
  end
31
31
 
32
+ def expects_db_queries(&block)
33
+ have_queries = false
34
+ ActiveSupport::Notifications.subscribed(
35
+ ->(*_) { have_queries = true },
36
+ 'sql.active_record',
37
+ &block
38
+ )
39
+ raise 'Expected some db queries, but none were made' unless have_queries
40
+ end
41
+
42
+ def expects_no_query(&block)
43
+ queries = []
44
+ ActiveSupport::Notifications.subscribed(
45
+ ->(*args) { queries << args[4][:sql] },
46
+ 'sql.active_record',
47
+ &block
48
+ )
49
+ raise "Expected no DB queries, but the following ones were made: #{queries.join(', ')}" if queries.present?
50
+ end
51
+
32
52
  def stub_model(name, superclass = nil, &block)
33
53
  stub_class(name, superclass || ActiveRecord::Base, &block)
34
54
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chewy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Toptal, LLC
7
8
  - pyromaniac
8
- autorequire:
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
12
+ date: 2021-02-11 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: rake
15
+ name: appraisal
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
@@ -25,7 +26,7 @@ dependencies:
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
- name: appraisal
29
+ name: database_cleaner
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - ">="
@@ -39,7 +40,7 @@ dependencies:
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
- name: rspec
43
+ name: elasticsearch-extensions
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - ">="
@@ -53,7 +54,7 @@ dependencies:
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  - !ruby/object:Gem::Dependency
56
- name: rspec-its
57
+ name: rake
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - ">="
@@ -67,7 +68,7 @@ dependencies:
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  - !ruby/object:Gem::Dependency
70
- name: rspec-collection_matchers
71
+ name: resque_spec
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
74
  - - ">="
@@ -81,21 +82,21 @@ dependencies:
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  - !ruby/object:Gem::Dependency
84
- name: sqlite3
85
+ name: rspec
85
86
  requirement: !ruby/object:Gem::Requirement
86
87
  requirements:
87
88
  - - ">="
88
89
  - !ruby/object:Gem::Version
89
- version: '0'
90
+ version: 3.7.0
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - ">="
95
96
  - !ruby/object:Gem::Version
96
- version: '0'
97
+ version: 3.7.0
97
98
  - !ruby/object:Gem::Dependency
98
- name: database_cleaner
99
+ name: rspec-collection_matchers
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
102
  - - ">="
@@ -109,7 +110,7 @@ dependencies:
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  - !ruby/object:Gem::Dependency
112
- name: elasticsearch-extensions
113
+ name: rspec-its
113
114
  requirement: !ruby/object:Gem::Requirement
114
115
  requirements:
115
116
  - - ">="
@@ -123,21 +124,21 @@ dependencies:
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  - !ruby/object:Gem::Dependency
126
- name: resque_spec
127
+ name: rubocop
127
128
  requirement: !ruby/object:Gem::Requirement
128
129
  requirements:
129
- - - ">="
130
+ - - '='
130
131
  - !ruby/object:Gem::Version
131
- version: '0'
132
+ version: 0.52.1
132
133
  type: :development
133
134
  prerelease: false
134
135
  version_requirements: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - ">="
137
+ - - '='
137
138
  - !ruby/object:Gem::Version
138
- version: '0'
139
+ version: 0.52.1
139
140
  - !ruby/object:Gem::Dependency
140
- name: timecop
141
+ name: sqlite3
141
142
  requirement: !ruby/object:Gem::Requirement
142
143
  requirements:
143
144
  - - ">="
@@ -151,19 +152,19 @@ dependencies:
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  - !ruby/object:Gem::Dependency
154
- name: rubocop
155
+ name: timecop
155
156
  requirement: !ruby/object:Gem::Requirement
156
157
  requirements:
157
- - - '='
158
+ - - ">="
158
159
  - !ruby/object:Gem::Version
159
- version: 0.48.1
160
+ version: '0'
160
161
  type: :development
161
162
  prerelease: false
162
163
  version_requirements: !ruby/object:Gem::Requirement
163
164
  requirements:
164
- - - '='
165
+ - - ">="
165
166
  - !ruby/object:Gem::Version
166
- version: 0.48.1
167
+ version: '0'
167
168
  - !ruby/object:Gem::Dependency
168
169
  name: method_source
169
170
  requirement: !ruby/object:Gem::Requirement
@@ -198,28 +199,28 @@ dependencies:
198
199
  requirements:
199
200
  - - ">="
200
201
  - !ruby/object:Gem::Version
201
- version: '4.0'
202
+ version: '5.2'
202
203
  type: :runtime
203
204
  prerelease: false
204
205
  version_requirements: !ruby/object:Gem::Requirement
205
206
  requirements:
206
207
  - - ">="
207
208
  - !ruby/object:Gem::Version
208
- version: '4.0'
209
+ version: '5.2'
209
210
  - !ruby/object:Gem::Dependency
210
211
  name: elasticsearch
211
212
  requirement: !ruby/object:Gem::Requirement
212
213
  requirements:
213
214
  - - ">="
214
215
  - !ruby/object:Gem::Version
215
- version: 2.0.0
216
+ version: 6.3.0
216
217
  type: :runtime
217
218
  prerelease: false
218
219
  version_requirements: !ruby/object:Gem::Requirement
219
220
  requirements:
220
221
  - - ">="
221
222
  - !ruby/object:Gem::Version
222
- version: 2.0.0
223
+ version: 6.3.0
223
224
  - !ruby/object:Gem::Dependency
224
225
  name: elasticsearch-dsl
225
226
  requirement: !ruby/object:Gem::Requirement
@@ -237,35 +238,31 @@ dependencies:
237
238
  description: Chewy provides functionality for Elasticsearch index handling, documents
238
239
  import mappings and chainable query DSL
239
240
  email:
241
+ - open-source@toptal.com
240
242
  - kinwizard@gmail.com
241
243
  executables: []
242
244
  extensions: []
243
245
  extra_rdoc_files: []
244
246
  files:
247
+ - ".circleci/config.yml"
245
248
  - ".gitignore"
246
249
  - ".rspec"
247
250
  - ".rubocop.yml"
248
251
  - ".rubocop_todo.yml"
249
- - ".travis.yml"
250
252
  - ".yardopts"
251
253
  - Appraisals
252
254
  - CHANGELOG.md
253
255
  - Gemfile
254
256
  - Guardfile
255
- - LEGACY_DSL.md
256
257
  - LICENSE.txt
257
258
  - README.md
258
259
  - Rakefile
259
260
  - chewy.gemspec
260
261
  - filters
261
- - gemfiles/rails.4.0.activerecord.gemfile
262
- - gemfiles/rails.4.1.activerecord.gemfile
263
- - gemfiles/rails.4.2.activerecord.gemfile
264
- - gemfiles/rails.4.2.mongoid.5.1.gemfile
265
- - gemfiles/rails.5.0.activerecord.gemfile
266
- - gemfiles/rails.5.0.mongoid.6.0.gemfile
267
- - gemfiles/rails.5.1.activerecord.gemfile
268
- - gemfiles/rails.5.1.mongoid.6.1.gemfile
262
+ - gemfiles/rails.5.2.activerecord.gemfile
263
+ - gemfiles/rails.5.2.mongoid.6.4.gemfile
264
+ - gemfiles/rails.6.0.activerecord.gemfile
265
+ - gemfiles/rails.6.1.activerecord.gemfile
269
266
  - gemfiles/sequel.4.45.gemfile
270
267
  - lib/chewy.rb
271
268
  - lib/chewy/backports/deep_dup.rb
@@ -284,32 +281,7 @@ files:
284
281
  - lib/chewy/minitest.rb
285
282
  - lib/chewy/minitest/helpers.rb
286
283
  - lib/chewy/minitest/search_index_receiver.rb
287
- - lib/chewy/query.rb
288
- - lib/chewy/query/compose.rb
289
- - lib/chewy/query/criteria.rb
290
- - lib/chewy/query/filters.rb
291
- - lib/chewy/query/loading.rb
292
- - lib/chewy/query/nodes/and.rb
293
- - lib/chewy/query/nodes/base.rb
294
- - lib/chewy/query/nodes/bool.rb
295
- - lib/chewy/query/nodes/equal.rb
296
- - lib/chewy/query/nodes/exists.rb
297
- - lib/chewy/query/nodes/expr.rb
298
- - lib/chewy/query/nodes/field.rb
299
- - lib/chewy/query/nodes/has_child.rb
300
- - lib/chewy/query/nodes/has_parent.rb
301
- - lib/chewy/query/nodes/has_relation.rb
302
- - lib/chewy/query/nodes/match_all.rb
303
- - lib/chewy/query/nodes/missing.rb
304
- - lib/chewy/query/nodes/not.rb
305
- - lib/chewy/query/nodes/or.rb
306
- - lib/chewy/query/nodes/prefix.rb
307
- - lib/chewy/query/nodes/query.rb
308
- - lib/chewy/query/nodes/range.rb
309
- - lib/chewy/query/nodes/raw.rb
310
- - lib/chewy/query/nodes/regexp.rb
311
- - lib/chewy/query/nodes/script.rb
312
- - lib/chewy/query/pagination.rb
284
+ - lib/chewy/multi_search.rb
313
285
  - lib/chewy/railtie.rb
314
286
  - lib/chewy/rake_helper.rb
315
287
  - lib/chewy/repository.rb
@@ -323,6 +295,7 @@ files:
323
295
  - lib/chewy/search/pagination/will_paginate.rb
324
296
  - lib/chewy/search/parameters.rb
325
297
  - lib/chewy/search/parameters/aggs.rb
298
+ - lib/chewy/search/parameters/allow_partial_search_results.rb
326
299
  - lib/chewy/search/parameters/concerns/bool_storage.rb
327
300
  - lib/chewy/search/parameters/concerns/hash_storage.rb
328
301
  - lib/chewy/search/parameters/concerns/integer_storage.rb
@@ -333,6 +306,7 @@ files:
333
306
  - lib/chewy/search/parameters/explain.rb
334
307
  - lib/chewy/search/parameters/filter.rb
335
308
  - lib/chewy/search/parameters/highlight.rb
309
+ - lib/chewy/search/parameters/indices.rb
336
310
  - lib/chewy/search/parameters/indices_boost.rb
337
311
  - lib/chewy/search/parameters/limit.rb
338
312
  - lib/chewy/search/parameters/load.rb
@@ -397,6 +371,7 @@ files:
397
371
  - lib/generators/templates/chewy.yml
398
372
  - lib/sequel/plugins/chewy_observe.rb
399
373
  - lib/tasks/chewy.rake
374
+ - migration_guide.md
400
375
  - spec/chewy/config_spec.rb
401
376
  - spec/chewy/fields/base_spec.rb
402
377
  - spec/chewy/fields/root_spec.rb
@@ -409,29 +384,7 @@ files:
409
384
  - spec/chewy/journal_spec.rb
410
385
  - spec/chewy/minitest/helpers_spec.rb
411
386
  - spec/chewy/minitest/search_index_receiver_spec.rb
412
- - spec/chewy/query/criteria_spec.rb
413
- - spec/chewy/query/filters_spec.rb
414
- - spec/chewy/query/loading_spec.rb
415
- - spec/chewy/query/nodes/and_spec.rb
416
- - spec/chewy/query/nodes/bool_spec.rb
417
- - spec/chewy/query/nodes/equal_spec.rb
418
- - spec/chewy/query/nodes/exists_spec.rb
419
- - spec/chewy/query/nodes/has_child_spec.rb
420
- - spec/chewy/query/nodes/has_parent_spec.rb
421
- - spec/chewy/query/nodes/match_all_spec.rb
422
- - spec/chewy/query/nodes/missing_spec.rb
423
- - spec/chewy/query/nodes/not_spec.rb
424
- - spec/chewy/query/nodes/or_spec.rb
425
- - spec/chewy/query/nodes/prefix_spec.rb
426
- - spec/chewy/query/nodes/query_spec.rb
427
- - spec/chewy/query/nodes/range_spec.rb
428
- - spec/chewy/query/nodes/raw_spec.rb
429
- - spec/chewy/query/nodes/regexp_spec.rb
430
- - spec/chewy/query/nodes/script_spec.rb
431
- - spec/chewy/query/pagination/kaminari_spec.rb
432
- - spec/chewy/query/pagination/will_paginate_spec.rb
433
- - spec/chewy/query/pagination_spec.rb
434
- - spec/chewy/query_spec.rb
387
+ - spec/chewy/multi_search_spec.rb
435
388
  - spec/chewy/rake_helper_spec.rb
436
389
  - spec/chewy/repository_spec.rb
437
390
  - spec/chewy/rspec/update_index_spec.rb
@@ -449,7 +402,7 @@ files:
449
402
  - spec/chewy/search/parameters/filter_spec.rb
450
403
  - spec/chewy/search/parameters/hash_storage_examples.rb
451
404
  - spec/chewy/search/parameters/highlight_spec.rb
452
- - spec/chewy/search/parameters/indices_boost_spec.rb
405
+ - spec/chewy/search/parameters/indices_spec.rb
453
406
  - spec/chewy/search/parameters/integer_storage_examples.rb
454
407
  - spec/chewy/search/parameters/limit_spec.rb
455
408
  - spec/chewy/search/parameters/load_spec.rb
@@ -518,7 +471,7 @@ homepage: https://github.com/toptal/chewy
518
471
  licenses:
519
472
  - MIT
520
473
  metadata: {}
521
- post_install_message:
474
+ post_install_message:
522
475
  rdoc_options: []
523
476
  require_paths:
524
477
  - lib
@@ -533,9 +486,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
533
486
  - !ruby/object:Gem::Version
534
487
  version: '0'
535
488
  requirements: []
536
- rubyforge_project:
537
- rubygems_version: 2.6.12
538
- signing_key:
489
+ rubygems_version: 3.1.2
490
+ signing_key:
539
491
  specification_version: 4
540
492
  summary: Elasticsearch ODM client wrapper
541
493
  test_files:
@@ -551,29 +503,7 @@ test_files:
551
503
  - spec/chewy/journal_spec.rb
552
504
  - spec/chewy/minitest/helpers_spec.rb
553
505
  - spec/chewy/minitest/search_index_receiver_spec.rb
554
- - spec/chewy/query/criteria_spec.rb
555
- - spec/chewy/query/filters_spec.rb
556
- - spec/chewy/query/loading_spec.rb
557
- - spec/chewy/query/nodes/and_spec.rb
558
- - spec/chewy/query/nodes/bool_spec.rb
559
- - spec/chewy/query/nodes/equal_spec.rb
560
- - spec/chewy/query/nodes/exists_spec.rb
561
- - spec/chewy/query/nodes/has_child_spec.rb
562
- - spec/chewy/query/nodes/has_parent_spec.rb
563
- - spec/chewy/query/nodes/match_all_spec.rb
564
- - spec/chewy/query/nodes/missing_spec.rb
565
- - spec/chewy/query/nodes/not_spec.rb
566
- - spec/chewy/query/nodes/or_spec.rb
567
- - spec/chewy/query/nodes/prefix_spec.rb
568
- - spec/chewy/query/nodes/query_spec.rb
569
- - spec/chewy/query/nodes/range_spec.rb
570
- - spec/chewy/query/nodes/raw_spec.rb
571
- - spec/chewy/query/nodes/regexp_spec.rb
572
- - spec/chewy/query/nodes/script_spec.rb
573
- - spec/chewy/query/pagination/kaminari_spec.rb
574
- - spec/chewy/query/pagination/will_paginate_spec.rb
575
- - spec/chewy/query/pagination_spec.rb
576
- - spec/chewy/query_spec.rb
506
+ - spec/chewy/multi_search_spec.rb
577
507
  - spec/chewy/rake_helper_spec.rb
578
508
  - spec/chewy/repository_spec.rb
579
509
  - spec/chewy/rspec/update_index_spec.rb
@@ -591,7 +521,7 @@ test_files:
591
521
  - spec/chewy/search/parameters/filter_spec.rb
592
522
  - spec/chewy/search/parameters/hash_storage_examples.rb
593
523
  - spec/chewy/search/parameters/highlight_spec.rb
594
- - spec/chewy/search/parameters/indices_boost_spec.rb
524
+ - spec/chewy/search/parameters/indices_spec.rb
595
525
  - spec/chewy/search/parameters/integer_storage_examples.rb
596
526
  - spec/chewy/search/parameters/limit_spec.rb
597
527
  - spec/chewy/search/parameters/load_spec.rb