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
@@ -4,7 +4,9 @@ describe :update_index do
4
4
  before do
5
5
  stub_index(:dummies) do
6
6
  define_type :dummy
7
- define_type :dummy2
7
+ end
8
+ stub_index(:dummies2) do
9
+ define_type :dummy
8
10
  end
9
11
  end
10
12
 
@@ -13,19 +15,18 @@ describe :update_index do
13
15
  DummiesIndex.create!
14
16
  end
15
17
 
16
- specify { expect {}.not_to update_index(DummiesIndex::Dummy) }
17
- specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex::Dummy) }
18
+ specify { expect {}.not_to update_index(DummiesIndex) }
19
+ specify { expect { DummiesIndex::Dummy.bulk body: [] }.not_to update_index(DummiesIndex) }
18
20
 
19
21
  specify do
20
- expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex::Dummy) }
22
+ expect { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex) }
21
23
  .to fail_with(/Expected index .* not to be updated, but it was with/)
22
24
  end
23
25
 
24
26
  specify do
25
27
  expect do
26
28
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
27
- DummiesIndex::Dummy2.bulk body: [{index: {_id: 43, data: {}}}]
28
- end.to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
29
+ end.to update_index(DummiesIndex).and_reindex(41, 42).only
29
30
  end
30
31
 
31
32
  context do
@@ -33,7 +34,7 @@ describe :update_index do
33
34
  expect do
34
35
  expect do
35
36
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
36
- end.not_to update_index(DummiesIndex::Dummy)
37
+ end.not_to update_index(DummiesIndex)
37
38
  end
38
39
  end
39
40
 
@@ -45,60 +46,60 @@ describe :update_index do
45
46
  specify do
46
47
  expect do
47
48
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
48
- DummiesIndex::Dummy2.bulk body: [{index: {_id: 43, data: {}}}]
49
- end.to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
50
- .and update_index(DummiesIndex::Dummy2).and_reindex(43).only
49
+ Dummies2Index::Dummy.bulk body: [{index: {_id: 43, data: {}}}]
50
+ end.to update_index(DummiesIndex).and_reindex(41, 42).only
51
+ .and update_index(Dummies2Index).and_reindex(43).only
51
52
  end
52
53
 
53
54
  context do
54
55
  let(:expectation) do
55
56
  expect do
56
57
  expect do
57
- DummiesIndex::Dummy2.bulk body: [{index: {_id: 43, data: {}}}]
58
- end.to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
59
- .and update_index(DummiesIndex::Dummy2).and_reindex(43).only
58
+ Dummies2Index::Dummy.bulk body: [{index: {_id: 43, data: {}}}]
59
+ end.to update_index(DummiesIndex).and_reindex(41, 42).only
60
+ .and update_index(Dummies2Index).and_reindex(43).only
60
61
  end
61
62
  end
62
63
 
63
- specify { expectation.to fail_matching 'Expected index `DummiesIndex::Dummy` to be updated' }
64
+ specify { expectation.to fail_matching 'Expected index `DummiesIndex` to be updated' }
64
65
  end
65
66
  end
66
67
 
67
68
  context '#only' do
68
69
  specify do
69
70
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
70
- .to update_index(DummiesIndex::Dummy).and_reindex(41, 42).only
71
+ .to update_index(DummiesIndex).and_reindex(41, 42).only
71
72
  end
72
73
  specify do
73
74
  expect do
74
75
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
75
- .to update_index(DummiesIndex::Dummy).and_reindex(41).only
76
+ .to update_index(DummiesIndex).and_reindex(41).only
76
77
  end
77
78
  .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
78
79
  end
79
80
  specify do
80
81
  expect do
81
82
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
82
- .to update_index(DummiesIndex::Dummy).and_reindex(41, times: 2).only
83
+ .to update_index(DummiesIndex).and_reindex(41, times: 2).only
83
84
  end
84
85
  .to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
85
86
  end
86
87
 
87
88
  specify do
88
89
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
89
- .to update_index(DummiesIndex::Dummy).and_delete(41, 42).only
90
+ .to update_index(DummiesIndex).and_delete(41, 42).only
90
91
  end
91
92
  specify do
92
93
  expect do
93
94
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
94
- .to update_index(DummiesIndex::Dummy).and_delete(41).only
95
+ .to update_index(DummiesIndex).and_delete(41).only
95
96
  end
96
97
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
97
98
  end
98
99
  specify do
99
100
  expect do
