chewy 5.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +214 -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/Appraisals +1 -17
  7. data/CHANGELOG.md +312 -356
  8. data/CODE_OF_CONDUCT.md +14 -0
  9. data/CONTRIBUTING.md +63 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +97 -92
  13. data/chewy.gemspec +5 -5
  14. data/gemfiles/rails.5.2.activerecord.gemfile +4 -3
  15. data/gemfiles/{rails.5.0.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +4 -3
  16. data/gemfiles/{rails.5.0.mongoid.6.1.gemfile → rails.6.0.activerecord.gemfile} +4 -3
  17. data/gemfiles/{rails.5.1.activerecord.gemfile → rails.6.1.activerecord.gemfile} +6 -3
  18. data/lib/chewy.rb +1 -1
  19. data/lib/chewy/backports/duplicable.rb +1 -1
  20. data/lib/chewy/config.rb +2 -20
  21. data/lib/chewy/fields/base.rb +1 -7
  22. data/lib/chewy/fields/root.rb +3 -4
  23. data/lib/chewy/index.rb +6 -15
  24. data/lib/chewy/index/actions.rb +12 -4
  25. data/lib/chewy/index/aliases.rb +14 -5
  26. data/lib/chewy/multi_search.rb +62 -0
  27. data/lib/chewy/railtie.rb +3 -19
  28. data/lib/chewy/search.rb +2 -9
  29. data/lib/chewy/search/loader.rb +3 -13
  30. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  31. data/lib/chewy/search/parameters.rb +24 -6
  32. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  33. data/lib/chewy/search/parameters/indices.rb +78 -0
  34. data/lib/chewy/search/parameters/none.rb +1 -3
  35. data/lib/chewy/search/request.rb +92 -85
  36. data/lib/chewy/search/response.rb +1 -1
  37. data/lib/chewy/search/scrolling.rb +8 -7
  38. data/lib/chewy/stash.rb +3 -6
  39. data/lib/chewy/strategy/active_job.rb +1 -1
  40. data/lib/chewy/strategy/sidekiq.rb +1 -1
  41. data/lib/chewy/type.rb +4 -1
  42. data/lib/chewy/type/adapter/active_record.rb +1 -1
  43. data/lib/chewy/type/adapter/mongoid.rb +1 -1
  44. data/lib/chewy/type/adapter/orm.rb +7 -4
  45. data/lib/chewy/type/adapter/sequel.rb +1 -1
  46. data/lib/chewy/type/import.rb +14 -4
  47. data/lib/chewy/type/import/bulk_request.rb +5 -4
  48. data/lib/chewy/type/import/journal_builder.rb +2 -3
  49. data/lib/chewy/type/import/routine.rb +3 -3
  50. data/lib/chewy/type/mapping.rb +5 -5
  51. data/lib/chewy/type/observe.rb +3 -3
  52. data/lib/chewy/type/syncer.rb +2 -6
  53. data/lib/chewy/type/witchcraft.rb +4 -2
  54. data/lib/chewy/type/wrapper.rb +12 -2
  55. data/lib/chewy/version.rb +1 -1
  56. data/lib/tasks/chewy.rake +10 -10
  57. data/migration_guide.md +37 -0
  58. data/spec/chewy/config_spec.rb +1 -22
  59. data/spec/chewy/fields/base_spec.rb +15 -13
  60. data/spec/chewy/fields/root_spec.rb +4 -4
  61. data/spec/chewy/index/actions_spec.rb +120 -33
  62. data/spec/chewy/index/aliases_spec.rb +3 -3
  63. data/spec/chewy/index/specification_spec.rb +13 -13
  64. data/spec/chewy/index_spec.rb +17 -42
  65. data/spec/chewy/journal_spec.rb +25 -21
  66. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  67. data/spec/chewy/multi_search_spec.rb +85 -0
  68. data/spec/chewy/rake_helper_spec.rb +102 -87
  69. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  70. data/spec/chewy/runtime_spec.rb +2 -2
  71. data/spec/chewy/search/loader_spec.rb +0 -16
  72. data/spec/chewy/search/parameters/indices_spec.rb +105 -0
  73. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  74. data/spec/chewy/search/parameters_spec.rb +21 -4
  75. data/spec/chewy/search/request_spec.rb +94 -78
  76. data/spec/chewy/search/response_spec.rb +27 -17
  77. data/spec/chewy/search/scrolling_spec.rb +22 -18
  78. data/spec/chewy/search_spec.rb +45 -41
  79. data/spec/chewy/stash_spec.rb +14 -12
  80. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  81. data/spec/chewy/strategy/shoryuken_spec.rb +6 -2
  82. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  83. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  84. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  85. data/spec/chewy/type/import/bulk_request_spec.rb +0 -6
  86. data/spec/chewy/type/import/journal_builder_spec.rb +9 -11
  87. data/spec/chewy/type/import_spec.rb +11 -2
  88. data/spec/chewy/type/mapping_spec.rb +8 -38
  89. data/spec/chewy/type/observe_spec.rb +4 -4
  90. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  91. data/spec/chewy/type/wrapper_spec.rb +3 -1
  92. data/spec/chewy_spec.rb +0 -7
  93. data/spec/spec_helper.rb +4 -8
  94. data/spec/support/active_record.rb +21 -0
  95. metadata +31 -100
  96. data/.travis.yml +0 -45
  97. data/LEGACY_DSL.md +0 -497
  98. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  99. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  100. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  101. data/gemfiles/rails.4.2.mongoid.5.2.gemfile +0 -16
  102. data/gemfiles/rails.5.1.mongoid.6.3.gemfile +0 -16
  103. data/lib/chewy/query.rb +0 -1137
  104. data/lib/chewy/query/compose.rb +0 -68
  105. data/lib/chewy/query/criteria.rb +0 -191
  106. data/lib/chewy/query/filters.rb +0 -244
  107. data/lib/chewy/query/loading.rb +0 -110
  108. data/lib/chewy/query/nodes/and.rb +0 -25
  109. data/lib/chewy/query/nodes/base.rb +0 -17
  110. data/lib/chewy/query/nodes/bool.rb +0 -34
  111. data/lib/chewy/query/nodes/equal.rb +0 -34
  112. data/lib/chewy/query/nodes/exists.rb +0 -20
  113. data/lib/chewy/query/nodes/expr.rb +0 -28
  114. data/lib/chewy/query/nodes/field.rb +0 -110
  115. data/lib/chewy/query/nodes/has_child.rb +0 -15
  116. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  117. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  118. data/lib/chewy/query/nodes/match_all.rb +0 -11
  119. data/lib/chewy/query/nodes/missing.rb +0 -20
  120. data/lib/chewy/query/nodes/not.rb +0 -25
  121. data/lib/chewy/query/nodes/or.rb +0 -25
  122. data/lib/chewy/query/nodes/prefix.rb +0 -19
  123. data/lib/chewy/query/nodes/query.rb +0 -20
  124. data/lib/chewy/query/nodes/range.rb +0 -63
  125. data/lib/chewy/query/nodes/raw.rb +0 -15
  126. data/lib/chewy/query/nodes/regexp.rb +0 -35
  127. data/lib/chewy/query/nodes/script.rb +0 -20
  128. data/lib/chewy/query/pagination.rb +0 -25
  129. data/lib/chewy/search/parameters/types.rb +0 -20
  130. data/spec/chewy/query/criteria_spec.rb +0 -700
  131. data/spec/chewy/query/filters_spec.rb +0 -201
  132. data/spec/chewy/query/loading_spec.rb +0 -124
  133. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  134. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  135. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  136. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  137. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  138. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  139. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  140. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  141. data/spec/chewy/query/nodes/not_spec.rb +0 -14
  142. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  143. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  144. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  145. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  146. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  147. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  148. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  149. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  150. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  151. data/spec/chewy/query/pagination_spec.rb +0 -39
  152. data/spec/chewy/query_spec.rb +0 -637
  153. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
  154. data/spec/chewy/search/parameters/types_spec.rb +0 -5
@@ -0,0 +1,37 @@
1
+ # Migration guide
2
+
3
+ This document outlines the steps you need to take when migrating between major versions of
4
+ Chewy and Elasticsearch. For simplicity's sake the guide will assume that you're using
5
+ Chewy alongside a matching Elasticsearch version.
6
+
7
+ ## Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7
8
+
9
+ In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the most seamless manner you have to:
10
+
11
+ * Upgrade to the latest 6.x stable releases, namely Chewy 6.0, Elasticsearch 6.8
12
+ * Study carefully [Breaking changes in 7.0](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.htmll), make sure your application conforms.
13
+ * Run your test suite on Chewy 7.0 / Elasticsearch 7
14
+ * Run manual tests on Chewy 7.0 / Elasticsearch 7
15
+ * Upgrade to Chewy 7.0
16
+ * Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference//rolling-upgrades.html) of Elasticsearch
17
+ * Run your test suite on Chewy 7.1 / Elasticsearch 7
18
+ * Run manual tests on Chewy 7.1 / Elasticsearch 7
19
+ * Upgrade to Chewy 7.1
20
+
21
+ ## Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6
22
+
23
+ In order to upgrade Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 in the most seamless manner you have to:
24
+
25
+ * Upgrade to the latest 5.x stable releases, namely Chewy 5.2, Elasticsearch 5.6
26
+ * [Migrate any multi-typed indexes into single-typed](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html)
27
+ * Using [multi-index queries](https://github.com/toptal/chewy/pull/657) could be helpful
28
+ * Parent/Child [relationship is deprecated](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/removal-of-types.html#parent-child-mapping-types) in favor of the [join field](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/parent-join.html)
29
+ * Handle deprecation of `string` type & `not_analyzed` value for the `index` mapping parameter:
30
+ * replace fields with `{ type: 'string', index: 'not_analyzed'}` by `{type: 'keyword'}`
31
+ * replace fields with `{ type: 'string', index: 'analyzed'}` by `{type: 'text'}`
32
+ * `PathHierarchy` tokenizer' param `delimiter` now accepts only one argument, [others should be replaced by character filter ](https://discuss.elastic.co/t/multichar-delimiter-in-path-hierarchy-tokenizer/16203)
33
+ * Make sure you don't use any other of the [deprecated Elasticsearch 5 features](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html)
34
+ * Run your test suite on Chewy 6 / Elasticsearch 6
35
+ * Run manual tests on Chewy 6 / Elasticsearch 6
36
+ * Upgrade to Chewy 6
37
+ * Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html) of Elasticsearch
@@ -6,9 +6,6 @@ describe Chewy::Config do
6
6
  its(:logger) { should be_nil }
7
7
  its(:transport_logger) { should be_nil }
8
8
  its(:transport_logger) { should be_nil }
9
- its(:query_mode) { should == :must }
10
- its(:filter_mode) { should == :and }
11
- its(:post_filter_mode) { should be_nil }
12
9
  its(:root_strategy) { should == :base }
13
10
  its(:request_strategy) { should == :atomic }
14
11
  its(:use_after_commit_callbacks) { should == true }
@@ -54,24 +51,6 @@ describe Chewy::Config do
54
51
  end
55
52
  end
56
53
 
57
- describe '#search_class=' do
58
- specify do
59
- expect { subject.search_class = Chewy::Query }
60
- .to change { subject.search_class }
61
- .from(be < Chewy::Search::Request)
62
- .to(be < Chewy::Query)
63
- end
64
-
65
- context do
66
- before { hide_const('Kaminari') }
67
-
68
- specify do
69
- expect(subject.search_class.included_modules)
70
- .to include(Chewy::Search::Pagination::WillPaginate)
71
- end
72
- end
73
- end
74
-
75
54
  describe '#search_class' do
76
55
  context 'nothing is defined' do
77
56
  before do
@@ -141,7 +120,7 @@ describe Chewy::Config do
141
120
  context 'when Rails::VERSION constant is defined' do
142
121
  it 'looks for configuration in "config/chewy.yml"' do
143
122
  module Rails
144
- VERSION = '5.1.0'.freeze
123
+ VERSION = '5.1.1'.freeze
145
124
 
146
125
  def self.root
147
126
  Pathname.new(__dir__)
@@ -143,7 +143,7 @@ describe Chewy::Fields::Base do
143
143
  end
144
144
 
145
145
  specify do
146
- expect(EventsIndex::Event.mappings_hash).to eq(event: {
146
+ expect(EventsIndex::Event.mappings_hash).to eq(
147
147
  properties: {
148
148
  id: {type: 'integer'},
149
149
  category: {
@@ -160,7 +160,7 @@ describe Chewy::Fields::Base do
160
160
  }
161
161
  }
162
162
  }
163
- })
163
+ )
164
164
  end
165
165
  end
166
166
 
@@ -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(
@@ -294,7 +296,7 @@ describe Chewy::Fields::Base do
294
296
  end
295
297
 
296
298
  specify do
297
- expect(EventsIndex::Event.mappings_hash).to eq(event: {
299
+ expect(EventsIndex::Event.mappings_hash).to eq(
298
300
  properties: {
299
301
  id: {type: 'integer'},
300
302
  name: {
@@ -305,7 +307,7 @@ describe Chewy::Fields::Base do
305
307
  },
306
308
  category: {type: 'object'}
307
309
  }
308
- })
310
+ )
309
311
  end
310
312
 
311
313
  specify do
@@ -13,7 +13,7 @@ describe Chewy::Fields::Root do
13
13
  field.dynamic_template template_42: {mapping: {}, match: ''}
14
14
  field.dynamic_template(/hello\..*/)
15
15
 
16
- expect(field.mappings_hash).to eq(product: {dynamic_templates: [
16
+ expect(field.mappings_hash).to eq(dynamic_templates: [
17
17
  {template_1: {mapping: {type: 'keyword'}, match: 'hello'}},
18
18
  {template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
19
19
  {template_3: {mapping: {}, path_match: 'hello.*'}},
@@ -21,7 +21,7 @@ describe Chewy::Fields::Root do
21
21
  {template_5: {mapping: {}, match: 'hello.*', match_pattern: 'regexp'}},
22
22
  {template_42: {mapping: {}, match: ''}},
23
23
  {template_7: {mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp'}}
24
- ]})
24
+ ])
25
25
  end
26
26
 
27
27
  context do
@@ -33,10 +33,10 @@ describe Chewy::Fields::Root do
33
33
 
34
34
  specify do
35
35
  field.dynamic_template 'hello', type: 'keyword'
36
- expect(field.mappings_hash).to eq(product: {dynamic_templates: [
36
+ expect(field.mappings_hash).to eq(dynamic_templates: [
37
37
  {template_42: {mapping: {}, match: ''}},
38
38
  {template_1: {mapping: {type: 'keyword'}, match: 'hello'}}
39
- ]})
39
+ ])
40
40
  end
41
41
  end
42
42
  end
@@ -3,7 +3,10 @@ require 'spec_helper'
3
3
  describe Chewy::Index::Actions do
4
4
  before { Chewy.massacre }
5
5
 
6
- before { stub_index :dummies }
6
+ before do
7
+ stub_index :dummies
8
+ stub_index :dummies_suffixed
9
+ end
7
10
 
8
11
  describe '.exists?' do
9
12
  specify { expect(DummiesIndex.exists?).to eq(false) }
@@ -25,26 +28,40 @@ describe Chewy::Index::Actions do
25
28
  end
26
29
 
27
30
  context do
28
- before { DummiesIndex.create '2013' }
31
+ before do
32
+ DummiesIndex.create '2013'
33
+ DummiesSuffixedIndex.create 'should_not_appear'
34
+ end
35
+
29
36
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
30
37
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
31
- specify { expect(DummiesIndex.aliases).to eq([]) }
38
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
32
39
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
33
40
  specify { expect(DummiesIndex.create('2013')).to eq(false) }
34
41
  specify { expect(DummiesIndex.create('2014')['acknowledged']).to eq(true) }
35
42
 
36
43
  context do
37
44
  before { DummiesIndex.create '2014' }
45
+
38
46
  specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
39
47
  end
40
48
  end
41
49
 
42
50
  context do
43
- before { DummiesIndex.create '2013', alias: false }
51
+ before do
52
+ DummiesIndex.create '2013', alias: false
53
+ DummiesSuffixedIndex.create 'should_not_appear'
54
+ end
55
+
44
56
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
45
57
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
46
58
  specify { expect(DummiesIndex.aliases).to eq([]) }
47
59
  specify { expect(DummiesIndex.indexes).to eq([]) }
60
+ specify { expect(DummiesIndex.exists?).to eq(false) }
61
+ # Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
62
+ # it would be awesome to have the following specs passing
63
+ # specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
64
+ # specify { expect(DummiesIndex.exists?).to eq(true) }
48
65
  end
49
66
  end
50
67
 
@@ -53,36 +70,54 @@ describe Chewy::Index::Actions do
53
70
  specify { expect(DummiesIndex.create!('2013')['acknowledged']).to eq(true) }
54
71
 
55
72
  context do
56
- before { DummiesIndex.create }
73
+ before do
74
+ DummiesIndex.create
75
+ DummiesSuffixedIndex.create 'should_not_appear'
76
+ end
77
+
57
78
  specify do
58
- expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies/)
79
+ expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies/)
59
80
  end
60
81
  specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
61
82
  end
62
83
 
63
84
  context do
64
- before { DummiesIndex.create! '2013' }
85
+ before do
86
+ DummiesIndex.create! '2013'
87
+ DummiesSuffixedIndex.create! 'should_not_appear'
88
+ end
89
+
65
90
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
66
91
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
67
- specify { expect(DummiesIndex.aliases).to eq([]) }
92
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
68
93
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
69
94
  specify do
70
- expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies_2013/)
95
+ expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/already exists.*dummies_2013/)
71
96
  end
72
97
  specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
73
98
 
74
99
  context do
75
100
  before { DummiesIndex.create! '2014' }
101
+
76
102
  specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
77
103
  end
78
104
  end
79
105
 
80
106
  context do
81
- before { DummiesIndex.create! '2013', alias: false }
107
+ before do
108
+ DummiesIndex.create! '2013', alias: false
109
+ DummiesSuffixedIndex.create! 'should_not_appear'
110
+ end
111
+
82
112
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
83
113
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
84
114
  specify { expect(DummiesIndex.aliases).to eq([]) }
85
115
  specify { expect(DummiesIndex.indexes).to eq([]) }
116
+ specify { expect(DummiesIndex.exists?).to eq(false) }
117
+ # Unfortunately, without alias we can't figure out that this dummies_2013 index is related to DummiesIndex
118
+ # it would be awesome to have the following specs passing
119
+ # specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
120
+ # specify { expect(DummiesIndex.exists?).to eq(true) }
86
121
  end
87
122
  end
88
123
 
@@ -91,27 +126,40 @@ describe Chewy::Index::Actions do
91
126
  specify { expect(DummiesIndex.delete('dummies_2013')).to eq(false) }
92
127
 
93
128
  context do
94
- before { DummiesIndex.create }
129
+ before do
130
+ DummiesIndex.create
131
+ DummiesSuffixedIndex.create 'should_not_appear'
132
+ end
133
+
95
134
  specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
96
135
 
97
136
  context do
98
137
  before { DummiesIndex.delete }
99
138
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
139
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
100
140
  end
101
141
  end
102
142
 
103
143
  context do
104
- before { DummiesIndex.create '2013' }
144
+ before do
145
+ DummiesIndex.create '2013'
146
+ DummiesSuffixedIndex.create 'should_not_appear'
147
+ end
148
+
105
149
  specify { expect(DummiesIndex.delete('2013')['acknowledged']).to eq(true) }
106
150
 
107
151
  context do
108
152
  before { DummiesIndex.delete('2013') }
109
153
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
110
154
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
155
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
111
156
  end
112
157
 
113
158
  context do
114
- before { DummiesIndex.create '2014' }
159
+ before do
160
+ DummiesIndex.create '2014'
161
+ end
162
+
115
163
  specify { expect(DummiesIndex.delete['acknowledged']).to eq(true) }
116
164
 
117
165
  context do
@@ -119,6 +167,7 @@ describe Chewy::Index::Actions do
119
167
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
120
168
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
121
169
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
170
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
122
171
  end
123
172
 
124
173
  context do
@@ -126,6 +175,7 @@ describe Chewy::Index::Actions do
126
175
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
127
176
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
128
177
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
178
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
129
179
  end
130
180
  end
131
181
  end
@@ -136,27 +186,38 @@ describe Chewy::Index::Actions do
136
186
  specify { expect { DummiesIndex.delete!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) }
137
187
 
138
188
  context do
139
- before { DummiesIndex.create }
189
+ before do
190
+ DummiesIndex.create
191
+ DummiesSuffixedIndex.create 'should_not_appear'
192
+ end
193
+
140
194
  specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
141
195
 
142
196
  context do
143
197
  before { DummiesIndex.delete! }
144
198
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
199
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
145
200
  end
146
201
  end
147
202
 
148
203
  context do
149
- before { DummiesIndex.create '2013' }
204
+ before do
205
+ DummiesIndex.create '2013'
206
+ DummiesSuffixedIndex.create 'should_not_appear'
207
+ end
208
+
150
209
  specify { expect(DummiesIndex.delete!('2013')['acknowledged']).to eq(true) }
151
210
 
152
211
  context do
153
212
  before { DummiesIndex.delete!('2013') }
154
213
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
155
214
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
215
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
156
216
  end
157
217
 
158
218
  context do
159
219
  before { DummiesIndex.create '2014' }
220
+
160
221
  specify { expect(DummiesIndex.delete!['acknowledged']).to eq(true) }
161
222
 
162
223
  context do
@@ -164,6 +225,7 @@ describe Chewy::Index::Actions do
164
225
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(false) }
165
226
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(false) }
166
227
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
228
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
167
229
  end
