chewy 6.0.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.github/dependabot.yml +42 -0
- data/.github/workflows/ruby.yml +60 -0
- data/.rubocop.yml +16 -8
- data/.rubocop_todo.yml +110 -22
- data/CHANGELOG.md +396 -105
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +4 -10
- data/Guardfile +3 -1
- data/README.md +497 -275
- data/chewy.gemspec +5 -20
- data/gemfiles/base.gemfile +12 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +10 -15
- data/gemfiles/rails.7.0.activerecord.gemfile +14 -0
- data/gemfiles/rails.7.1.activerecord.gemfile +14 -0
- data/lib/chewy/config.rb +60 -52
- data/lib/chewy/elastic_client.rb +31 -0
- data/lib/chewy/errors.rb +7 -10
- data/lib/chewy/fields/base.rb +79 -13
- data/lib/chewy/fields/root.rb +4 -14
- data/lib/chewy/index/actions.rb +54 -37
- data/lib/chewy/{type → index}/adapter/active_record.rb +30 -6
- data/lib/chewy/{type → index}/adapter/base.rb +2 -3
- data/lib/chewy/{type → index}/adapter/object.rb +27 -31
- data/lib/chewy/{type → index}/adapter/orm.rb +17 -18
- data/lib/chewy/index/aliases.rb +14 -5
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/{type → index}/import/bulk_request.rb +6 -7
- data/lib/chewy/{type → index}/import/journal_builder.rb +11 -12
- data/lib/chewy/{type → index}/import/routine.rb +18 -17
- data/lib/chewy/{type → index}/import.rb +76 -32
- data/lib/chewy/{type → index}/mapping.rb +29 -34
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/specification.rb +1 -0
- data/lib/chewy/{type → index}/syncer.rb +59 -59
- data/lib/chewy/{type → index}/witchcraft.rb +11 -7
- data/lib/chewy/{type → index}/wrapper.rb +2 -2
- data/lib/chewy/index.rb +67 -94
- data/lib/chewy/journal.rb +25 -14
- data/lib/chewy/log_subscriber.rb +5 -1
- data/lib/chewy/minitest/helpers.rb +86 -13
- data/lib/chewy/minitest/search_index_receiver.rb +24 -26
- data/lib/chewy/railtie.rb +6 -20
- data/lib/chewy/rake_helper.rb +169 -113
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +55 -44
- data/lib/chewy/rspec.rb +2 -0
- data/lib/chewy/runtime/version.rb +1 -1
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +19 -41
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +2 -2
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +13 -58
- data/lib/chewy/search/parameters/knn.rb +16 -0
- data/lib/chewy/search/parameters/order.rb +6 -19
- data/lib/chewy/search/parameters/source.rb +5 -1
- data/lib/chewy/search/parameters/storage.rb +1 -1
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters.rb +6 -4
- data/lib/chewy/search/query_proxy.rb +9 -2
- data/lib/chewy/search/request.rb +169 -134
- data/lib/chewy/search/response.rb +5 -5
- data/lib/chewy/search/scoping.rb +7 -8
- data/lib/chewy/search/scrolling.rb +13 -13
- data/lib/chewy/search.rb +9 -19
- data/lib/chewy/stash.rb +19 -30
- data/lib/chewy/strategy/active_job.rb +1 -1
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +10 -0
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +168 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +76 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +30 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +2 -1
- data/lib/chewy/strategy.rb +6 -19
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +39 -86
- data/lib/generators/chewy/install_generator.rb +1 -1
- data/lib/tasks/chewy.rake +36 -32
- data/migration_guide.md +46 -8
- data/spec/chewy/config_spec.rb +16 -41
- data/spec/chewy/elastic_client_spec.rb +26 -0
- data/spec/chewy/fields/base_spec.rb +432 -147
- data/spec/chewy/fields/root_spec.rb +20 -28
- data/spec/chewy/fields/time_fields_spec.rb +5 -5
- data/spec/chewy/index/actions_spec.rb +368 -59
- data/spec/chewy/{type → index}/adapter/active_record_spec.rb +156 -40
- data/spec/chewy/{type → index}/adapter/object_spec.rb +21 -6
- data/spec/chewy/index/aliases_spec.rb +3 -3
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/{type → index}/import/bulk_request_spec.rb +5 -12
- data/spec/chewy/{type → index}/import/journal_builder_spec.rb +9 -19
- data/spec/chewy/{type → index}/import/routine_spec.rb +19 -19
- data/spec/chewy/{type → index}/import_spec.rb +164 -98
- data/spec/chewy/index/mapping_spec.rb +135 -0
- data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
- data/spec/chewy/index/observe/callback_spec.rb +139 -0
- data/spec/chewy/index/observe_spec.rb +143 -0
- data/spec/chewy/index/settings_spec.rb +3 -1
- data/spec/chewy/index/specification_spec.rb +20 -30
- data/spec/chewy/{type → index}/syncer_spec.rb +14 -19
- data/spec/chewy/{type → index}/witchcraft_spec.rb +20 -22
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +60 -105
- data/spec/chewy/journal_spec.rb +25 -74
- data/spec/chewy/minitest/helpers_spec.rb +123 -15
- data/spec/chewy/minitest/search_index_receiver_spec.rb +28 -30
- data/spec/chewy/multi_search_spec.rb +4 -5
- data/spec/chewy/rake_helper_spec.rb +315 -55
- data/spec/chewy/rspec/build_query_spec.rb +34 -0
- data/spec/chewy/rspec/helpers_spec.rb +61 -0
- data/spec/chewy/rspec/update_index_spec.rb +74 -71
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +19 -53
- data/spec/chewy/search/pagination/kaminari_examples.rb +4 -6
- data/spec/chewy/search/pagination/kaminari_spec.rb +2 -2
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +26 -117
- data/spec/chewy/search/parameters/knn_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +18 -11
- data/spec/chewy/search/parameters/query_storage_examples.rb +67 -21
- data/spec/chewy/search/parameters/search_after_spec.rb +4 -1
- data/spec/chewy/search/parameters/source_spec.rb +8 -2
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +18 -4
- data/spec/chewy/search/query_proxy_spec.rb +68 -17
- data/spec/chewy/search/request_spec.rb +292 -110
- data/spec/chewy/search/response_spec.rb +12 -12
- data/spec/chewy/search/scrolling_spec.rb +10 -17
- data/spec/chewy/search_spec.rb +40 -34
- data/spec/chewy/stash_spec.rb +9 -21
- data/spec/chewy/strategy/active_job_spec.rb +16 -16
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +9 -10
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +208 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +12 -12
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +24 -107
- data/spec/spec_helper.rb +3 -22
- data/spec/support/active_record.rb +25 -7
- metadata +78 -339
- data/.circleci/config.yml +0 -240
- data/Appraisals +0 -81
- data/gemfiles/rails.5.2.activerecord.gemfile +0 -17
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +0 -17
- data/gemfiles/rails.6.0.activerecord.gemfile +0 -17
- data/gemfiles/sequel.4.45.gemfile +0 -11
- data/lib/chewy/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -91
- data/lib/chewy/search/pagination/will_paginate.rb +0 -43
- data/lib/chewy/search/parameters/types.rb +0 -20
- data/lib/chewy/strategy/resque.rb +0 -27
- data/lib/chewy/strategy/shoryuken.rb +0 -40
- data/lib/chewy/type/actions.rb +0 -43
- data/lib/chewy/type/adapter/mongoid.rb +0 -67
- data/lib/chewy/type/adapter/sequel.rb +0 -93
- data/lib/chewy/type/crutch.rb +0 -32
- data/lib/chewy/type/import/bulk_builder.rb +0 -122
- data/lib/chewy/type/observe.rb +0 -82
- data/lib/chewy/type.rb +0 -120
- data/lib/sequel/plugins/chewy_observe.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_examples.rb +0 -63
- data/spec/chewy/search/pagination/will_paginate_spec.rb +0 -23
- data/spec/chewy/search/parameters/types_spec.rb +0 -5
- data/spec/chewy/strategy/resque_spec.rb +0 -46
- data/spec/chewy/strategy/shoryuken_spec.rb +0 -70
- data/spec/chewy/type/actions_spec.rb +0 -50
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -372
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -472
- data/spec/chewy/type/import/bulk_builder_spec.rb +0 -194
- data/spec/chewy/type/mapping_spec.rb +0 -175
- data/spec/chewy/type/observe_spec.rb +0 -137
- data/spec/chewy/type/wrapper_spec.rb +0 -100
- data/spec/chewy/type_spec.rb +0 -55
- data/spec/support/mongoid.rb +0 -93
- data/spec/support/sequel.rb +0 -80
@@ -3,10 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe :update_index do
|
4
4
|
before do
|
5
5
|
stub_index(:dummies) do
|
6
|
-
define_type :dummy
|
7
6
|
end
|
8
7
|
stub_index(:dummies2) do
|
9
|
-
define_type :dummy
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -16,16 +14,16 @@ describe :update_index do
|
|
16
14
|
end
|
17
15
|
|
18
16
|
specify { expect {}.not_to update_index(DummiesIndex) }
|
19
|
-
specify { expect { DummiesIndex
|
17
|
+
specify { expect { DummiesIndex.bulk body: [] }.not_to update_index(DummiesIndex) }
|
20
18
|
|
21
19
|
specify do
|
22
|
-
expect { expect { DummiesIndex
|
20
|
+
expect { expect { DummiesIndex.bulk body: [{index: {_id: 42}}] }.not_to update_index(DummiesIndex) }
|
23
21
|
.to fail_with(/Expected index .* not to be updated, but it was with/)
|
24
22
|
end
|
25
23
|
|
26
24
|
specify do
|
27
25
|
expect do
|
28
|
-
DummiesIndex
|
26
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
29
27
|
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
30
28
|
end
|
31
29
|
|
@@ -33,7 +31,7 @@ describe :update_index do
|
|
33
31
|
let(:expectation) do
|
34
32
|
expect do
|
35
33
|
expect do
|
36
|
-
DummiesIndex
|
34
|
+
DummiesIndex.bulk body: [{index: {_id: 42}}, {index: {_id: 41}}, {index: {_id: 42}}]
|
37
35
|
end.not_to update_index(DummiesIndex)
|
38
36
|
end
|
39
37
|
end
|
@@ -45,8 +43,8 @@ describe :update_index do
|
|
45
43
|
context 'compound matchers' do
|
46
44
|
specify do
|
47
45
|
expect do
|
48
|
-
DummiesIndex
|
49
|
-
Dummies2Index
|
46
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
47
|
+
Dummies2Index.bulk body: [{index: {_id: 43, data: {}}}]
|
50
48
|
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
51
49
|
.and update_index(Dummies2Index).and_reindex(43).only
|
52
50
|
end
|
@@ -55,7 +53,7 @@ describe :update_index do
|
|
55
53
|
let(:expectation) do
|
56
54
|
expect do
|
57
55
|
expect do
|
58
|
-
Dummies2Index
|
56
|
+
Dummies2Index.bulk body: [{index: {_id: 43, data: {}}}]
|
59
57
|
end.to update_index(DummiesIndex).and_reindex(41, 42).only
|
60
58
|
.and update_index(Dummies2Index).and_reindex(43).only
|
61
59
|
end
|
@@ -67,96 +65,91 @@ describe :update_index do
|
|
67
65
|
|
68
66
|
context '#only' do
|
69
67
|
specify do
|
70
|
-
expect { DummiesIndex
|
68
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
71
69
|
.to update_index(DummiesIndex).and_reindex(41, 42).only
|
72
70
|
end
|
73
71
|
specify do
|
74
72
|
expect do
|
75
|
-
expect { DummiesIndex
|
73
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
76
74
|
.to update_index(DummiesIndex).and_reindex(41).only
|
77
|
-
end
|
78
|
-
.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
75
|
+
end.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
79
76
|
end
|
80
77
|
specify do
|
81
78
|
expect do
|
82
|
-
expect { DummiesIndex
|
79
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}] }
|
83
80
|
.to update_index(DummiesIndex).and_reindex(41, times: 2).only
|
84
|
-
end
|
85
|
-
.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
81
|
+
end.to fail_matching 'to update documents ["41"] only, but ["42"] was updated also'
|
86
82
|
end
|
87
83
|
|
88
84
|
specify do
|
89
|
-
expect { DummiesIndex
|
85
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
90
86
|
.to update_index(DummiesIndex).and_delete(41, 42).only
|
91
87
|
end
|
92
88
|
specify do
|
93
89
|
expect do
|
94
|
-
expect { DummiesIndex
|
90
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
95
91
|
.to update_index(DummiesIndex).and_delete(41).only
|
96
|
-
end
|
97
|
-
.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
92
|
+
end.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
98
93
|
end
|
99
94
|
specify do
|
100
95
|
expect do
|
101
|
-
expect { DummiesIndex
|
96
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 41}}] }
|
102
97
|
.to update_index(DummiesIndex).and_delete(41, times: 2).only
|
103
|
-
end
|
104
|
-
.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
98
|
+
end.to fail_matching 'to delete documents ["41"] only, but ["42"] was deleted also'
|
105
99
|
end
|
106
100
|
|
107
101
|
specify do
|
108
102
|
expect do
|
109
|
-
expect { DummiesIndex
|
103
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
|
110
104
|
.to update_index(DummiesIndex).and_reindex(42).only
|
111
|
-
end
|
112
|
-
.to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also'
|
105
|
+
end.to fail_matching 'to update documents ["42"] only, but ["41"] was deleted also'
|
113
106
|
end
|
114
107
|
specify do
|
115
108
|
expect do
|
116
|
-
expect
|
117
|
-
.
|
118
|
-
|
119
|
-
.to
|
109
|
+
expect do
|
110
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}},
|
111
|
+
{delete: {_id: 41}}]
|
112
|
+
end.to update_index(DummiesIndex).and_reindex(42).only
|
113
|
+
end.to fail_matching 'to update documents ["42"] only, but ["43"] was updated and ["41"] was deleted also'
|
120
114
|
end
|
121
115
|
specify do
|
122
116
|
expect do
|
123
|
-
expect { DummiesIndex
|
117
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}] }
|
124
118
|
.to update_index(DummiesIndex).and_delete(41).only
|
125
|
-
end
|
126
|
-
.to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also'
|
119
|
+
end.to fail_matching 'to delete documents ["41"] only, but ["42"] was updated also'
|
127
120
|
end
|
128
121
|
specify do
|
129
122
|
expect do
|
130
|
-
expect
|
131
|
-
.
|
132
|
-
|
133
|
-
|
123
|
+
expect do
|
124
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 41}}, {delete: {_id: 43}}]
|
125
|
+
end.to update_index(DummiesIndex).and_delete(41).only
|
126
|
+
end.to fail_matching 'to delete documents ["41"] only, but ["42"] was updated and ["43"] was deleted also'
|
134
127
|
end
|
135
128
|
end
|
136
129
|
|
137
130
|
context '#and_reindex' do
|
138
|
-
specify { expect { DummiesIndex
|
131
|
+
specify { expect { DummiesIndex.bulk body: [{index: {_id: 42}}] }.to update_index(DummiesIndex) }
|
139
132
|
specify do
|
140
|
-
expect { DummiesIndex
|
133
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}] }
|
141
134
|
.to update_index(DummiesIndex).and_reindex(42)
|
142
135
|
end
|
143
136
|
specify do
|
144
|
-
expect { DummiesIndex
|
137
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
145
138
|
.to update_index(DummiesIndex).and_reindex(double(id: 42))
|
146
139
|
end
|
147
140
|
specify do
|
148
|
-
expect { DummiesIndex
|
141
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
149
142
|
.to update_index(DummiesIndex).and_reindex(double(id: 42), double(id: 43))
|
150
143
|
end
|
151
144
|
specify do
|
152
|
-
expect { DummiesIndex
|
145
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}] }
|
153
146
|
.to update_index(DummiesIndex).and_reindex([double(id: 42), 43])
|
154
147
|
end
|
155
148
|
|
156
149
|
specify do
|
157
150
|
expect do
|
158
151
|
expect do
|
159
|
-
DummiesIndex
|
152
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
160
153
|
end.to update_index(DummiesIndex).and_reindex([44, 43])
|
161
154
|
end.to fail_matching 'Expected document with id `44` to be reindexed, but it was not'
|
162
155
|
end
|
@@ -165,8 +158,9 @@ describe :update_index do
|
|
165
158
|
let(:expectation) do
|
166
159
|
expect do
|
167
160
|
expect do
|
168
|
-
DummiesIndex
|
169
|
-
end.to update_index(DummiesIndex).and_reindex(44, double(id: 47))
|
161
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
162
|
+
end.to update_index(DummiesIndex).and_reindex(44, double(id: 47))
|
163
|
+
end
|
170
164
|
end
|
171
165
|
|
172
166
|
specify { expectation.to fail_matching('Expected document with id `44` to be reindexed, but it was not') }
|
@@ -176,24 +170,27 @@ describe :update_index do
|
|
176
170
|
context ':times' do
|
177
171
|
specify do
|
178
172
|
expect do
|
179
|
-
DummiesIndex
|
180
|
-
DummiesIndex
|
181
|
-
end.to update_index(DummiesIndex).and_reindex(42, 44, times: 1).and_reindex(43, times: 2)
|
173
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
174
|
+
DummiesIndex.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
|
175
|
+
end.to update_index(DummiesIndex).and_reindex(42, 44, times: 1).and_reindex(43, times: 2)
|
176
|
+
end
|
182
177
|
|
183
178
|
specify do
|
184
179
|
expect do
|
185
180
|
expect do
|
186
|
-
DummiesIndex
|
181
|
+
DummiesIndex.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
|
187
182
|
end.to update_index(DummiesIndex).and_reindex(42, times: 3)
|
188
|
-
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not')
|
183
|
+
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not')
|
184
|
+
end
|
189
185
|
|
190
186
|
context do
|
191
187
|
let(:expectation) do
|
192
188
|
expect do
|
193
189
|
expect do
|
194
|
-
DummiesIndex
|
195
|
-
DummiesIndex
|
196
|
-
end.to update_index(DummiesIndex).and_reindex(42, times: 3).and_reindex(44, 43, times: 4)
|
190
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 43, data: {}}}]
|
191
|
+
DummiesIndex.bulk body: [{index: {_id: 43, data: {}}}, {index: {_id: 44, data: {}}}]
|
192
|
+
end.to update_index(DummiesIndex).and_reindex(42, times: 3).and_reindex(44, 43, times: 4)
|
193
|
+
end
|
197
194
|
end
|
198
195
|
|
199
196
|
specify { expectation.to fail_matching 'Expected document with id `44` to be reindexed' }
|
@@ -206,20 +203,23 @@ describe :update_index do
|
|
206
203
|
context ':with' do
|
207
204
|
specify do
|
208
205
|
expect do
|
209
|
-
DummiesIndex
|
210
|
-
end.to update_index(DummiesIndex).and_reindex(42, with: {a: 2})
|
206
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
|
207
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: {a: 2})
|
208
|
+
end
|
211
209
|
|
212
210
|
specify do
|
213
211
|
expect do
|
214
|
-
DummiesIndex
|
215
|
-
end.to update_index(DummiesIndex).and_reindex(42, with: {a: '1', b: 2})
|
212
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: {a: '1'}}}, {index: {_id: 42, data: {'b' => 2}}}]
|
213
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: {a: '1', b: 2})
|
214
|
+
end
|
216
215
|
|
217
216
|
specify do
|
218
217
|
expect do
|
219
218
|
expect do
|
220
|
-
DummiesIndex
|
219
|
+
DummiesIndex.bulk body: [{index: {_id: 43, data: {a: '1'}}}]
|
221
220
|
end.to update_index(DummiesIndex).and_reindex(42, with: {a: 1})
|
222
|
-
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not')
|
221
|
+
end.to fail_matching('Expected document with id `42` to be reindexed, but it was not')
|
222
|
+
end
|
223
223
|
|
224
224
|
[
|
225
225
|
[{a: %w[one two]}, {a: %w[one two]}],
|
@@ -230,8 +230,9 @@ describe :update_index do
|
|
230
230
|
].each do |(data, with)|
|
231
231
|
specify do
|
232
232
|
expect do
|
233
|
-
DummiesIndex
|
234
|
-
end.to update_index(DummiesIndex).and_reindex(42, with: with)
|
233
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: data}}]
|
234
|
+
end.to update_index(DummiesIndex).and_reindex(42, with: with)
|
235
|
+
end
|
235
236
|
end
|
236
237
|
|
237
238
|
[
|
@@ -244,17 +245,19 @@ describe :update_index do
|
|
244
245
|
specify do
|
245
246
|
expect do
|
246
247
|
expect do
|
247
|
-
DummiesIndex
|
248
|
+
DummiesIndex.bulk body: [{index: {_id: 42, data: data}}]
|
248
249
|
end.to update_index(DummiesIndex).and_reindex(42, with: with)
|
249
|
-
end.to fail_matching('Expected document with id `42` to be reindexed')
|
250
|
+
end.to fail_matching('Expected document with id `42` to be reindexed')
|
251
|
+
end
|
250
252
|
end
|
251
253
|
|
252
254
|
context do
|
253
255
|
let(:expectation) do
|
254
256
|
expect do
|
255
257
|
expect do
|
256
|
-
DummiesIndex
|
257
|
-
end.to update_index(DummiesIndex).and_reindex(43, times: 2, with: {a: 2})
|
258
|
+
DummiesIndex.bulk body: [{index: {_id: 43, data: {a: '1'}}}, {index: {_id: 42, data: {'a' => 2}}}]
|
259
|
+
end.to update_index(DummiesIndex).and_reindex(43, times: 2, with: {a: 2})
|
260
|
+
end
|
258
261
|
end
|
259
262
|
|
260
263
|
specify { expectation.to fail_matching 'Expected document with id `43` to be reindexed' }
|
@@ -266,26 +269,26 @@ describe :update_index do
|
|
266
269
|
|
267
270
|
context '#and_delete' do
|
268
271
|
specify do
|
269
|
-
expect { DummiesIndex
|
272
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
|
270
273
|
.to update_index(DummiesIndex).and_reindex(42).and_delete(double(id: 43))
|
271
274
|
end
|
272
275
|
specify do
|
273
|
-
expect { DummiesIndex
|
276
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
274
277
|
.to update_index(DummiesIndex).and_delete(42).and_delete(double(id: 43))
|
275
278
|
end
|
276
279
|
specify do
|
277
|
-
expect { DummiesIndex
|
280
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
278
281
|
.to update_index(DummiesIndex).and_delete(42, double(id: 43))
|
279
282
|
end
|
280
283
|
specify do
|
281
|
-
expect { DummiesIndex
|
284
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42}}, {delete: {_id: 43}}] }
|
282
285
|
.to update_index(DummiesIndex).and_delete([43, double(id: 42)])
|
283
286
|
end
|
284
287
|
|
285
288
|
context do
|
286
289
|
let(:expectation) do
|
287
290
|
expect do
|
288
|
-
expect { DummiesIndex
|
291
|
+
expect { DummiesIndex.bulk body: [{index: {_id: 42, data: {}}}, {delete: {_id: 43}}] }
|
289
292
|
.to update_index(DummiesIndex).and_reindex(43).and_delete(double(id: 42))
|
290
293
|
end
|
291
294
|
end
|
@@ -297,7 +300,7 @@ describe :update_index do
|
|
297
300
|
context do
|
298
301
|
let(:expectation) do
|
299
302
|
expect do
|
300
|
-
expect { DummiesIndex
|
303
|
+
expect { DummiesIndex.bulk body: [{delete: {_id: 42, data: {}}}, {delete: {_id: 42}}] }
|
301
304
|
.to update_index(DummiesIndex).and_delete(44, times: 2).and_delete(double(id: 42), times: 3)
|
302
305
|
end
|
303
306
|
end
|
data/spec/chewy/runtime_spec.rb
CHANGED
@@ -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 >= '
|
7
|
-
specify { expect(described_class.version).to be < '
|
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
|
@@ -8,17 +8,15 @@ describe Chewy::Search::Loader do
|
|
8
8
|
stub_model(:country)
|
9
9
|
|
10
10
|
stub_index(:cities) do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
11
|
+
index_scope City
|
12
|
+
field :name
|
13
|
+
field :rating, type: 'integer'
|
15
14
|
end
|
16
15
|
|
17
16
|
stub_index(:countries) do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
17
|
+
index_scope Country
|
18
|
+
field :name
|
19
|
+
field :rating, type: 'integer'
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -33,19 +31,18 @@ describe Chewy::Search::Loader do
|
|
33
31
|
let(:options) { {} }
|
34
32
|
subject { described_class.new(indexes: [CitiesIndex, CountriesIndex], **options) }
|
35
33
|
|
36
|
-
describe '#
|
37
|
-
specify { expect(subject.
|
38
|
-
specify { expect(subject.
|
34
|
+
describe '#derive_index' do
|
35
|
+
specify { expect(subject.derive_index('cities')).to eq(CitiesIndex) }
|
36
|
+
specify { expect(subject.derive_index('cities_suffix')).to eq(CitiesIndex) }
|
39
37
|
|
40
|
-
specify { expect { subject.
|
41
|
-
specify { expect { subject.
|
42
|
-
specify { expect { subject.derive_type('citiessuffix', 'city') }.to raise_error(Chewy::UnderivableType) }
|
38
|
+
specify { expect { subject.derive_index('whatever') }.to raise_error(Chewy::UndefinedIndex) }
|
39
|
+
specify { expect { subject.derive_index('citiessuffix') }.to raise_error(Chewy::UndefinedIndex) }
|
43
40
|
|
44
41
|
context do
|
45
42
|
before { CitiesIndex.index_name :boro_goves }
|
46
43
|
|
47
|
-
specify { expect(subject.
|
48
|
-
specify { expect(subject.
|
44
|
+
specify { expect(subject.derive_index('boro_goves')).to eq(CitiesIndex) }
|
45
|
+
specify { expect(subject.derive_index('boro_goves_suffix')).to eq(CitiesIndex) }
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
@@ -54,21 +51,6 @@ describe Chewy::Search::Loader do
|
|
54
51
|
|
55
52
|
specify { expect(subject.load(hits)).to eq([*cities, *countries]) }
|
56
53
|
|
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
54
|
context 'scopes', :active_record do
|
73
55
|
context do
|
74
56
|
let(:options) { {scope: -> { where('rating > 2') }} }
|
@@ -76,19 +58,7 @@ describe Chewy::Search::Loader do
|
|
76
58
|
end
|
77
59
|
|
78
60
|
context do
|
79
|
-
let(:options) { {
|
80
|
-
specify { expect(subject.load(hits)).to eq([*cities, nil, countries.last]) }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'scopes', :mongoid do
|
85
|
-
context do
|
86
|
-
let(:options) { {scope: -> { where(:rating.gt => 2) }} }
|
87
|
-
specify { expect(subject.load(hits)).to eq([nil, nil, nil, countries.last]) }
|
88
|
-
end
|
89
|
-
|
90
|
-
context do
|
91
|
-
let(:options) { {country: {scope: -> { where(:rating.gt => 2) }}} }
|
61
|
+
let(:options) { {countries: {scope: -> { where('rating > 2') }}} }
|
92
62
|
specify { expect(subject.load(hits)).to eq([*cities, nil, countries.last]) }
|
93
63
|
end
|
94
64
|
end
|
@@ -96,21 +66,17 @@ describe Chewy::Search::Loader do
|
|
96
66
|
context 'objects' do
|
97
67
|
before do
|
98
68
|
stub_index(:cities) do
|
99
|
-
|
100
|
-
|
101
|
-
field :rating, type: 'integer'
|
102
|
-
end
|
69
|
+
field :name
|
70
|
+
field :rating, type: 'integer'
|
103
71
|
end
|
104
72
|
|
105
73
|
stub_index(:countries) do
|
106
|
-
|
107
|
-
|
108
|
-
field :rating, type: 'integer'
|
109
|
-
end
|
74
|
+
field :name
|
75
|
+
field :rating, type: 'integer'
|
110
76
|
end
|
111
77
|
end
|
112
78
|
|
113
|
-
specify { expect(subject.load(hits).map(&:class).uniq).to eq([CitiesIndex
|
79
|
+
specify { expect(subject.load(hits).map(&:class).uniq).to eq([CitiesIndex, CountriesIndex]) }
|
114
80
|
specify { expect(subject.load(hits).map(&:rating)).to eq([*cities, *countries].map(&:rating)) }
|
115
81
|
end
|
116
82
|
end
|
@@ -5,10 +5,8 @@ shared_examples :kaminari do |request_base_class|
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_index(:products) do
|
8
|
-
|
9
|
-
|
10
|
-
field :age, type: 'integer'
|
11
|
-
end
|
8
|
+
field :name
|
9
|
+
field :age, type: 'integer'
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -25,8 +23,8 @@ shared_examples :kaminari do |request_base_class|
|
|
25
23
|
context do
|
26
24
|
let(:data) { Array.new(10) { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
27
25
|
|
28
|
-
before { ProductsIndex
|
29
|
-
before { allow(
|
26
|
+
before { ProductsIndex.import!(data.map { |h| double(h) }) }
|
27
|
+
before { allow(Kaminari.config).to receive_messages(default_per_page: 3) }
|
30
28
|
|
31
29
|
describe '#per, #page' do
|
32
30
|
specify { expect(search.map { |e| e.attributes.except(*except_fields) }).to match_array(data) }
|
@@ -5,8 +5,8 @@ describe Chewy::Search::Pagination::Kaminari do
|
|
5
5
|
describe '#objects' do
|
6
6
|
let(:data) { Array.new(12) { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
7
7
|
|
8
|
-
before { ProductsIndex
|
9
|
-
before { allow(
|
8
|
+
before { ProductsIndex.import!(data.map { |h| double(h) }) }
|
9
|
+
before { allow(Kaminari.config).to receive_messages(default_per_page: 17) }
|
10
10
|
|
11
11
|
specify { expect(search.objects.class).to eq(Kaminari::PaginatableArray) }
|
12
12
|
specify { expect(search.objects.total_count).to eq(12) }
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Search::Parameters::IgnoreUnavailable do
|
4
|
+
subject { described_class.new(true) }
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
specify { expect(subject.value).to eq(true) }
|
8
|
+
specify { expect(described_class.new.value).to eq(nil) }
|
9
|
+
specify { expect(described_class.new(42).value).to eq(true) }
|
10
|
+
specify { expect(described_class.new(false).value).to eq(false) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#replace!' do
|
14
|
+
specify { expect { subject.replace!(false) }.to change { subject.value }.from(true).to(false) }
|
15
|
+
specify { expect { subject.replace!(nil) }.to change { subject.value }.from(true).to(nil) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#update!' do
|
19
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(true) }
|
20
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(true).to(false) }
|
21
|
+
specify { expect { subject.update!(true) }.not_to change { subject.value }.from(true) }
|
22
|
+
|
23
|
+
context do
|
24
|
+
subject { described_class.new(false) }
|
25
|
+
|
26
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(false) }
|
27
|
+
specify { expect { subject.update!(false) }.not_to change { subject.value }.from(false) }
|
28
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(false).to(true) }
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
subject { described_class.new }
|
33
|
+
|
34
|
+
specify { expect { subject.update!(nil) }.not_to change { subject.value }.from(nil) }
|
35
|
+
specify { expect { subject.update!(false) }.to change { subject.value }.from(nil).to(false) }
|
36
|
+
specify { expect { subject.update!(true) }.to change { subject.value }.from(nil).to(true) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#merge!' do
|
41
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(true) }
|
42
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(true).to(false) }
|
43
|
+
specify { expect { subject.merge!(described_class.new(true)) }.not_to change { subject.value }.from(true) }
|
44
|
+
|
45
|
+
context do
|
46
|
+
subject { described_class.new(false) }
|
47
|
+
|
48
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(false) }
|
49
|
+
specify { expect { subject.merge!(described_class.new(false)) }.not_to change { subject.value }.from(false) }
|
50
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(false).to(true) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context do
|
54
|
+
subject { described_class.new }
|
55
|
+
|
56
|
+
specify { expect { subject.merge!(described_class.new) }.not_to change { subject.value }.from(nil) }
|
57
|
+
specify { expect { subject.merge!(described_class.new(false)) }.to change { subject.value }.from(nil).to(false) }
|
58
|
+
specify { expect { subject.merge!(described_class.new(true)) }.to change { subject.value }.from(nil).to(true) }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#render' do
|
63
|
+
specify { expect(described_class.new.render).to be_nil }
|
64
|
+
specify { expect(described_class.new(false).render).to eq(ignore_unavailable: false) }
|
65
|
+
specify { expect(subject.render).to eq(ignore_unavailable: true) }
|
66
|
+
end
|
67
|
+
end
|