chewy 0.10.1 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +240 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/.rubocop.yml +25 -25
  7. data/Appraisals +12 -10
  8. data/CHANGELOG.md +312 -331
  9. data/CODE_OF_CONDUCT.md +14 -0
  10. data/CONTRIBUTING.md +63 -0
  11. data/Gemfile +5 -1
  12. data/LICENSE.txt +1 -1
  13. data/README.md +143 -77
  14. data/chewy.gemspec +10 -12
  15. data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
  16. data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
  17. data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
  18. data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
  19. data/gemfiles/sequel.4.45.gemfile +2 -2
  20. data/lib/chewy.rb +2 -1
  21. data/lib/chewy/backports/duplicable.rb +1 -1
  22. data/lib/chewy/config.rb +10 -39
  23. data/lib/chewy/fields/base.rb +9 -3
  24. data/lib/chewy/fields/root.rb +13 -9
  25. data/lib/chewy/index.rb +3 -1
  26. data/lib/chewy/index/actions.rb +28 -16
  27. data/lib/chewy/index/aliases.rb +16 -5
  28. data/lib/chewy/index/settings.rb +2 -0
  29. data/lib/chewy/index/specification.rb +12 -10
  30. data/lib/chewy/minitest/helpers.rb +6 -6
  31. data/lib/chewy/minitest/search_index_receiver.rb +17 -17
  32. data/lib/chewy/multi_search.rb +62 -0
  33. data/lib/chewy/railtie.rb +3 -5
  34. data/lib/chewy/rake_helper.rb +5 -5
  35. data/lib/chewy/rspec/update_index.rb +3 -5
  36. data/lib/chewy/search.rb +4 -11
  37. data/lib/chewy/search/loader.rb +1 -1
  38. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  39. data/lib/chewy/search/parameters.rb +24 -6
  40. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  41. data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
  42. data/lib/chewy/search/parameters/indices.rb +123 -0
  43. data/lib/chewy/search/parameters/none.rb +1 -3
  44. data/lib/chewy/search/request.rb +101 -74
  45. data/lib/chewy/search/scrolling.rb +7 -6
  46. data/lib/chewy/stash.rb +31 -22
  47. data/lib/chewy/strategy/active_job.rb +1 -1
  48. data/lib/chewy/strategy/atomic.rb +1 -1
  49. data/lib/chewy/strategy/sidekiq.rb +1 -1
  50. data/lib/chewy/type.rb +5 -2
  51. data/lib/chewy/type/adapter/active_record.rb +1 -1
  52. data/lib/chewy/type/adapter/base.rb +9 -9
  53. data/lib/chewy/type/adapter/mongoid.rb +2 -4
  54. data/lib/chewy/type/adapter/orm.rb +7 -4
  55. data/lib/chewy/type/adapter/sequel.rb +5 -7
  56. data/lib/chewy/type/crutch.rb +1 -1
  57. data/lib/chewy/type/import.rb +16 -5
  58. data/lib/chewy/type/import/bulk_builder.rb +1 -1
  59. data/lib/chewy/type/import/bulk_request.rb +4 -2
  60. data/lib/chewy/type/import/journal_builder.rb +3 -3
  61. data/lib/chewy/type/import/routine.rb +3 -3
  62. data/lib/chewy/type/mapping.rb +42 -36
  63. data/lib/chewy/type/observe.rb +16 -12
  64. data/lib/chewy/type/syncer.rb +6 -7
  65. data/lib/chewy/type/witchcraft.rb +5 -3
  66. data/lib/chewy/type/wrapper.rb +14 -4
  67. data/lib/chewy/version.rb +1 -1
  68. data/lib/sequel/plugins/chewy_observe.rb +4 -19
  69. data/migration_guide.md +34 -0
  70. data/spec/chewy/config_spec.rb +16 -21
  71. data/spec/chewy/fields/base_spec.rb +68 -70
  72. data/spec/chewy/fields/root_spec.rb +13 -13
  73. data/spec/chewy/index/actions_spec.rb +157 -38
  74. data/spec/chewy/index/aliases_spec.rb +3 -3
  75. data/spec/chewy/index/specification_spec.rb +25 -16
  76. data/spec/chewy/index_spec.rb +75 -45
  77. data/spec/chewy/journal_spec.rb +33 -29
  78. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  79. data/spec/chewy/multi_search_spec.rb +85 -0
  80. data/spec/chewy/rake_helper_spec.rb +123 -95
  81. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  82. data/spec/chewy/runtime_spec.rb +2 -2
  83. data/spec/chewy/search/parameters/indices_spec.rb +190 -0
  84. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  85. data/spec/chewy/search/parameters_spec.rb +21 -4
  86. data/spec/chewy/search/request_spec.rb +103 -70
  87. data/spec/chewy/search/response_spec.rb +27 -17
  88. data/spec/chewy/search/scrolling_spec.rb +27 -17
  89. data/spec/chewy/search_spec.rb +49 -35
  90. data/spec/chewy/stash_spec.rb +15 -13
  91. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  92. data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
  93. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  94. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  95. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  96. data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
  97. data/spec/chewy/type/import_spec.rb +15 -0
  98. data/spec/chewy/type/mapping_spec.rb +51 -18
  99. data/spec/chewy/type/observe_spec.rb +4 -4
  100. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  101. data/spec/chewy/type/wrapper_spec.rb +3 -1
  102. data/spec/chewy_spec.rb +0 -7
  103. data/spec/spec_helper.rb +5 -1
  104. data/spec/support/active_record.rb +21 -0
  105. metadata +51 -116
  106. data/.travis.yml +0 -53
  107. data/LEGACY_DSL.md +0 -497
  108. data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
  109. data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
  110. data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
  111. data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
  112. data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
  113. data/lib/chewy/query.rb +0 -1098
  114. data/lib/chewy/query/compose.rb +0 -68
  115. data/lib/chewy/query/criteria.rb +0 -191
  116. data/lib/chewy/query/filters.rb +0 -227
  117. data/lib/chewy/query/loading.rb +0 -111
  118. data/lib/chewy/query/nodes/and.rb +0 -25
  119. data/lib/chewy/query/nodes/base.rb +0 -17
  120. data/lib/chewy/query/nodes/bool.rb +0 -34
  121. data/lib/chewy/query/nodes/equal.rb +0 -34
  122. data/lib/chewy/query/nodes/exists.rb +0 -20
  123. data/lib/chewy/query/nodes/expr.rb +0 -28
  124. data/lib/chewy/query/nodes/field.rb +0 -110
  125. data/lib/chewy/query/nodes/has_child.rb +0 -15
  126. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  127. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  128. data/lib/chewy/query/nodes/match_all.rb +0 -11
  129. data/lib/chewy/query/nodes/missing.rb +0 -20
  130. data/lib/chewy/query/nodes/not.rb +0 -25
  131. data/lib/chewy/query/nodes/or.rb +0 -25
  132. data/lib/chewy/query/nodes/prefix.rb +0 -19
  133. data/lib/chewy/query/nodes/query.rb +0 -20
  134. data/lib/chewy/query/nodes/range.rb +0 -63
  135. data/lib/chewy/query/nodes/raw.rb +0 -15
  136. data/lib/chewy/query/nodes/regexp.rb +0 -35
  137. data/lib/chewy/query/nodes/script.rb +0 -20
  138. data/lib/chewy/query/pagination.rb +0 -25
  139. data/spec/chewy/query/criteria_spec.rb +0 -700
  140. data/spec/chewy/query/filters_spec.rb +0 -201
  141. data/spec/chewy/query/loading_spec.rb +0 -124
  142. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  143. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  144. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  145. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  146. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  147. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  148. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  149. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  150. data/spec/chewy/query/nodes/not_spec.rb +0 -13
  151. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  152. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  153. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  154. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  155. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  156. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  157. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  158. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  159. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  160. data/spec/chewy/query/pagination_spec.rb +0 -39
  161. data/spec/chewy/query_spec.rb +0 -636
  162. 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