168
230
 
169
231
  context do
@@ -171,6 +233,7 @@ describe Chewy::Index::Actions do
171
233
  specify { expect(Chewy.client.indices.exists(index: 'dummies')).to eq(true) }
172
234
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2013')).to eq(true) }
173
235
  specify { expect(Chewy.client.indices.exists(index: 'dummies_2014')).to eq(false) }
236
+ specify { expect(Chewy.client.indices.exists(index: 'dummies_suffixed')).to eq(true) }
174
237
  end
175
238
  end
176
239
  end
@@ -184,19 +247,19 @@ describe Chewy::Index::Actions do
184
247
  before { DummiesIndex.purge }
185
248
  specify { expect(DummiesIndex).to be_exists }
186
249
  specify { expect(DummiesIndex.aliases).to eq([]) }
187
- specify { expect(DummiesIndex.indexes).to eq([]) }
250
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
188
251
 
189
252
  context do
190
253
  before { DummiesIndex.purge }
191
254
  specify { expect(DummiesIndex).to be_exists }
192
255
  specify { expect(DummiesIndex.aliases).to eq([]) }
193
- specify { expect(DummiesIndex.indexes).to eq([]) }
256
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
194
257
  end
195
258
 
196
259
  context do
197
260
  before { DummiesIndex.purge('2013') }
