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,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
@@ -429,6 +516,12 @@ describe Chewy::Index::Actions do
429
516
  expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
430
517
  expect(CitiesIndex.reset!(suffix)).to eq(true)
431
518
  end
519
+
520
+ specify 'uses empty index settings if not defined' do
521
+ allow(Chewy).to receive(:wait_for_status).and_return(nil)
522
+ allow(CitiesIndex).to receive(:settings_hash).and_return({})
523
+ expect(CitiesIndex.reset!(suffix)).to eq(true)
524
+ end
432
525
  end
433
526
  end
434
527
 
@@ -478,7 +571,7 @@ describe Chewy::Index::Actions do
478
571
  end
479
572
  end
480
573
 
481
- context 'applying journal' do
574
+ xcontext 'applying journal' do
482
575
  before do
483
576
  stub_index(:cities) do
484
577
  define_type City do
@@ -494,23 +587,49 @@ describe Chewy::Index::Actions do
494
587
 
495
588
  let(:parallel_update) do
496
589
  Thread.new do
590
+ p 'start parallel'
497
591
  sleep(1.5)
498
592
  cities.first.update(name: 'NewName1', rating: 0)
499
593
  cities.last.update(name: 'NewName3', rating: 0)
500
594
  CitiesIndex::City.import!([cities.first, cities.last], journal: true)
595
+ p 'end parallel'
501
596
  end
502
597
  end
503
598
 
504
599
  specify 'with journal application' do
505
- parallel_update
506
- CitiesIndex.reset!('suffix')
600
+ cities
601
+ p 'cities created1'
602
+ ::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
603
+ [
604
+ parallel_update,
605
+ Thread.new do
606
+ p 'start reset1'
607
+ CitiesIndex.reset!('suffix')
608
+ p 'end reset1'
609
+ end
610
+ ].map(&:join)
611
+ ::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
612
+ p 'expect1'
507
613
  expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
614
+ p 'end expect1'
508
615
  end
509
616
 
510
617
  specify 'without journal application' do
511
- parallel_update
512
- CitiesIndex.reset!('suffix', apply_journal: false)
618
+ cities
619
+ p 'cities created2'
620
+ ::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
621
+ [
622
+ parallel_update,
623
+ Thread.new do
624
+ p 'start reset2'
625
+ CitiesIndex.reset!('suffix', apply_journal: false)
626
+ p 'end reset2'
627
+ end
628
+ ].map(&:join)
629
+ ::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
630
+ p 'expect2'
513
631
  expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
632
+ p 'end expect2'
514
633
  end
515
634
  end
516
635