100
101
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
101
- .to update_index(DummiesIndex::Dummy).and_delete(41, times: 2).only
102
+ .to update_index(DummiesIndex).and_delete(41, times: 2).only
102
103
  end
103
104
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
104
105
  end
@@ -106,57 +107,57 @@ describe :update_index do
106
107
  specify do
107
108
  expect do
108
109
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
109
- .to update_index(DummiesIndex::Dummy).and_reindex(42).only
110
+ .to update_index(DummiesIndex).and_reindex(42).only
110
111
  end
111
112
  .to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also'
112
113
  end
113
114
  specify do
114
115
  expect do
115
116
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}, {delete: {_id: 41}}] }
116
- .to update_index(DummiesIndex::Dummy).and_reindex(42).only
117
+ .to update_index(DummiesIndex).and_reindex(42).only
117
118
  end
118
119
  .to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also'
119
120
  end
120
121
  specify do
121
122
  expect do
122
123
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
123
- .to update_index(DummiesIndex::Dummy).and_delete(41).only
124
+ .to update_index(DummiesIndex).and_delete(41).only
124
125
  end
125
126
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also'
126
127
  end
127
128
  specify do
128
129
  expect do
129
130
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}, {delete: {_id: 43}}] }
130
- .to update_index(DummiesIndex::Dummy).and_delete(41).only
131
+ .to update_index(DummiesIndex).and_delete(41).only
131
132
  end
132
133
  .to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also'
133
134
  end
134
135
  end
135
136
 
136
137
  context '#and_reindex' do
137
- specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex::Dummy) }
138
+ specify { expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex) }
138
139
  specify do
139
140
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}] }
140
- .to update_index(DummiesIndex::Dummy).and_reindex(42)
141
+ .to update_index(DummiesIndex).and_reindex(42)
141
142
  end
142
143
  specify do
143
144
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
144
- .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42))
145
+ .to update_index(DummiesIndex).and_reindex(double(id: 42))
145
146
  end
146
147
  specify do
147
148
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
148
- .to update_index(DummiesIndex::Dummy).and_reindex(double(id: 42), double(id: 43))
149
+ .to update_index(DummiesIndex).and_reindex(double(id: 42), double(id: 43))
149
150
  end
150
151
  specify do
151
152
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
152
- .to update_index(DummiesIndex::Dummy).and_reindex([double(id: 42), 43])
153
+ .to update_index(DummiesIndex).and_reindex([double(id: 42), 43])
153
154
  end
154
155
 
155
156
  specify do
156
157
  expect do
157
158
  expect do
158
159
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
159
- end.to update_index(DummiesIndex::Dummy).and_reindex([44, 43])
160
+ end.to update_index(DummiesIndex).and_reindex([44, 43])
160
161
  end.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
161
162
  end
162
163
 
@@ -165,7 +166,7 @@ describe :update_index do
165
166
  expect do
166
167
  expect do
167
168
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
168
- end.to update_index(DummiesIndex::Dummy).and_reindex(44, double(id: 47)) end
169
+ end.to update_index(DummiesIndex).and_reindex(44, double(id: 47)) end
169
170
  end
170
171
 
171
172
  specify { expectation.to fail_matching('Expected document with id `44` to be reindexed, but it was not') }
@@ -177,13 +178,13 @@ describe :update_index do
177
178
  expect do
178
179
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
179
180
  DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
180
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) end
181
+ end.to update_index(DummiesIndex).and_reindex(42, 44, times: 1).and_reindex(43, times: 2) end
181
182
 
182
183
  specify do
183
184
  expect do
184
185
  expect do
185
186
  DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
186
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3)
187
+ end.to update_index(DummiesIndex).and_reindex(42, times: 3)
187
188
  end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
188
189
 
189
190
  context do
@@ -192,7 +193,7 @@ describe :update_index do
192
193
  expect do
193
194
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
194
195
  DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
195
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) end
196
+ end.to update_index(DummiesIndex).and_reindex(42, times: 3).and_reindex(44, 43, times: 4) end
196
197
  end
197
198
 
198
199
  specify { expectation.to fail_matching 'Expected document with id `44` to be reindexed' }
@@ -206,18 +207,18 @@ describe :update_index do
206
207
  specify do
207
208
  expect do
208
209
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
209
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 2}) end
210
+ end.to update_index(DummiesIndex).and_reindex(42, with: {a: 2}) end
210
211
 
211
212
  specify do
212
213
  expect do