198
261
  specify { expect(DummiesIndex).to be_exists }
199
- specify { expect(DummiesIndex.aliases).to eq([]) }
262
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
200
263
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
201
264
  end
202
265
  end
@@ -204,20 +267,20 @@ describe Chewy::Index::Actions do
204
267
  context do
205
268
  before { DummiesIndex.purge('2013') }
206
269
  specify { expect(DummiesIndex).to be_exists }
207
- specify { expect(DummiesIndex.aliases).to eq([]) }
270
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
208
271
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
209
272
 
210
273
  context do
211
274
  before { DummiesIndex.purge }
212
275
  specify { expect(DummiesIndex).to be_exists }
213
276
  specify { expect(DummiesIndex.aliases).to eq([]) }
214
- specify { expect(DummiesIndex.indexes).to eq([]) }
277
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
215
278
  end
216
279
 
217
280
  context do
218
281
  before { DummiesIndex.purge('2014') }
219
282
  specify { expect(DummiesIndex).to be_exists }
220
- specify { expect(DummiesIndex.aliases).to eq([]) }
283
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
221
284
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
222
285
  end
223
286
  end
@@ -231,19 +294,19 @@ describe Chewy::Index::Actions do
231
294
  before { DummiesIndex.purge! }
232
295
  specify { expect(DummiesIndex).to be_exists }