@@ -152,6 +158,15 @@ describe Chewy::Type::Import do
152
158
  specify do
153
159
  expect { import City.where(id: dummy_cities.first.id) }.to update_index(CitiesIndex::City).and_reindex(dummy_cities.first).only
154
160
  end
161
+
162
+ specify do
163
+ allow(CitiesIndex::City).to receive(:import_linear).and_return(double(present?: false))
164
+ allow(CitiesIndex::City).to receive(:import_parallel).and_return(double(present?: false))
165
+
166
+ expects_no_query(except: /SELECT\s+1\s+AS\s+one\s+FROM/) do
167
+ import City.where(id: dummy_cities.first.id)
168
+ end
169
+ end
155
170
  end
156
171
  end
157
172
 
@@ -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
@@ -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,27 @@ 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(except: nil, &block)
43
+ queries = []
44
+ ActiveSupport::Notifications.subscribed(
45
+ ->(*args) { queries << args[4][:sql] },
46
+ 'sql.active_record',
47
+ &block
48
+ )
49
+ ofending_queries = except ? queries.find_all { |query| !query.match(except) } : queries
50
+ raise "Expected no DB queries, but the following ones were made: #{ofending_queries.join(', ')}" if ofending_queries.present?
51
+ end
52
+
32
53
  def stub_model(name, superclass = nil, &block)