213
214
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
214
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: '1', b: 2}) end
215
+ end.to update_index(DummiesIndex).and_reindex(42, with: {a: '1', b: 2}) end
215
216
 
216
217
  specify do
217
218
  expect do
218
219
  expect do
219
220
  DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
220
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: {a: 1})
221
+ end.to update_index(DummiesIndex).and_reindex(42, with: {a: 1})
221
222
  end.to fail_matching('Expected document with id `42` to be reindexed, but it was not') end
222
223
 
223
224
  [
@@ -230,7 +231,7 @@ describe :update_index do
230
231
  specify do
231
232
  expect do
232
233
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
233
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with) end
234
+ end.to update_index(DummiesIndex).and_reindex(42, with: with) end
234
235
  end
235
236
 
236
237
  [
@@ -244,7 +245,7 @@ describe :update_index do
244
245
  expect do
245
246
  expect do
246
247
  DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: data}}]
247
- end.to update_index(DummiesIndex::Dummy).and_reindex(42, with: with)
248
+ end.to update_index(DummiesIndex).and_reindex(42, with: with)
248
249
  end.to fail_matching('Expected document with id `42` to be reindexed') end
249
250
  end
250
251
 
@@ -253,7 +254,7 @@ describe :update_index do
253
254
  expect do
254
255
  expect do
255
256
  DummiesIndex::Dummy.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
256
- end.to update_index(DummiesIndex::Dummy).and_reindex(43, times: 2, with: {a: 2}) end
257
+ end.to update_index(DummiesIndex).and_reindex(43, times: 2, with: {a: 2}) end
257
258
  end
258
259
 
259
260
  specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed' }
@@ -266,26 +267,26 @@ describe :update_index do
266
267
  context '#and_delete' do
267
268
  specify do
268
269
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
269
- .to update_index(DummiesIndex::Dummy).and_reindex(42).and_delete(double(id: 43))
270
+ .to update_index(DummiesIndex).and_reindex(42).and_delete(double(id: 43))
270
271
  end
271
272
  specify do
272
273
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
273
- .to update_index(DummiesIndex::Dummy).and_delete(42).and_delete(double(id: 43))
274
+ .to update_index(DummiesIndex).and_delete(42).and_delete(double(id: 43))
274
275
  end
275
276
  specify do
276
277
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
277
- .to update_index(DummiesIndex::Dummy).and_delete(42, double(id: 43))
278
+ .to update_index(DummiesIndex).and_delete(42, double(id: 43))
278
279
  end
279
280
  specify do
280
281
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
281
- .to update_index(DummiesIndex::Dummy).and_delete([43, double(id: 42)])
282
+ .to update_index(DummiesIndex).and_delete([43, double(id: 42)])
282
283
  end
283
284
 
284
285
  context do
285
286
  let(:expectation) do
286
287
  expect do