233
296
  specify { expect(DummiesIndex.aliases).to eq([]) }
234
- specify { expect(DummiesIndex.indexes).to eq([]) }
297
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
235
298
 
236
299
  context do
237
300
  before { DummiesIndex.purge! }
238
301
  specify { expect(DummiesIndex).to be_exists }
239
302
  specify { expect(DummiesIndex.aliases).to eq([]) }
240
- specify { expect(DummiesIndex.indexes).to eq([]) }
303
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
241
304
  end
242
305
 
243
306
  context do
244
307
  before { DummiesIndex.purge!('2013') }
245
308
  specify { expect(DummiesIndex).to be_exists }
246
- specify { expect(DummiesIndex.aliases).to eq([]) }
309
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
247
310
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
248
311
  end
249
312
  end
@@ -251,20 +314,20 @@ describe Chewy::Index::Actions do
251
314
  context do
252
315
  before { DummiesIndex.purge!('2013') }
253
316
  specify { expect(DummiesIndex).to be_exists }
254
- specify { expect(DummiesIndex.aliases).to eq([]) }
317
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
255
318
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
256
319
 
257
320
  context do
258
321
  before { DummiesIndex.purge! }
259
322
  specify { expect(DummiesIndex).to be_exists }
260
323
  specify { expect(DummiesIndex.aliases).to eq([]) }