33
54
  stub_class(name, superclass || ActiveRecord::Base, &block)
34
55
  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.1
4
+ version: 7.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-08-07 00:00:00.000000000 Z
12
+ date: 2021-02-22 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,36 @@ 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"
248
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
249
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
250
+ - ".github/PULL_REQUEST_TEMPLATE.md"
245
251
  - ".gitignore"
246
252
  - ".rspec"
247
253
  - ".rubocop.yml"
248
254
  - ".rubocop_todo.yml"
249
- - ".travis.yml"
250
255
  - ".yardopts"
251
256
  - Appraisals
252
257
  - CHANGELOG.md
258
+ - CODE_OF_CONDUCT.md
259
+ - CONTRIBUTING.md
253
260
  - Gemfile
254
261
  - Guardfile
255
- - LEGACY_DSL.md
256
262
  - LICENSE.txt
257
263
  - README.md
258
264
  - Rakefile
259
265
  - chewy.gemspec
260
266
  - 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
267
+ - gemfiles/rails.5.2.activerecord.gemfile
268
+ - gemfiles/rails.5.2.mongoid.6.4.gemfile
269
+ - gemfiles/rails.6.0.activerecord.gemfile
270
+ - gemfiles/rails.6.1.activerecord.gemfile
269
271
  - gemfiles/sequel.4.45.gemfile
270
272
  - lib/chewy.rb
271
273
  - lib/chewy/backports/deep_dup.rb
@@ -284,32 +286,7 @@ files:
284
286
  - lib/chewy/minitest.rb
285
287
  - lib/chewy/minitest/helpers.rb
286
288
  - 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
289
+ - lib/chewy/multi_search.rb
313
290
  - lib/chewy/railtie.rb
314
291
  - lib/chewy/rake_helper.rb
315
292
  - lib/chewy/repository.rb
@@ -323,6 +300,7 @@ files:
323
300
  - lib/chewy/search/pagination/will_paginate.rb
324
301
  - lib/chewy/search/parameters.rb
325
302
  - lib/chewy/search/parameters/aggs.rb
303
+ - lib/chewy/search/parameters/allow_partial_search_results.rb
326
304
  - lib/chewy/search/parameters/concerns/bool_storage.rb
327
305
  - lib/chewy/search/parameters/concerns/hash_storage.rb
