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
@@ -8,16 +8,14 @@ describe Chewy::Search::Response, :orm 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
|
stub_index(:countries) do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
index_scope Country
|
17
|
+
field :name
|
18
|
+
field :rating, type: 'integer'
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -127,7 +125,9 @@ describe Chewy::Search::Response, :orm do
|
|
127
125
|
specify { expect(subject.aggs).to eq({}) }
|
128
126
|
|
129
127
|
context do
|
130
|
-
let(:request)
|
128
|
+
let(:request) do
|
129
|
+
Chewy::Search::Request.new(CitiesIndex, CountriesIndex).aggs(avg_rating: {avg: {field: :rating}})
|
130
|
+
end
|
131
131
|
specify { expect(subject.aggs).to eq('avg_rating' => {'value' => 1.5}) }
|
132
132
|
end
|
133
133
|
end
|
@@ -137,7 +137,7 @@ describe Chewy::Search::Response, :orm do
|
|
137
137
|
specify { expect(subject.wrappers).to have(4).items }
|
138
138
|
specify do
|
139
139
|
expect(subject.wrappers.map(&:class).uniq)
|
140
|
-
.to contain_exactly(CitiesIndex
|
140
|
+
.to contain_exactly(CitiesIndex, CountriesIndex)
|
141
141
|
end
|
142
142
|
specify { expect(subject.wrappers.map(&:_data)).to eq(subject.hits) }
|
143
143
|
|
@@ -166,7 +166,7 @@ describe Chewy::Search::Response, :orm do
|
|
166
166
|
'_source' => {'id' => 2, 'rating' => 0}}
|
167
167
|
]}}
|
168
168
|
end
|
169
|
-
specify { expect(subject.wrappers.first).to be_a(CitiesIndex
|
169
|
+
specify { expect(subject.wrappers.first).to be_a(CitiesIndex) }
|
170
170
|
specify { expect(subject.wrappers.first.id).to eq(2) }
|
171
171
|
specify { expect(subject.wrappers.first.rating).to eq(0) }
|
172
172
|
specify { expect(subject.wrappers.first._score).to eq(1.3) }
|
@@ -183,7 +183,7 @@ describe Chewy::Search::Response, :orm do
|
|
183
183
|
'_explanation' => {foo: 'bar'}}
|
184
184
|
]}}
|
185
185
|
end
|
186
|
-
specify { expect(subject.wrappers.first).to be_a(CountriesIndex
|
186
|
+
specify { expect(subject.wrappers.first).to be_a(CountriesIndex) }
|
187
187
|
specify { expect(subject.wrappers.first.id).to eq('2') }
|
188
188
|
specify { expect(subject.wrappers.first.rating).to be_nil }
|
189
189
|
specify { expect(subject.wrappers.first._score).to eq(1.2) }
|
@@ -8,16 +8,14 @@ describe Chewy::Search::Scrolling, :orm 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
|
stub_index(:countries) do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
index_scope Country
|
17
|
+
field :name
|
18
|
+
field :rating, type: 'integer'
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -108,7 +106,7 @@ describe Chewy::Search::Scrolling, :orm do
|
|
108
106
|
end
|
109
107
|
|
110
108
|
it 'clears the scroll after completion' do
|
111
|
-
expect(Chewy.client).to receive(:clear_scroll).with(scroll_id: anything).once.and_call_original
|
109
|
+
expect(Chewy.client).to receive(:clear_scroll).with(body: {scroll_id: anything}).once.and_call_original
|
112
110
|
request.scroll_batches(batch_size: 3) {}
|
113
111
|
end
|
114
112
|
|
@@ -119,21 +117,16 @@ describe Chewy::Search::Scrolling, :orm do
|
|
119
117
|
outer_payload << payload
|
120
118
|
end
|
121
119
|
request.scroll_batches(batch_size: 3).to_a
|
122
|
-
|
123
120
|
expect(outer_payload).to match_array([
|
124
121
|
hash_including(
|
125
122
|
index: [CitiesIndex, CountriesIndex],
|
126
123
|
indexes: [CitiesIndex, CountriesIndex],
|
127
|
-
request: {index: %w[cities countries],
|
128
|
-
type: [CitiesIndex::City, CountriesIndex::Country],
|
129
|
-
types: [CitiesIndex::City, CountriesIndex::Country]
|
124
|
+
request: {index: %w[cities countries], body: {sort: ['rating']}, size: 3, scroll: '1m'}
|
130
125
|
),
|
131
126
|
hash_including(
|
132
127
|
index: [CitiesIndex, CountriesIndex],
|
133
128
|
indexes: [CitiesIndex, CountriesIndex],
|
134
|
-
request: {scroll: '1m', scroll_id: an_instance_of(String)}
|
135
|
-
type: [CitiesIndex::City, CountriesIndex::Country],
|
136
|
-
types: [CitiesIndex::City, CountriesIndex::Country]
|
129
|
+
request: {scroll: '1m', scroll_id: an_instance_of(String)}
|
137
130
|
)
|
138
131
|
])
|
139
132
|
end
|
@@ -158,7 +151,7 @@ describe Chewy::Search::Scrolling, :orm do
|
|
158
151
|
end
|
159
152
|
specify do
|
160
153
|
expect(request.scroll_wrappers(batch_size: 2).map(&:class).uniq)
|
161
|
-
.to eq([CitiesIndex
|
154
|
+
.to eq([CitiesIndex, CountriesIndex])
|
162
155
|
end
|
163
156
|
end
|
164
157
|
|
data/spec/chewy/search_spec.rb
CHANGED
@@ -4,47 +4,34 @@ describe Chewy::Search do
|
|
4
4
|
before { Chewy.massacre }
|
5
5
|
|
6
6
|
before do
|
7
|
-
stub_index(:products)
|
8
|
-
define_type :product
|
9
|
-
end
|
7
|
+
stub_index(:products)
|
10
8
|
end
|
11
9
|
|
12
|
-
let(:product) { ProductsIndex::Product }
|
13
|
-
|
14
10
|
describe '.all' do
|
15
11
|
specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
|
16
|
-
specify { expect(product.all).to be_a(Chewy::Search::Request) }
|
17
12
|
|
18
13
|
context do
|
19
14
|
before { allow(Chewy).to receive_messages(search_class: Chewy::Search::Request) }
|
20
15
|
|
21
16
|
specify { expect(ProductsIndex.all).to be_a(Chewy::Search::Request) }
|
22
|
-
specify { expect(product.all).to be_a(Chewy::Search::Request) }
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
26
20
|
describe '.search_string' do
|
27
21
|
specify do
|
28
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).
|
22
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(q: 'hello')).once
|
29
23
|
ProductsIndex.search_string('hello')
|
30
|
-
product.search_string('hello')
|
31
24
|
end
|
32
25
|
|
33
26
|
specify do
|
34
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).
|
27
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(explain: true)).once
|
35
28
|
ProductsIndex.search_string('hello', explain: true)
|
36
|
-
product.search_string('hello', explain: true)
|
37
29
|
end
|
38
30
|
|
39
31
|
specify do
|
40
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products']
|
32
|
+
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'])).once
|
41
33
|
ProductsIndex.search_string('hello')
|
42
34
|
end
|
43
|
-
|
44
|
-
specify do
|
45
|
-
expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product]))
|
46
|
-
product.search_string('hello')
|
47
|
-
end
|
48
35
|
end
|
49
36
|
|
50
37
|
context 'named scopes' do
|
@@ -61,10 +48,13 @@ describe Chewy::Search do
|
|
61
48
|
filter { match name: "Name#{index}" }
|
62
49
|
end
|
63
50
|
|
64
|
-
|
65
|
-
|
66
|
-
field :rating, type: :integer
|
51
|
+
def self.by_rating_with_kwargs(value, options:) # rubocop:disable Lint/UnusedMethodArgument
|
52
|
+
filter { match rating: value }
|
67
53
|
end
|
54
|
+
|
55
|
+
index_scope City
|
56
|
+
field :name, type: 'keyword'
|
57
|
+
field :rating, type: :integer
|
68
58
|
end
|
69
59
|
|
70
60
|
stub_index(:countries) do
|
@@ -76,10 +66,9 @@ describe Chewy::Search do
|
|
76
66
|
filter { match name: "Name#{index}" }
|
77
67
|
end
|
78
68
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
69
|
+
index_scope Country
|
70
|
+
field :name, type: 'keyword'
|
71
|
+
field :rating, type: :integer
|
83
72
|
end
|
84
73
|
end
|
85
74
|
|
@@ -92,30 +81,47 @@ describe Chewy::Search do
|
|
92
81
|
end
|
93
82
|
|
94
83
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
95
|
-
specify
|
84
|
+
specify do
|
85
|
+
expect(CitiesIndex.indices(CountriesIndex).by_rating(1).map(&:class))
|
86
|
+
.to match_array([CitiesIndex, CountriesIndex])
|
87
|
+
end
|
96
88
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:rating)).to eq([1]) }
|
97
|
-
specify
|
89
|
+
specify do
|
90
|
+
expect(CitiesIndex.indices(CountriesIndex).by_rating(1).by_name(2).map(&:class))
|
91
|
+
.to eq([CitiesIndex])
|
92
|
+
end
|
98
93
|
specify { expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:rating)).to eq([2, 1]) }
|
99
|
-
specify
|
94
|
+
specify do
|
95
|
+
expect(CitiesIndex.indices(CountriesIndex).by_name(3).map(&:class))
|
96
|
+
.to eq([CitiesIndex, CountriesIndex])
|
97
|
+
end
|
100
98
|
specify { expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:rating)).to eq([1, 1]) }
|
101
|
-
specify
|
99
|
+
specify do
|
100
|
+
expect(CitiesIndex.indices(CountriesIndex).order(:name).by_rating(1).map(&:class))
|
101
|
+
.to match_array([CitiesIndex, CountriesIndex])
|
102
|
+
end
|
102
103
|
|
103
104
|
specify { expect(CitiesIndex.by_rating(2).map(&:rating)).to eq([2]) }
|
104
|
-
specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex
|
105
|
+
specify { expect(CitiesIndex.by_rating(2).map(&:class)).to eq([CitiesIndex]) }
|
105
106
|
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:rating)).to eq([2]) }
|
106
|
-
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex
|
107
|
+
specify { expect(CitiesIndex.by_rating(2).by_name(3).map(&:class)).to eq([CitiesIndex]) }
|
107
108
|
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
108
109
|
specify { expect(CitiesIndex.by_name(3).map(&:rating)).to eq([2]) }
|
109
110
|
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
110
111
|
specify { expect(CitiesIndex.order(:name).by_name(3).map(&:rating)).to eq([2]) }
|
111
112
|
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:rating)).to eq([2]) }
|
112
|
-
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex
|
113
|
+
specify { expect(CitiesIndex.order(:name).by_rating(2).map(&:class)).to eq([CitiesIndex]) }
|
113
114
|
|
114
115
|
specify { expect(CountriesIndex.by_rating(3).map(&:rating)).to eq([3]) }
|
115
|
-
specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex
|
116
|
+
specify { expect(CountriesIndex.by_rating(3).map(&:class)).to eq([CountriesIndex]) }
|
116
117
|
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:rating)).to eq([3]) }
|
117
|
-
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex
|
118
|
+
specify { expect(CountriesIndex.by_rating(3).by_name(5).map(&:class)).to eq([CountriesIndex]) }
|
118
119
|
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:rating)).to eq([3]) }
|
119
|
-
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex
|
120
|
+
specify { expect(CountriesIndex.order(:name).by_rating(3).map(&:class)).to eq([CountriesIndex]) }
|
121
|
+
|
122
|
+
specify 'supports keyword arguments' do
|
123
|
+
expect(CitiesIndex.by_rating_with_kwargs(3, options: 'blah blah blah').map(&:rating)).to eq([3])
|
124
|
+
expect(CitiesIndex.order(:name).by_rating_with_kwargs(3, options: 'blah blah blah').map(&:rating)).to eq([3])
|
125
|
+
end
|
120
126
|
end
|
121
127
|
end
|
data/spec/chewy/stash_spec.rb
CHANGED
@@ -10,12 +10,10 @@ describe Chewy::Stash::Journal, :orm do
|
|
10
10
|
before do
|
11
11
|
stub_model(:city)
|
12
12
|
stub_index(:cities) do
|
13
|
-
|
13
|
+
index_scope City
|
14
14
|
end
|
15
|
-
stub_index(:countries)
|
16
|
-
|
17
|
-
end
|
18
|
-
stub_index(:users) { define_type :user }
|
15
|
+
stub_index(:countries)
|
16
|
+
stub_index(:users)
|
19
17
|
stub_index(:borogoves)
|
20
18
|
end
|
21
19
|
|
@@ -28,7 +26,7 @@ describe Chewy::Stash::Journal, :orm do
|
|
28
26
|
CountriesIndex.import!([id: 2, name: 'Country'], journal: true)
|
29
27
|
end
|
30
28
|
Timecop.travel(Time.now + 2.minutes) do
|
31
|
-
UsersIndex
|
29
|
+
UsersIndex.import!([id: 3, name: 'User'], journal: true)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -72,26 +70,16 @@ describe Chewy::Stash::Journal, :orm do
|
|
72
70
|
specify { expect(fetch_deleted_number(described_class.clean(only: UsersIndex))).to eq(1) }
|
73
71
|
specify { expect(fetch_deleted_number(described_class.clean(only: [CitiesIndex, UsersIndex]))).to eq(2) }
|
74
72
|
|
75
|
-
specify
|
73
|
+
specify do
|
74
|
+
expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CountriesIndex))).to eq(0)
|
75
|
+
end
|
76
76
|
specify { expect(fetch_deleted_number(described_class.clean(Time.now + 30.seconds, only: CitiesIndex))).to eq(1) }
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '.for' do
|
80
80
|
specify { expect(described_class.for(UsersIndex).map(&:index_name)).to eq(['users']) }
|
81
|
-
specify
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#type' do
|
86
|
-
let(:index_name) { 'users' }
|
87
|
-
let(:type_name) { 'city' }
|
88
|
-
subject { described_class::Journal.new('index_name' => index_name, 'type_name' => type_name).type }
|
89
|
-
|
90
|
-
specify { expect { subject }.to raise_error(Chewy::UnderivableType) }
|
91
|
-
|
92
|
-
context do
|
93
|
-
let(:index_name) { 'cities' }
|
94
|
-
it { is_expected.to eq(CitiesIndex::City) }
|
81
|
+
specify do
|
82
|
+
expect(described_class.for(CitiesIndex, UsersIndex).map(&:index_name)).to contain_exactly('cities', 'users')
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
if defined?(
|
3
|
+
if defined?(ActiveJob)
|
4
4
|
describe Chewy::Strategy::ActiveJob do
|
5
5
|
around do |example|
|
6
6
|
active_job_settings = Chewy.settings[:active_job]
|
@@ -9,21 +9,21 @@ if defined?(::ActiveJob)
|
|
9
9
|
Chewy.settings[:active_job] = active_job_settings
|
10
10
|
end
|
11
11
|
before(:all) do
|
12
|
-
|
12
|
+
ActiveJob::Base.logger = Chewy.logger
|
13
13
|
end
|
14
14
|
before do
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
ActiveJob::Base.queue_adapter = :test
|
16
|
+
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
|
17
|
+
ActiveJob::Base.queue_adapter.performed_jobs.clear
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
21
21
|
stub_model(:city) do
|
22
|
-
update_index('cities
|
22
|
+
update_index('cities') { self }
|
23
23
|
end
|
24
24
|
|
25
25
|
stub_index(:cities) do
|
26
|
-
|
26
|
+
index_scope City
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -32,14 +32,14 @@ if defined?(::ActiveJob)
|
|
32
32
|
|
33
33
|
specify do
|
34
34
|
expect { [city, other_city].map(&:save!) }
|
35
|
-
.not_to update_index(CitiesIndex
|
35
|
+
.not_to update_index(CitiesIndex, strategy: :active_job)
|
36
36
|
end
|
37
37
|
|
38
38
|
specify do
|
39
39
|
Chewy.strategy(:active_job) do
|
40
40
|
[city, other_city].map(&:save!)
|
41
41
|
end
|
42
|
-
enqueued_job =
|
42
|
+
enqueued_job = ActiveJob::Base.queue_adapter.enqueued_jobs.first
|
43
43
|
expect(enqueued_job[:job]).to eq(Chewy::Strategy::ActiveJob::Worker)
|
44
44
|
expect(enqueued_job[:queue]).to eq('low')
|
45
45
|
end
|
@@ -48,26 +48,26 @@ if defined?(::ActiveJob)
|
|
48
48
|
Chewy.strategy(:active_job) do
|
49
49
|
[city, other_city].map(&:save!)
|
50
50
|
end
|
51
|
-
enqueued_job =
|
51
|
+
enqueued_job = ActiveJob::Base.queue_adapter.enqueued_jobs.first
|
52
52
|
expect(enqueued_job[:queue]).to eq('low')
|
53
53
|
end
|
54
54
|
|
55
55
|
specify do
|
56
|
-
|
56
|
+
ActiveJob::Base.queue_adapter = :inline
|
57
57
|
expect { [city, other_city].map(&:save!) }
|
58
|
-
.to update_index(CitiesIndex
|
58
|
+
.to update_index(CitiesIndex, strategy: :active_job)
|
59
59
|
.and_reindex(city, other_city).only
|
60
60
|
end
|
61
61
|
|
62
62
|
specify do
|
63
|
-
expect(CitiesIndex
|
64
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex
|
63
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601')
|
64
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
65
65
|
end
|
66
66
|
|
67
67
|
specify do
|
68
68
|
allow(Chewy).to receive(:disable_refresh_async).and_return(true)
|
69
|
-
expect(CitiesIndex
|
70
|
-
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex
|
69
|
+
expect(CitiesIndex).to receive(:import!).with([city.id, other_city.id], suffix: '201601', refresh: false)
|
70
|
+
Chewy::Strategy::ActiveJob::Worker.new.perform('CitiesIndex', [city.id, other_city.id], suffix: '201601')
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Strategy::AtomicNoRefresh, :orm do
|
4
|
+
around { |example| Chewy.strategy(:bypass) { example.run } }
|
5
|
+
|
6
|
+
before do
|
7
|
+
stub_model(:country) do
|
8
|
+
update_index('countries') { self }
|
9
|
+
end
|
10
|
+
|
11
|
+
stub_index(:countries) do
|
12
|
+
index_scope Country
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:country) { Country.create!(name: 'hello', country_code: 'HL') }
|
17
|
+
let(:other_country) { Country.create!(name: 'world', country_code: 'WD') }
|
18
|
+
|
19
|
+
specify do
|
20
|
+
expect { [country, other_country].map(&:save!) }
|
21
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
22
|
+
.and_reindex(country, other_country).only.no_refresh
|
23
|
+
end
|
24
|
+
|
25
|
+
specify do
|
26
|
+
expect { [country, other_country].map(&:destroy) }
|
27
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
28
|
+
.and_delete(country, other_country).only.no_refresh
|
29
|
+
end
|
30
|
+
|
31
|
+
context do
|
32
|
+
before do
|
33
|
+
stub_index(:countries) do
|
34
|
+
index_scope Country
|
35
|
+
root id: -> { country_code }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
specify do
|
40
|
+
expect { [country, other_country].map(&:save!) }
|
41
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
42
|
+
.and_reindex('HL', 'WD').only.no_refresh
|
43
|
+
end
|
44
|
+
|
45
|
+
specify do
|
46
|
+
expect { [country, other_country].map(&:destroy) }
|
47
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
48
|
+
.and_delete('HL', 'WD').only.no_refresh
|
49
|
+
end
|
50
|
+
|
51
|
+
specify do
|
52
|
+
expect do
|
53
|
+
country.save!
|
54
|
+
other_country.destroy
|
55
|
+
end
|
56
|
+
.to update_index(CountriesIndex, strategy: :atomic_no_refresh)
|
57
|
+
.and_reindex('HL').and_delete('WD').only.no_refresh
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -5,11 +5,11 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
stub_model(:country) do
|
8
|
-
update_index('countries
|
8
|
+
update_index('countries') { self }
|
9
9
|
end
|
10
10
|
|
11
11
|
stub_index(:countries) do
|
12
|
-
|
12
|
+
index_scope Country
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -18,35 +18,34 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
18
18
|
|
19
19
|
specify do
|
20
20
|
expect { [country, other_country].map(&:save!) }
|
21
|
-
.to update_index(CountriesIndex
|
21
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
22
22
|
.and_reindex(country, other_country).only
|
23
23
|
end
|
24
24
|
|
25
25
|
specify do
|
26
26
|
expect { [country, other_country].map(&:destroy) }
|
27
|
-
.to update_index(CountriesIndex
|
27
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
28
28
|
.and_delete(country, other_country).only
|
29
29
|
end
|
30
30
|
|
31
31
|
context do
|
32
32
|
before do
|
33
33
|
stub_index(:countries) do
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
index_scope Country
|
35
|
+
root id: -> { country_code } do
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
40
|
specify do
|
42
41
|
expect { [country, other_country].map(&:save!) }
|
43
|
-
.to update_index(CountriesIndex
|
42
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
44
43
|
.and_reindex('HL', 'WD').only
|
45
44
|
end
|
46
45
|
|
47
46
|
specify do
|
48
47
|
expect { [country, other_country].map(&:destroy) }
|
49
|
-
.to update_index(CountriesIndex
|
48
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
50
49
|
.and_delete('HL', 'WD').only
|
51
50
|
end
|
52
51
|
|
@@ -55,7 +54,7 @@ describe Chewy::Strategy::Atomic, :orm do
|
|
55
54
|
country.save!
|
56
55
|
other_country.destroy
|
57
56
|
end
|
58
|
-
.to update_index(CountriesIndex
|
57
|
+
.to update_index(CountriesIndex, strategy: :atomic)
|
59
58
|
.and_reindex('HL').and_delete('WD').only
|
60
59
|
end
|
61
60
|
end
|