261
- specify { expect(DummiesIndex.indexes).to eq([]) }
324
+ specify { expect(DummiesIndex.indexes).to eq(['dummies']) }
262
325
  end
263
326
 
264
327
  context do
265
328
  before { DummiesIndex.purge!('2014') }
266
329
  specify { expect(DummiesIndex).to be_exists }
267
- specify { expect(DummiesIndex.aliases).to eq([]) }
330
+ specify { expect(DummiesIndex.aliases).to eq(['dummies']) }
268
331
  specify { expect(DummiesIndex.indexes).to eq(['dummies_2014']) }
269
332
  end
270
333
  end
@@ -281,6 +344,18 @@ describe Chewy::Index::Actions do
281
344
 
282
345
  specify { expect(CitiesIndex.import).to eq(true) }
283
346
 
347
+ specify 'with an empty array' do
348
+ expect(CitiesIndex).not_to receive(:exists?)
349
+ expect(CitiesIndex).not_to receive(:create!)
350
+ expect(CitiesIndex.import([])).to eq(true)
351
+ end
352
+
353
+ specify 'with an empty relation' do
354
+ expect(CitiesIndex).not_to receive(:exists?)
355
+ expect(CitiesIndex).not_to receive(:create!)
356
+ expect(CitiesIndex.import(City.where('1 = 2'))).to eq(true)
357
+ end
358
+
284
359
  context do