328
306
  - lib/chewy/search/parameters/concerns/integer_storage.rb
@@ -333,6 +311,7 @@ files:
333
311
  - lib/chewy/search/parameters/explain.rb
334
312
  - lib/chewy/search/parameters/filter.rb
335
313
  - lib/chewy/search/parameters/highlight.rb
314
+ - lib/chewy/search/parameters/indices.rb
336
315
  - lib/chewy/search/parameters/indices_boost.rb
337
316
  - lib/chewy/search/parameters/limit.rb
338
317
  - lib/chewy/search/parameters/load.rb
@@ -397,6 +376,7 @@ files:
397
376
  - lib/generators/templates/chewy.yml
398
377
  - lib/sequel/plugins/chewy_observe.rb
399
378
  - lib/tasks/chewy.rake
379
+ - migration_guide.md
400
380
  - spec/chewy/config_spec.rb
401
381
  - spec/chewy/fields/base_spec.rb
402
382
  - spec/chewy/fields/root_spec.rb
@@ -409,29 +389,7 @@ files:
409
389
  - spec/chewy/journal_spec.rb
410
390
  - spec/chewy/minitest/helpers_spec.rb
411
391
  - 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
392
+ - spec/chewy/multi_search_spec.rb
435
393
  - spec/chewy/rake_helper_spec.rb
436
394
  - spec/chewy/repository_spec.rb
437
395
  - spec/chewy/rspec/update_index_spec.rb
@@ -449,7 +407,7 @@ files:
449
407
  - spec/chewy/search/parameters/filter_spec.rb
450
408
  - spec/chewy/search/parameters/hash_storage_examples.rb
451
409
  - spec/chewy/search/parameters/highlight_spec.rb
452
- - spec/chewy/search/parameters/indices_boost_spec.rb
410
+ - spec/chewy/search/parameters/indices_spec.rb
453
411
  - spec/chewy/search/parameters/integer_storage_examples.rb
454
412
  - spec/chewy/search/parameters/limit_spec.rb
455
413
  - spec/chewy/search/parameters/load_spec.rb
@@ -518,7 +476,7 @@ homepage: https://github.com/toptal/chewy
518
476
  licenses:
519
477
  - MIT
520
478
  metadata: {}
521
- post_install_message:
479
+ post_install_message:
522
480
  rdoc_options: []
523
481
  require_paths:
524
482
  - lib
@@ -533,9 +491,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
533
491
  - !ruby/object:Gem::Version
534
492
  version: '0'
535
493
  requirements: []
536
- rubyforge_project:
537
- rubygems_version: 2.6.12
538
- signing_key:
494
+ rubygems_version: 3.1.2
495
+ signing_key:
539
496
  specification_version: 4
540
497
  summary: Elasticsearch ODM client wrapper
541
498
  test_files:
@@ -551,29 +508,7 @@ test_files:
551
508
  - spec/chewy/journal_spec.rb
552
509
  - spec/chewy/minitest/helpers_spec.rb
553
510
  - 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
511
+ - spec/chewy/multi_search_spec.rb
577
512
  - spec/chewy/rake_helper_spec.rb
578
513
  - spec/chewy/repository_spec.rb
579
514
  - spec/chewy/rspec/update_index_spec.rb
@@ -591,7 +526,7 @@ test_files:
591
526
  - spec/chewy/search/parameters/filter_spec.rb
592
527
  - spec/chewy/search/parameters/hash_storage_examples.rb
593
528
  - spec/chewy/search/parameters/highlight_spec.rb
594
- - spec/chewy/search/parameters/indices_boost_spec.rb
529
+ - spec/chewy/search/parameters/indices_spec.rb
595
530
  - spec/chewy/search/parameters/integer_storage_examples.rb
596
531
  - spec/chewy/search/parameters/limit_spec.rb
597
532
  - spec/chewy/search/parameters/load_spec.rb