287
288
  expect { DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
288
- .to update_index(DummiesIndex::Dummy).and_reindex(43).and_delete(double(id: 42))
289
+ .to update_index(DummiesIndex).and_reindex(43).and_delete(double(id: 42))
289
290
  end
290
291
  end
291
292
 
@@ -297,7 +298,7 @@ describe :update_index do
297
298
  let(:expectation) do
298
299
  expect do
299
300
  expect { DummiesIndex::Dummy.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
300
- .to update_index(DummiesIndex::Dummy).and_delete(44, times: 2).and_delete(double(id: 42), times: 3)
301
+ .to update_index(DummiesIndex).and_delete(44, times: 2).and_delete(double(id: 42), times: 3)
301
302
  end
302
303
  end
303
304
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Chewy::Runtime do
4
4
  describe '.version' do
5
5
  specify { expect(described_class.version).to be_a(described_class::Version) }
6
- specify { expect(described_class.version).to be >= '2.4' }
7
- specify { expect(described_class.version).to be < '6.0' }
6
+ specify { expect(described_class.version).to be >= '7.0' }
7
+ specify { expect(described_class.version).to be < '8.0' }
8
8
  end
9
9
  end
@@ -37,7 +37,6 @@ describe Chewy::Search::Loader do
37
37
  specify { expect(subject.derive_type('cities', 'city')).to eq(CitiesIndex::City) }
38
38
  specify { expect(subject.derive_type('cities_suffix', 'city')).to eq(CitiesIndex::City) }
39
39
 
40
- specify { expect { subject.derive_type('cities', 'place') }.to raise_error(Chewy::UnderivableType) }
41
40
  specify { expect { subject.derive_type('whatever', 'city') }.to raise_error(Chewy::UnderivableType) }
42
41
  specify { expect { subject.derive_type('citiessuffix', 'city') }.to raise_error(Chewy::UnderivableType) }
43
42
 
@@ -54,21 +53,6 @@ describe Chewy::Search::Loader do
54
53
 
55
54
  specify { expect(subject.load(hits)).to eq([*cities, *countries]) }
56
55
 
57
- context do
58
- let(:options) { {only: 'city'} }
59
- specify { expect(subject.load(hits)).to eq([*cities, nil, nil]) }
60
- end
61
-
62
- context do
63
- let(:options) { {except: 'city'} }
64
- specify { expect(subject.load(hits)).to eq([nil, nil, *countries]) }
65
- end
66
-
67
- context do
68
- let(:options) { {except: %w[city country]} }
69
- specify { expect(subject.load(hits)).to eq([nil, nil, nil, nil]) }
70
- end
71
-
72
56
  context 'scopes', :active_record do
73
57
  context do
74
58
  let(:options) { {scope: -> { where('rating > 2') }} }
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Chewy::Search::Parameters::Indices do
4
+ before do
5
+ stub_index(:first) do
6
+ define_type :one
7
+ end
8
+
9
+ stub_index(:second) do
10
+ define_type :three
11
+ end
12
+
13
+ stub_index(:third)
14
+ end
15
+
16
+ subject { described_class.new(indices: [FirstIndex, SecondIndex]) }
17
+
18
+ describe '#initialize' do
19
+ specify { expect(described_class.new.value).to eq(indices: []) }
20
+ specify { expect(described_class.new(nil).value).to eq(indices: []) }
21
+ specify { expect(described_class.new(foo: :whatever).value).to eq(indices: []) }
22
+ specify { expect(subject.value).to eq(indices: [FirstIndex, SecondIndex]) }
23
+ end
24
+
25
+ describe '#replace!' do
26
+ specify do
27
+ expect { subject.replace!(nil) }
28
+ .to change { subject.value }
29
+ .from(indices: [FirstIndex, SecondIndex])
30
+ .to(indices: [])
31
+ end
32
+
33
+ specify do
34
+ expect { subject.replace!(indices: SecondIndex) }
35
+ .to change { subject.value }
36
+ .from(indices: [FirstIndex, SecondIndex])
37
+ .to(indices: [SecondIndex])
38
+ end
39
+ end
40
+
41
+ describe '#update!' do
42
+ specify do
43
+ expect { subject.update!(nil) }
44
+ .not_to change { subject.value }
45
+ end
46
+
47
+ specify do
48
+ expect { subject.update!(indices: ThirdIndex) }
49
+ .to change { subject.value }
50
+ .from(indices: [FirstIndex, SecondIndex])
51
+ .to(indices: [FirstIndex, SecondIndex, ThirdIndex])
52
+ end
53
+ end
54
+
55
+ describe '#merge!' do
56
+ specify do
57
+ expect { subject.merge!(described_class.new) }
58
+ .not_to change { subject.value }
59
+ end
60
+
61
+ specify do
62
+ expect { subject.merge!(described_class.new(indices: SecondIndex)) }
63
+ .not_to change { subject.value }
64
+ end
65
+ end
66
+
67
+ describe '#render' do
68
+ specify { expect(described_class.new.render).to eq({}) }
69
+ specify do
70
+ expect(described_class.new(
71
+ indices: FirstIndex
72
+ ).render).to eq(index: %w[first])
73
+ end
74
+ specify do
75
+ expect(described_class.new(
76
+ indices: :whatever
77
+ ).render).to eq(index: %w[whatever])
78
+ end
79
+ specify do
80
+ expect(described_class.new(
81
+ indices: [FirstIndex, :whatever]
82
+ ).render).to eq(index: %w[first whatever])
83
+ end
84
+ end
85
+
86
+ describe '#==' do
87
+ specify { expect(described_class.new).to eq(described_class.new) }
88
+ specify do
89
+ expect(described_class.new(indices: :first))
90
+ .to eq(described_class.new(indices: FirstIndex))
91
+ end
92
+ specify do
93
+ expect(described_class.new(indices: FirstIndex))
94
+ .to eq(described_class.new(indices: FirstIndex))
95
+ end
96
+ end
97
+
98
+ describe '#indices' do
99
+ specify do
100
+ expect(described_class.new(
101
+ indices: [FirstIndex, :whatever]
102
+ ).indices).to contain_exactly(FirstIndex)
103
+ end
104
+ end
105
+ end