285
360
  before do
286
361
  stub_index(:cities) do
@@ -305,6 +380,18 @@ describe Chewy::Index::Actions do
305
380
 
306
381
  specify { expect(CitiesIndex.import!).to eq(true) }
307
382
 
383
+ specify 'with an empty array' do
384
+ expect(CitiesIndex).not_to receive(:exists?)
385
+ expect(CitiesIndex).not_to receive(:create!)
386
+ expect(CitiesIndex.import!([])).to eq(true)
387
+ end
388
+
389
+ specify 'with an empty relation' do
390
+ expect(CitiesIndex).not_to receive(:exists?)
391
+ expect(CitiesIndex).not_to receive(:create!)
392
+ expect(CitiesIndex.import!(City.where('1 = 2'))).to eq(true)
393
+ end
394
+
308
395
  context do
309
396
  before do
310
397
  stub_index(:cities) do
@@ -337,13 +424,13 @@ describe Chewy::Index::Actions do
337
424
 
338
425
  specify { expect(CitiesIndex.all).to have(1).item }
339
426
  specify { expect(CitiesIndex.aliases).to eq([]) }
340
- specify { expect(CitiesIndex.indexes).to eq([]) }
427
+ specify { expect(CitiesIndex.indexes).to eq(['cities']) }
341
428
 
342
429
  context do
343
430
  before { CitiesIndex.reset!('2013') }
344
431
 
345
432
  specify { expect(CitiesIndex.all).to have(1).item }
346
- specify { expect(CitiesIndex.aliases).to eq([]) }
433
+ specify { expect(CitiesIndex.aliases).to eq(['cities']) }
347
434
  specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
348
435
  end
349
436
 
@@ -352,7 +439,7 @@ describe Chewy::Index::Actions do
352
439
 
353
440
  specify { expect(CitiesIndex.all).to have(1).item }
354
441
  specify { expect(CitiesIndex.aliases).to eq([]) }
355
- specify { expect(CitiesIndex.indexes).to eq([]) }
442
+ specify { expect(CitiesIndex.indexes).to eq(['cities']) }
356
443
  end
357
444
  end
358
445
 
@@ -360,14 +447,14 @@ describe Chewy::Index::Actions do
360
447
  before { CitiesIndex.reset!('2013') }
361
448
 
362
449
  specify { expect(CitiesIndex.all).to have(1).item }
363
- specify { expect(CitiesIndex.aliases).to eq([]) }
450
+ specify { expect(CitiesIndex.aliases).to eq(['cities']) }
364
451
  specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
365
452
 
366
453
  context do
367
454
  before { CitiesIndex.reset!('2014') }
368
455
 
369
456
  specify { expect(CitiesIndex.all).to have(1).item }
370
- specify { expect(CitiesIndex.aliases).to eq([]) }
457
+ specify { expect(CitiesIndex.aliases).to eq(['cities']) }
371
458
  specify { expect(CitiesIndex.indexes).to eq(['cities_2014']) }
372
459
  specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
373
460
  end
@@ -377,7 +464,7 @@ describe Chewy::Index::Actions do
377
464
 
378
465
  specify { expect(CitiesIndex.all).to have(1).item }
379
466
  specify { expect(CitiesIndex.aliases).to eq([]) }
380
- specify { expect(CitiesIndex.indexes).to eq([]) }
467
+ specify { expect(CitiesIndex.indexes).to eq(['cities']) }
381
468
  specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
382
469
  end
383
470
  end